Skip to content

Commit abc2b87

Browse files
CLOUDP-34998: Scaffolder to generate controllers and indexers (#2831)
Scaffolder generates controllers and indexers per resource version
1 parent 36bd2f0 commit abc2b87

File tree

165 files changed

+33167
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+33167
-414
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ linters:
6565
- prealloc
6666
- unparam
6767
path: pkg/controller
68+
- linters:
69+
- dupl
70+
path: internal/generated
71+
- linters:
72+
- dupl
73+
path: internal/indexer
6874
- linters:
6975
- prealloc
7076
path: pkg/controller/atlasdatabaseuser/connectionsecrets

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ bin/manager: bin/$(TARGET_OS)/$(TARGET_ARCH)/manager
274274
.PHONY: manager
275275
manager: generate fmt vet bin/manager ## Build manager binary
276276

277+
.PHONY: build
278+
build: bin/manager
279+
277280
.PHONY: install
278281
install: manifests ## Install CRDs from a cluster
279282
$(KUSTOMIZE) build config/crd | kubectl apply -f -
@@ -816,4 +819,11 @@ clean-bundle:
816819
autogenerated-manifests: manifests update-manager-kustomization
817820
@echo "Creating directory..."
818821
@mkdir -p $(TARGET_DIR)/generated
819-
@$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/generated > $(TARGET_DIR)/generated/allinone.yaml
822+
@$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/generated > $(TARGET_DIR)/generated/allinone.yaml
823+
824+
.PHONY: gen-all
825+
gen-all:
826+
$(MAKE) -C tools/openapi2crd crds-force
827+
$(MAKE) -C tools/crd2go build
828+
cd tools/crd2go && ./crd2go -input ../openapi2crd/crds.yaml -output ../../internal/nextapi/v1
829+
$(MAKE) -C tools/scaffolder generate-all

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/mongodb/mongodb-atlas-kubernetes/v2
22

3-
go 1.25
3+
go 1.25.1
44

55
toolchain go1.25.3
66

@@ -21,13 +21,15 @@ require (
2121
github.com/google/go-cmp v0.7.0
2222
github.com/google/uuid v1.6.0
2323
github.com/mongodb-forks/digest v1.1.0
24+
github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go v0.0.0-20251023081430-afe130f9138e
2425
github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1
2526
github.com/onsi/ginkgo/v2 v2.27.2
2627
github.com/onsi/gomega v1.38.2
2728
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
2829
github.com/sethvargo/go-password v0.3.1
2930
github.com/stretchr/testify v1.11.1
3031
github.com/yudai/gojsondiff v1.0.0
32+
go.mongodb.org/atlas-sdk/v20250312005 v20250312005.0.0
3133
go.mongodb.org/atlas-sdk/v20250312006 v20250312006.1.0
3234
go.mongodb.org/mongo-driver v1.17.6
3335
go.uber.org/zap v1.27.0
@@ -68,11 +70,10 @@ require (
6870
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6971
github.com/jmespath/go-jmespath v0.4.0 // indirect
7072
github.com/kylelemons/godebug v1.1.0 // indirect
71-
github.com/mattn/go-colorable v0.1.14 // indirect
7273
github.com/onsi/ginkgo v1.16.5 // indirect
7374
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
7475
github.com/sergi/go-diff v1.4.0 // indirect
75-
github.com/spf13/cobra v1.9.1 // indirect
76+
github.com/spf13/cobra v1.10.1 // indirect
7677
github.com/stoewer/go-strcase v1.3.0 // indirect
7778
github.com/stretchr/objx v0.5.2 // indirect
7879
github.com/x448/float16 v0.8.4 // indirect
@@ -138,7 +139,7 @@ require (
138139
github.com/prometheus/client_model v0.6.1 // indirect
139140
github.com/prometheus/common v0.62.0 // indirect
140141
github.com/prometheus/procfs v0.15.1 // indirect
141-
github.com/spf13/pflag v1.0.6 // indirect
142+
github.com/spf13/pflag v1.0.10 // indirect
142143
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
143144
github.com/xdg-go/scram v1.1.2 // indirect
144145
github.com/xdg-go/stringprep v1.0.4 // indirect

go.sum

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd
229229
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
230230
github.com/mongodb-forks/digest v1.1.0 h1:7eUdsR1BtqLv0mdNm4OXs6ddWvR4X2/OsLwdKksrOoc=
231231
github.com/mongodb-forks/digest v1.1.0/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg=
232+
github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go v0.0.0-20251023081430-afe130f9138e h1:IDF5AmTwyxnjyb+HO5BPNwn8tbIIN3d60/vY90Ppfu8=
233+
github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go v0.0.0-20251023081430-afe130f9138e/go.mod h1:16AvHza5d0digrWj6AgOCUbFrKwKhWrnASCGpXQrX3Y=
232234
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
233235
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
234236
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
@@ -265,19 +267,20 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ
265267
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
266268
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
267269
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
268-
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
269-
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
270+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
271+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
270272
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
271273
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
272274
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
273275
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
274276
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
275277
github.com/sethvargo/go-password v0.3.1 h1:WqrLTjo7X6AcVYfC6R7GtSyuUQR9hGyAj/f1PYQZCJU=
276278
github.com/sethvargo/go-password v0.3.1/go.mod h1:rXofC1zT54N7R8K/h1WDUdkf9BOx5OptoxrMBcrXzvs=
277-
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
278-
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
279-
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
280-
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
279+
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
280+
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
281+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
282+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
283+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
281284
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
282285
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
283286
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -320,6 +323,8 @@ github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZ
320323
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
321324
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
322325
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
326+
go.mongodb.org/atlas-sdk/v20250312005 v20250312005.0.0 h1:uKOtHXCP/Gwuj+IF1hsKtIAxNSVjKNo+o4Z+ulgCEXw=
327+
go.mongodb.org/atlas-sdk/v20250312005 v20250312005.0.0/go.mod h1:UeRE741z+kDGH00qQasZmthQxJMeA6PmAtY/2dStW+Q=
323328
go.mongodb.org/atlas-sdk/v20250312006 v20250312006.1.0 h1:PcVxslw4G7/I9SbUi5y81i4YZnL1dKRnGpeHVyNSTh4=
324329
go.mongodb.org/atlas-sdk/v20250312006 v20250312006.1.0/go.mod h1:UZYSaCimjGs3j+wMwgHSKUSIvoJXzmy/xrer0t5TLgo=
325330
go.mongodb.org/mongo-driver v1.17.6 h1:87JUG1wZfWsr6rIz3ZmpH90rL5tea7O3IHuSwHUpsss=

internal/controller/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"sigs.k8s.io/controller-runtime/pkg/predicate"
2828
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2929

30-
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/autogen/controller/connectionsecret"
3130
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/atlas"
3231
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/atlasbackupcompliancepolicy"
3332
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/atlascustomrole"
@@ -47,6 +46,7 @@ import (
4746
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/watch"
4847
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/dryrun"
4948
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/featureflags"
49+
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/generated/controller/connectionsecret"
5050
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
5151
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/version"
5252
ctrlstate "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/state"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package backupcompliancepolicy
16+
17+
import (
18+
zap "go.uber.org/zap"
19+
client "sigs.k8s.io/controller-runtime/pkg/client"
20+
cluster "sigs.k8s.io/controller-runtime/pkg/cluster"
21+
22+
atlas "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/atlas"
23+
reconciler "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/reconciler"
24+
v1 "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/nextapi/generated/v1"
25+
ctrlstate "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/state"
26+
)
27+
28+
// +kubebuilder:rbac:groups=atlas.mongodb.com,resources=backupcompliancepolicys,verbs=get;list;watch;create;update;patch;delete
29+
// +kubebuilder:rbac:groups=atlas.mongodb.com,resources=backupcompliancepolicys/status,verbs=get;update;patch
30+
// +kubebuilder:rbac:groups=atlas.mongodb.com,resources=backupcompliancepolicys/finalizers,verbs=update
31+
// +kubebuilder:rbac:groups=atlas.mongodb.com,namespace=default,resources=backupcompliancepolicys,verbs=get;list;watch;create;update;patch;delete
32+
// +kubebuilder:rbac:groups=atlas.mongodb.com,namespace=default,resources=backupcompliancepolicys/status,verbs=get;update;patch
33+
// +kubebuilder:rbac:groups=atlas.mongodb.com,namespace=default,resources=backupcompliancepolicys/finalizers,verbs=update
34+
type BackupCompliancePolicyHandler struct {
35+
ctrlstate.StateHandler[v1.BackupCompliancePolicy]
36+
reconciler.AtlasReconciler
37+
handlerv20250312 *BackupCompliancePolicyHandlerv20250312
38+
}
39+
40+
func NewBackupCompliancePolicyReconciler(c cluster.Cluster, atlasProvider atlas.Provider, logger *zap.Logger, globalSecretRef client.ObjectKey, reapplySupport bool) *ctrlstate.Reconciler[v1.BackupCompliancePolicy] {
41+
// Create version-specific handlers
42+
43+
handlerv20250312 := NewBackupCompliancePolicyHandlerv20250312(atlasProvider, c.GetClient(), logger.Named("controllers").Named("BackupCompliancePolicy-v20250312").Sugar(), globalSecretRef)
44+
45+
// Create main handler dispatcher
46+
backupcompliancepolicyHandler := &BackupCompliancePolicyHandler{
47+
AtlasReconciler: reconciler.AtlasReconciler{
48+
AtlasProvider: atlasProvider,
49+
Client: c.GetClient(),
50+
GlobalSecretRef: globalSecretRef,
51+
Log: logger.Named("controllers").Named("AtlasBackupCompliancePolicy").Sugar(),
52+
},
53+
handlerv20250312: handlerv20250312,
54+
}
55+
56+
return ctrlstate.NewStateReconciler(backupcompliancepolicyHandler, ctrlstate.WithCluster[v1.BackupCompliancePolicy](c), ctrlstate.WithReapplySupport[v1.BackupCompliancePolicy](reapplySupport))
57+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package backupcompliancepolicy
16+
17+
import (
18+
"context"
19+
"fmt"
20+
21+
controllerruntime "sigs.k8s.io/controller-runtime"
22+
builder "sigs.k8s.io/controller-runtime/pkg/builder"
23+
client "sigs.k8s.io/controller-runtime/pkg/client"
24+
controller "sigs.k8s.io/controller-runtime/pkg/controller"
25+
reconcile "sigs.k8s.io/controller-runtime/pkg/reconcile"
26+
27+
v1 "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/nextapi/generated/v1"
28+
ctrlstate "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/state"
29+
result "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/result"
30+
state "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/state"
31+
)
32+
33+
// getHandlerForResource selects the appropriate version-specific handler based on which resource spec version is set
34+
func (h *BackupCompliancePolicyHandler) getHandlerForResource(backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.StateHandler[v1.BackupCompliancePolicy], error) {
35+
// Check which resource spec version is set and validate that only one is specified
36+
var versionCount int
37+
var selectedHandler ctrlstate.StateHandler[v1.BackupCompliancePolicy]
38+
39+
if backupcompliancepolicy.Spec.V20250312 != nil {
40+
versionCount++
41+
selectedHandler = h.handlerv20250312
42+
}
43+
44+
if versionCount == 0 {
45+
return nil, fmt.Errorf("no resource spec version specified - please set one of the available spec versions")
46+
}
47+
if versionCount > 1 {
48+
return nil, fmt.Errorf("multiple resource spec versions specified - please set only one spec version")
49+
}
50+
return selectedHandler, nil
51+
}
52+
53+
// HandleInitial delegates to the version-specific handler
54+
func (h *BackupCompliancePolicyHandler) HandleInitial(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
55+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
56+
if err != nil {
57+
return result.Error(state.StateInitial, err)
58+
}
59+
return handler.HandleInitial(ctx, backupcompliancepolicy)
60+
}
61+
62+
// HandleImportRequested delegates to the version-specific handler
63+
func (h *BackupCompliancePolicyHandler) HandleImportRequested(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
64+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
65+
if err != nil {
66+
return result.Error(state.StateInitial, err)
67+
}
68+
return handler.HandleImportRequested(ctx, backupcompliancepolicy)
69+
}
70+
71+
// HandleImported delegates to the version-specific handler
72+
func (h *BackupCompliancePolicyHandler) HandleImported(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
73+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
74+
if err != nil {
75+
return result.Error(state.StateInitial, err)
76+
}
77+
return handler.HandleImported(ctx, backupcompliancepolicy)
78+
}
79+
80+
// HandleCreating delegates to the version-specific handler
81+
func (h *BackupCompliancePolicyHandler) HandleCreating(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
82+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
83+
if err != nil {
84+
return result.Error(state.StateInitial, err)
85+
}
86+
return handler.HandleCreating(ctx, backupcompliancepolicy)
87+
}
88+
89+
// HandleCreated delegates to the version-specific handler
90+
func (h *BackupCompliancePolicyHandler) HandleCreated(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
91+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
92+
if err != nil {
93+
return result.Error(state.StateInitial, err)
94+
}
95+
return handler.HandleCreated(ctx, backupcompliancepolicy)
96+
}
97+
98+
// HandleUpdating delegates to the version-specific handler
99+
func (h *BackupCompliancePolicyHandler) HandleUpdating(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
100+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
101+
if err != nil {
102+
return result.Error(state.StateInitial, err)
103+
}
104+
return handler.HandleUpdating(ctx, backupcompliancepolicy)
105+
}
106+
107+
// HandleUpdated delegates to the version-specific handler
108+
func (h *BackupCompliancePolicyHandler) HandleUpdated(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
109+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
110+
if err != nil {
111+
return result.Error(state.StateInitial, err)
112+
}
113+
return handler.HandleUpdated(ctx, backupcompliancepolicy)
114+
}
115+
116+
// HandleDeletionRequested delegates to the version-specific handler
117+
func (h *BackupCompliancePolicyHandler) HandleDeletionRequested(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
118+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
119+
if err != nil {
120+
return result.Error(state.StateInitial, err)
121+
}
122+
return handler.HandleDeletionRequested(ctx, backupcompliancepolicy)
123+
}
124+
125+
// HandleDeleting delegates to the version-specific handler
126+
func (h *BackupCompliancePolicyHandler) HandleDeleting(ctx context.Context, backupcompliancepolicy *v1.BackupCompliancePolicy) (ctrlstate.Result, error) {
127+
handler, err := h.getHandlerForResource(backupcompliancepolicy)
128+
if err != nil {
129+
return result.Error(state.StateInitial, err)
130+
}
131+
return handler.HandleDeleting(ctx, backupcompliancepolicy)
132+
}
133+
134+
// For returns the resource and predicates for the controller
135+
func (h *BackupCompliancePolicyHandler) For() (client.Object, builder.Predicates) {
136+
obj := &v1.BackupCompliancePolicy{}
137+
// TODO: Add appropriate predicates
138+
return obj, builder.WithPredicates()
139+
}
140+
141+
// SetupWithManager sets up the controller with the Manager
142+
func (h *BackupCompliancePolicyHandler) SetupWithManager(mgr controllerruntime.Manager, rec reconcile.Reconciler, defaultOptions controller.Options) error {
143+
h.Client = mgr.GetClient()
144+
return controllerruntime.NewControllerManagedBy(mgr).Named("BackupCompliancePolicy").For(h.For()).WithOptions(defaultOptions).Complete(rec)
145+
}

0 commit comments

Comments
 (0)