Skip to content

Commit

Permalink
Move to controller-sdk 1.34.2
Browse files Browse the repository at this point in the history
The move to operator-sdk is to aid with newer APIs that we may define
and overall catching up to the later sdk versions for maintainability
of the code base in the future.

This commit has 2 major changes as follows,
- Move controllers to internal/controller and main.go to cmd/

The above hence entails changes to Makefile, import paths, and other
artifacts that are path dependent.

- Move to kustomize v5

The above changes patchesStrategicMerge to patches and commonLabels
to labels (though the latter is unused in comments)

Related to the actual change is to move the PROJECT file to
kubebuilder v4 and to update the install scripts to use the latest
versions of the required tools.

Overall changes were performed following the upgrade guides from v1.24.0
to v1.34.2:
https://sdk.operatorframework.io/docs/upgrading-sdk-version/

One of the bigger change to move from kubebuilder v3 to v4 required
following the migration guide at:
https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md

Open areas:
Move to gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0
Change transformers to labels in kustomize

Signed-off-by: Shyamsundar Ranganathan <[email protected]>
  • Loading branch information
ShyamsundarR committed May 21, 2024
1 parent 463cfcf commit 76000a6
Show file tree
Hide file tree
Showing 100 changed files with 163 additions and 245 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ COPY api/ api/
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY controllers/ controllers/
COPY cmd/main.go cmd/main.go
COPY internal/controller/ internal/controller/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager cmd/main.go

FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /
Expand Down
39 changes: 20 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,46 +141,46 @@ test: generate manifests envtest ## Run all the tests.
go test ./... -coverprofile cover.out

test-pvrgl: generate manifests envtest ## Run ProtectedVolumeReplicationGroupList tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus ProtectedVolumeReplicationGroupList
go test ./internal/controller -coverprofile cover.out -ginkgo.focus ProtectedVolumeReplicationGroupList

test-obj: generate manifests envtest ## Run ObjectStorer tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus FakeObjectStorer
go test ./internal/controller -coverprofile cover.out -ginkgo.focus FakeObjectStorer

test-vs: generate manifests envtest ## Run VolumeSync tests.
go test ./controllers/volsync -coverprofile cover.out
go test ./internal/controller/volsync -coverprofile cover.out

test-vrg: generate manifests envtest ## Run VolumeReplicationGroup tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroup
go test ./internal/controller -coverprofile cover.out -ginkgo.focus VolumeReplicationGroup

test-vrg-pvc: generate manifests envtest ## Run VolumeReplicationGroupPVC tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupPVC
go test ./internal/controller -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupPVC

test-vrg-vr: generate manifests envtest ## Run VolumeReplicationGroupVolRep tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupVolRep
go test ./internal/controller -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupVolRep

test-vrg-vs: generate manifests envtest ## Run VolumeReplicationGroupVolSync tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupVolSync
go test ./internal/controller -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupVolSync

test-vrg-recipe: generate manifests envtest ## Run VolumeReplicationGroupRecipe tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupRecipe
go test ./internal/controller -coverprofile cover.out -ginkgo.focus VolumeReplicationGroupRecipe

test-vrg-kubeobjects: generate manifests envtest ## Run VolumeReplicationGroupKubeObjects tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus VRG_KubeObjectProtection
go test ./internal/controller -coverprofile cover.out -ginkgo.focus VRG_KubeObjectProtection

test-drpc: generate manifests envtest ## Run DRPlacementControl tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus DRPlacementControl
go test ./internal/controller -coverprofile cover.out -ginkgo.focus DRPlacementControl

test-drcluster: generate manifests envtest ## Run DRCluster tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus DRClusterController
go test ./internal/controller -coverprofile cover.out -ginkgo.focus DRClusterController

test-drpolicy: generate manifests envtest ## Run DRPolicy tests.
go test ./controllers -coverprofile cover.out -ginkgo.focus DRPolicyController
go test ./internal/controller -coverprofile cover.out -ginkgo.focus DRPolicyController

test-util: generate manifests envtest ## Run util tests.
go test ./controllers/util -coverprofile cover.out
go test ./internal/controller/util -coverprofile cover.out

test-util-pvc: generate manifests envtest ## Run util-pvc tests.
go test ./controllers/util -coverprofile cover.out -ginkgo.focus PVCS_Util
go test ./internal/controller/util -coverprofile cover.out -ginkgo.focus PVCS_Util

test-drenv: ## Run drenv tests.
$(MAKE) -C test
Expand All @@ -201,15 +201,15 @@ venv:
##@ Build

# Build manager binary
build: generate ## Build manager binary.
go build -o bin/manager main.go
build: generate manifests ## Build manager binary.
go build -o bin/manager cmd/main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run-hub: generate manifests ## Run DR Orchestrator controller from your host.
go run ./main.go --config=examples/dr_hub_config.yaml
go run ./cmd/main.go --config=examples/dr_hub_config.yaml

run-dr-cluster: generate manifests ## Run DR manager controller from your host.
go run ./main.go --config=examples/dr_cluster_config.yaml
go run ./cmd/main.go --config=examples/dr_cluster_config.yaml

docker-build: ## Build docker image with the manager.
$(DOCKERCMD) build -t ${IMG} .
Expand Down Expand Up @@ -391,7 +391,8 @@ ifeq ($(DOCKERCMD),docker)
-e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' \
Dockerfile > Dockerfile.cross
$(SED_CMD) -e 's/GOARCH=amd64/GOARCH=$${TARGETARCH}/' -i Dockerfile.cross
- $(DOCKERCMD) buildx create --name $(IMAGE_NAME)-builder --bootstrap --use
- $(DOCKERCMD) buildx create --name $(IMAGE_NAME)-builder
$(DOCKERCMD) buildx use project-v3-builder
- $(DOCKERCMD) buildx build --push --platform="${PLATFORMS}" --tag ${IMG} -f Dockerfile.cross .
- $(DOCKERCMD) buildx rm $(IMAGE_NAME)-builder
rm Dockerfile.cross
Expand Down
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

domain: openshift.io
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand Down
6 changes: 3 additions & 3 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (

ramendrv1alpha1 "github.com/ramendr/ramen/api/v1alpha1"

"github.com/ramendr/ramen/controllers"
argocdv1alpha1hack "github.com/ramendr/ramen/controllers/argocd"
rmnutil "github.com/ramendr/ramen/controllers/util"
controllers "github.com/ramendr/ramen/internal/controller"
argocdv1alpha1hack "github.com/ramendr/ramen/internal/controller/argocd"
rmnutil "github.com/ramendr/ramen/internal/controller/util"
recipe "github.com/ramendr/recipe/api/v1alpha1"
// +kubebuilder:scaffold:imports
)
Expand Down
26 changes: 13 additions & 13 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ resources:
- bases/ramendr.openshift.io_maintenancemodes.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_volumereplicationgroups.yaml
#- patches/webhook_in_drpolicies.yaml
#- patches/webhook_in_DRPlacementControls.yaml
#- patches/webhook_in_drclusters.yaml
#- patches/webhook_in_protectedvolumereplicationgrouplists.yaml
#- patches/webhook_in_maintenancemodes.yaml
#- path: patches/webhook_in_volumereplicationgroups.yaml
#- path: patches/webhook_in_drpolicies.yaml
#- path: patches/webhook_in_DRPlacementControls.yaml
#- path: patches/webhook_in_drclusters.yaml
#- path: patches/webhook_in_protectedvolumereplicationgrouplists.yaml
#- path: patches/webhook_in_maintenancemodes.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_volumereplicationgroups.yaml
#- patches/cainjection_in_drpolicies.yaml
#- patches/cainjection_in_DRPlacementControls.yaml
#- patches/cainjection_in_drclusters.yaml
#- patches/cainjection_in_protectedvolumereplicationgrouplists.yaml
#- patches/cainjection_in_maintenancemodes.yaml
#- path: patches/cainjection_in_volumereplicationgroups.yaml
#- path: patches/cainjection_in_drpolicies.yaml
#- path: patches/cainjection_in_DRPlacementControls.yaml
#- path: patches/cainjection_in_drclusters.yaml
#- path: patches/cainjection_in_protectedvolumereplicationgrouplists.yaml
#- path: patches/cainjection_in_maintenancemodes.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 0 additions & 7 deletions config/crd/patches/cainjection_in_drclusters.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions config/crd/patches/cainjection_in_drplacementcontrols.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions config/crd/patches/cainjection_in_drpolicies.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions config/crd/patches/cainjection_in_maintenancemodes.yaml

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions config/crd/patches/webhook_in_maintenancemodes.yaml

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions config/crd/patches/webhook_in_volumereplicationgroups.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions config/dr-cluster/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ resources:
- ../../crd/bases/ramendr.openshift.io_maintenancemodes.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_volumereplicationgroups.yaml
#- path: patches/webhook_in_volumereplicationgroups.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_volumereplicationgroups.yaml
#- path: patches/cainjection_in_volumereplicationgroups.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
13 changes: 7 additions & 6 deletions config/dr-cluster/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace: ramen-system
# field above.
namePrefix: ramen-dr-cluster-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
#labels:
#- includeSelectors: true
# pairs:
# someName: someValue

transformers:
- |-
Expand Down Expand Up @@ -48,9 +49,9 @@ transformers:

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
patchesStrategicMerge:
- ../../default/manager_auth_proxy_patch.yaml
- ../../default/manager_config_patch.yaml
patches:
- path: ../../default/manager_auth_proxy_patch.yaml
- path: ../../default/manager_config_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
2 changes: 1 addition & 1 deletion config/hub/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resources:
- ../../crd/bases/ramendr.openshift.io_drclusters.yaml
# +kubebuilder:scaffold:crdkustomizeresource

# patchesStrategicMerge:
# patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
# +kubebuilder:scaffold:crdkustomizewebhookpatch
Expand Down
13 changes: 7 additions & 6 deletions config/hub/default/k8s/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace: ramen-system
# field above.
namePrefix: ramen-hub-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
#labels:
#- includeSelectors: true
# pairs:
# someName: someValue

transformers:
- |-
Expand Down Expand Up @@ -42,9 +43,9 @@ transformers:
# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
patchesStrategicMerge:
- ../../../default/manager_auth_proxy_patch.yaml
- ../../../default/manager_config_patch.yaml
patches:
- path: ../../../default/manager_auth_proxy_patch.yaml
- path: ../../../default/manager_config_patch.yaml


apiVersion: kustomize.config.k8s.io/v1beta1
Expand Down
15 changes: 8 additions & 7 deletions config/hub/default/ocp/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace: ramen-system
# field above.
namePrefix: ramen-hub-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
#labels:
#- includeSelectors: true
# pairs:
# someName: someValue

transformers:
- |-
Expand Down Expand Up @@ -49,9 +50,9 @@ transformers:

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
patchesStrategicMerge:
- ../../../default/manager_auth_proxy_patch.yaml
- ../../../default/manager_config_patch.yaml
patches:
- path: ../../../default/manager_auth_proxy_patch.yaml
- path: ../../../default/manager_config_patch.yaml


apiVersion: kustomize.config.k8s.io/v1beta1
Expand All @@ -66,4 +67,4 @@ resources:
images:
- name: kube-rbac-proxy
newName: gcr.io/kubebuilder/kube-rbac-proxy
newTag: v0.13.0
newTag: v0.13.1
2 changes: 1 addition & 1 deletion docs/dev/cve.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Here is an example of the command for three different scenarios
```
$ go mod why -m golang.org/x/time
# golang.org/x/time
github.com/ramendr/ramen/controllers
github.com/ramendr/ramen/internal/controller
golang.org/x/time/rate
```
Expand Down
Loading

0 comments on commit 76000a6

Please sign in to comment.