Skip to content

Commit

Permalink
Merge branch 'main' into dev/K8SPSMDB-675
Browse files Browse the repository at this point in the history
  • Loading branch information
hors authored Dec 3, 2024
2 parents 9945cb5 + 43f0939 commit eeb9cc6
Show file tree
Hide file tree
Showing 31 changed files with 1,811 additions and 1,494 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

SWAGGER = $(shell pwd)/bin/swagger
swagger: ## Download swagger locally if necessary.
$(call go-get-tool,$(SWAGGER),github.com/go-swagger/go-swagger/cmd/swagger@latest)

# Prepare release
CERT_MANAGER_VER := $(shell grep -Eo "cert-manager v.*" go.mod|grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
release: manifests
Expand Down Expand Up @@ -124,3 +128,13 @@ after-release: manifests
-e "/^ backup:/,/^ image:/{s#image: .*#image: perconalab/percona-server-mongodb-operator:main-backup#}" \
-e "s#initImage: .*#initImage: perconalab/percona-server-mongodb-operator:main#g" \
-e "/^ pmm:/,/^ image:/{s#image: .*#image: perconalab/pmm-client:dev-latest#}" deploy/cr.yaml

version-service-client: swagger
curl https://raw.githubusercontent.com/Percona-Lab/percona-version-service/$(VS_BRANCH)/api/version.swagger.yaml \
--output ./version.swagger.yaml
rm -rf ./versionserviceclient
swagger generate client \
-f ./version.swagger.yaml \
-c ./versionserviceclient/ \
-m ./versionserviceclient/models
rm ./version.swagger.yaml
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
k8s.io/api v0.31.3
k8s.io/apimachinery v0.31.3
k8s.io/client-go v0.31.3
sigs.k8s.io/controller-runtime v0.19.1
sigs.k8s.io/controller-runtime v0.19.3
sigs.k8s.io/mcs-api v0.1.0
sigs.k8s.io/yaml v1.4.0
)
Expand Down Expand Up @@ -62,7 +62,6 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -814,8 +812,8 @@ k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 h1:MDF6h2H/h4tbzmtIKTuctcwZmY0tY
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0=
sigs.k8s.io/controller-runtime v0.6.1/go.mod h1:XRYBPdbf5XJu9kpS84VJiZ7h/u1hF3gEORz0efEja7A=
sigs.k8s.io/controller-runtime v0.19.1 h1:Son+Q40+Be3QWb+niBXAg2vFiYWolDjjRfO8hn/cxOk=
sigs.k8s.io/controller-runtime v0.19.1/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/controller-runtime v0.19.3 h1:XO2GvC9OPftRst6xWCpTgBZO04S2cbp0Qqkj8bX1sPw=
sigs.k8s.io/controller-runtime v0.19.3/go.mod h1:j4j87DqtsThvwTv5/Tc5NFRyyF/RF0ip4+62tbTSIUM=
sigs.k8s.io/controller-tools v0.3.0/go.mod h1:enhtKGfxZD1GFEoMgP8Fdbu+uKQ/cq1/WGJhdVChfvI=
sigs.k8s.io/gateway-api v1.1.0 h1:DsLDXCi6jR+Xz8/xd0Z1PYl2Pn0TyaFMOPPZIj4inDM=
sigs.k8s.io/gateway-api v1.1.0/go.mod h1:ZH4lHrL2sDi0FHZ9jjneb8kKnGzFWyrTya35sWUTrRs=
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/perconaservermongodb/connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestConnectionLeaks(t *testing.T) {
r := buildFakeClient(obj...)
r.mongoClientProvider = &fakeMongoClientProvider{pods: rsPods, cr: cr, connectionCount: connectionCount}
r.serverVersion = &version.ServerVersion{Platform: version.PlatformKubernetes}
r.crons = NewCronRegistry()

g, gCtx := errgroup.WithContext(ctx)
gCtx, cancel := context.WithCancel(gCtx)
Expand Down
31 changes: 21 additions & 10 deletions pkg/controller/perconaservermongodb/psmdb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,27 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
var _ reconcile.Reconciler = &ReconcilePerconaServerMongoDB{}

type CronRegistry struct {
crons *cron.Cron
jobs map[string]Schedule
backupJobs *sync.Map
crons *cron.Cron
ensureVersionJobs *sync.Map
backupJobs *sync.Map
}

type Schedule struct {
ID int
CronSchedule string
// AddFuncWithSeconds does the same as cron.AddFunc but changes the schedule so that the function will run the exact second that this method is called.
func (r *CronRegistry) AddFuncWithSeconds(spec string, cmd func()) (cron.EntryID, error) {
schedule, err := cron.ParseStandard(spec)
if err != nil {
return 0, errors.Wrap(err, "failed to parse cron schedule")
}
schedule.(*cron.SpecSchedule).Second = uint64(1 << time.Now().Second())
id := r.crons.Schedule(schedule, cron.FuncJob(cmd))
return id, nil
}

func NewCronRegistry() CronRegistry {
c := CronRegistry{
crons: cron.New(),
jobs: make(map[string]Schedule),
backupJobs: new(sync.Map),
crons: cron.New(),
ensureVersionJobs: new(sync.Map),
backupJobs: new(sync.Map),
}

c.crons.Start()
Expand Down Expand Up @@ -444,7 +450,12 @@ func (r *ReconcilePerconaServerMongoDB) Reconcile(ctx context.Context, request r

err = r.scheduleEnsureVersion(ctx, cr, VersionServiceClient{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to ensure version")
return reconcile.Result{}, errors.Wrap(err, "schedule ensure version job")
}

err = r.scheduleTelemetryRequests(ctx, cr, VersionServiceClient{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "schedule telemetry job")
}

if err = r.updatePITR(ctx, cr); err != nil {
Expand Down
Loading

0 comments on commit eeb9cc6

Please sign in to comment.