From 7b858b29928c5531d8abf3fbc5009507456e60a7 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Thu, 13 Apr 2023 16:26:14 +0200 Subject: [PATCH 1/5] go and sdk update update to golang 1.19 and operator-sdk 1.26 (cherry picked from commit 2a17cbabb01f1a2e4035279568fb4688055f8472) --- .../build-osp-director-operator.yaml | 4 ++-- .github/workflows/golangci-lint.yaml | 4 ++-- Dockerfile | 2 +- Makefile | 23 ++++++++++++++++--- ...openstack.org_openstackbackuprequests.yaml | 2 +- ...rector.openstack.org_openstackbackups.yaml | 2 +- ....openstack.org_openstackbaremetalsets.yaml | 2 +- ...rector.openstack.org_openstackclients.yaml | 2 +- ...enstack.org_openstackconfiggenerators.yaml | 2 +- ...openstack.org_openstackconfigversions.yaml | 2 +- ....openstack.org_openstackcontrolplanes.yaml | 2 +- ...rector.openstack.org_openstackdeploys.yaml | 2 +- ...openstack.org_openstackephemeralheats.yaml | 2 +- ...irector.openstack.org_openstackipsets.yaml | 2 +- ...r.openstack.org_openstackmacaddresses.yaml | 2 +- ...openstack.org_openstacknetattachments.yaml | 2 +- ...tor.openstack.org_openstacknetconfigs.yaml | 2 +- ...-director.openstack.org_openstacknets.yaml | 2 +- ...enstack.org_openstackprovisionservers.yaml | 2 +- ...irector.openstack.org_openstackvmsets.yaml | 2 +- 20 files changed, 41 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build-osp-director-operator.yaml b/.github/workflows/build-osp-director-operator.yaml index cfedce8b..7028b681 100644 --- a/.github/workflows/build-osp-director-operator.yaml +++ b/.github/workflows/build-osp-director-operator.yaml @@ -164,7 +164,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.18.x + go-version: 1.19.x - name: Checkout osp-director-operator repository uses: actions/checkout@v3 @@ -173,7 +173,7 @@ jobs: uses: redhat-actions/openshift-tools-installer@v1 with: source: github - operator-sdk: '1.23.0' + operator-sdk: '1.26.0' - name: Log in to Quay Registry uses: redhat-actions/podman-login@v1 diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 560076af..edafbcce 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -10,7 +10,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.18.x + go-version: 1.19.x - name: Checkout project code uses: actions/checkout@v3 - name: Checkout openstack-k8s-operators-ci project @@ -32,7 +32,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.18.x + go-version: 1.19.x - name: Checkout project code uses: actions/checkout@v3 - name: Run golangci lint diff --git a/Dockerfile b/Dockerfile index a7143d52..44f8fc99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG GOLANG_BUILDER=golang:1.18 +ARG GOLANG_BUILDER=golang:1.19 ARG OPERATOR_BASE_IMAGE=gcr.io/distroless/static:nonroot # Build the manager binary diff --git a/Makefile b/Makefile index 025e0be8..3dbb551c 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ endif # Image URL to use all building/pushing image targets IMG ?= controller:latest # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.24 +ENVTEST_K8S_VERSION = 1.25.0 # Metrics bind address METRICS_BIND_ADDRESS ?= :8080 CRD_OPTIONS ?= "crd:crdVersions=v1,generateEmbeddedObjectMeta=true" @@ -148,7 +148,7 @@ vet: ## Run go vet against code. .PHONY: test test: manifests generate fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out ##@ Build @@ -168,6 +168,23 @@ docker-build: test ## Build docker image with the manager. docker-push: ## Push docker image with the manager. podman push ${IMG} +# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple +# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: +# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ +# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ +# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=> than the export will fail) +# To properly provided solutions that supports more than one platform you should use this option. +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le +.PHONY: docker-buildx +docker-buildx: test ## Build and push docker image for the manager for cross-platform support + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + - docker buildx create --name project-v3-builder + docker buildx use project-v3-builder + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross + - docker buildx rm project-v3-builder + rm Dockerfile.cross + ##@ Deployment ifndef ignore-not-found @@ -205,7 +222,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions KUSTOMIZE_VERSION ?= v3.8.7 -CONTROLLER_TOOLS_VERSION ?= v0.9.2 +CONTROLLER_TOOLS_VERSION ?= v0.10.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize diff --git a/config/crd/bases/osp-director.openstack.org_openstackbackuprequests.yaml b/config/crd/bases/osp-director.openstack.org_openstackbackuprequests.yaml index e21e4963..cdaa7356 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackbackuprequests.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackbackuprequests.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackbackuprequests.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackbackups.yaml b/config/crd/bases/osp-director.openstack.org_openstackbackups.yaml index 7491ecbb..34b44677 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackbackups.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackbackups.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackbackups.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackbaremetalsets.yaml b/config/crd/bases/osp-director.openstack.org_openstackbaremetalsets.yaml index e27ff34b..70e1dd1f 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackbaremetalsets.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackbaremetalsets.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackbaremetalsets.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackclients.yaml b/config/crd/bases/osp-director.openstack.org_openstackclients.yaml index 1359538f..36c6f823 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackclients.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackclients.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackclients.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackconfiggenerators.yaml b/config/crd/bases/osp-director.openstack.org_openstackconfiggenerators.yaml index 8c919b48..29a0c2a4 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackconfiggenerators.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackconfiggenerators.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackconfiggenerators.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackconfigversions.yaml b/config/crd/bases/osp-director.openstack.org_openstackconfigversions.yaml index 182364ac..14d868b7 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackconfigversions.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackconfigversions.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackconfigversions.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackcontrolplanes.yaml b/config/crd/bases/osp-director.openstack.org_openstackcontrolplanes.yaml index a4531cf7..01b243de 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackcontrolplanes.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackcontrolplanes.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackcontrolplanes.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackdeploys.yaml b/config/crd/bases/osp-director.openstack.org_openstackdeploys.yaml index 8e3ec6c5..1e200c1e 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackdeploys.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackdeploys.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackdeploys.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackephemeralheats.yaml b/config/crd/bases/osp-director.openstack.org_openstackephemeralheats.yaml index 542eadf2..5b431f69 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackephemeralheats.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackephemeralheats.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackephemeralheats.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackipsets.yaml b/config/crd/bases/osp-director.openstack.org_openstackipsets.yaml index fb9a535f..e1ceb5ee 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackipsets.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackipsets.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackipsets.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackmacaddresses.yaml b/config/crd/bases/osp-director.openstack.org_openstackmacaddresses.yaml index bbf9a1a3..05ebfe4d 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackmacaddresses.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackmacaddresses.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackmacaddresses.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstacknetattachments.yaml b/config/crd/bases/osp-director.openstack.org_openstacknetattachments.yaml index 11dd8e61..d9c85571 100644 --- a/config/crd/bases/osp-director.openstack.org_openstacknetattachments.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstacknetattachments.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstacknetattachments.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstacknetconfigs.yaml b/config/crd/bases/osp-director.openstack.org_openstacknetconfigs.yaml index d7c9cfdf..701ba7ff 100644 --- a/config/crd/bases/osp-director.openstack.org_openstacknetconfigs.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstacknetconfigs.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstacknetconfigs.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstacknets.yaml b/config/crd/bases/osp-director.openstack.org_openstacknets.yaml index 5ae79e8f..34b126e3 100644 --- a/config/crd/bases/osp-director.openstack.org_openstacknets.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstacknets.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstacknets.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackprovisionservers.yaml b/config/crd/bases/osp-director.openstack.org_openstackprovisionservers.yaml index cacc2d51..d8790e1b 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackprovisionservers.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackprovisionservers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackprovisionservers.osp-director.openstack.org spec: diff --git a/config/crd/bases/osp-director.openstack.org_openstackvmsets.yaml b/config/crd/bases/osp-director.openstack.org_openstackvmsets.yaml index bbe48cf6..e82629ba 100644 --- a/config/crd/bases/osp-director.openstack.org_openstackvmsets.yaml +++ b/config/crd/bases/osp-director.openstack.org_openstackvmsets.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 + controller-gen.kubebuilder.io/version: v0.10.0 creationTimestamp: null name: openstackvmsets.osp-director.openstack.org spec: From b86feebee93d59b05b3a064a78780989d70454e7 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Thu, 13 Apr 2023 16:26:50 +0200 Subject: [PATCH 2/5] add .golangci.yaml config (cherry picked from commit e44a7d18dd321ad37a8ee5790f73a55d8d39e04a) --- .golangci.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..4789d022 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,17 @@ +linters: + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + - errorlint + - revive + - gofmt + - govet +linters-settings: + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter + - name: unused-parameter + severity: warning + disabled: true +run: + timeout: 5m From 764f56850412f3e09332203a9a81d5d96e571fb7 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Thu, 13 Apr 2023 16:29:06 +0200 Subject: [PATCH 3/5] make ci happy (cherry picked from commit 977844794fdf3c922a499bdbd1e86d217a992caf) --- api/shared/conditions.go | 26 -------------- api/shared/osp.go | 4 +-- api/v1beta1/common_openstackcontrolplane.go | 2 -- api/v1beta1/common_openstacknet.go | 6 ---- api/v1beta1/common_types.go | 2 -- api/v1beta1/openstackdeploy_webhook.go | 2 -- api/v1beta2/common_openstackcontrolplane.go | 2 -- api/v1beta2/common_types.go | 2 -- api/v1beta2/groupversion_info.go | 4 +-- .../openstackbaremetalset_controller.go | 14 ++++---- controllers/openstackclient_controller.go | 25 +++++++++---- .../openstackconfiggenerator_controller.go | 8 ----- .../openstackcontrolplane_controller.go | 11 ++---- controllers/openstackipset_controller.go | 2 -- controllers/openstacknet_controller.go | 2 -- controllers/openstacknetconfig_controller.go | 14 -------- controllers/openstackvmset_controller.go | 22 +++--------- go.mod | 2 +- go.sum | 1 - pkg/bindata_util/render.go | 2 +- pkg/common/configmap.go | 15 ++++---- pkg/common/errors.go | 36 ------------------- pkg/common/fencing.go | 3 +- pkg/common/hash.go | 2 +- pkg/common/ipam.go | 2 -- pkg/common/pod.go | 2 +- pkg/common/pvc.go | 4 +-- pkg/common/replicaset.go | 2 +- pkg/common/secret.go | 19 +++++----- pkg/common/service.go | 6 ++-- pkg/common/template_util.go | 3 +- pkg/openstackconfiggenerator/configmap.go | 22 +++++------- pkg/openstackipset/funcs.go | 4 --- pkg/openstacknet/funcs.go | 2 -- pkg/openstacknetattachment/funcs.go | 2 -- pkg/openstacknetconfig/funcs.go | 2 -- 36 files changed, 73 insertions(+), 206 deletions(-) delete mode 100644 pkg/common/errors.go diff --git a/api/shared/conditions.go b/api/shared/conditions.go index 383302ab..c9320c48 100644 --- a/api/shared/conditions.go +++ b/api/shared/conditions.go @@ -98,9 +98,7 @@ const ( CommonCondReasonServiceNotFound ConditionReason = "ServiceNotFound" ) -// // Client -// const ( // // condition reasones @@ -128,9 +126,7 @@ const ( OsClientCondReasonPodMissing ConditionReason = "OpenStackClientPodMissing" ) -// // ConfigGenerator -// const ( // // condition types @@ -195,9 +191,7 @@ const ( ConfigGeneratorCondReasonClusterServiceIPError ConditionReason = "ClusterServiceIPError" ) -// // BaremetalSet -// const ( // BaremetalSetCondTypeEmpty - special state for 0 requested BaremetalHosts and 0 already provisioned BaremetalSetCondTypeEmpty ConditionType = "Empty" @@ -261,9 +255,7 @@ const ( BaremetalSetCondReasonVirtualMachineCountZero ConditionReason = "BaremetalHostCountZero" ) -// // ControlPlane -// const ( // ControlPlaneEmpty - special state for 0 requested VMs and 0 already provisioned ControlPlaneEmpty ConditionType = "Empty" @@ -300,9 +292,7 @@ const ( ControlPlaneReasonDeploymentSSHKeysSecretCreateOrUpdateError ConditionReason = "DeploymentSSHKeysSecretCreateOrUpdateError" ) -// // Deploy -// const ( // // condition types @@ -337,9 +327,7 @@ const ( DeployCondReasonConfigCreate ConditionReason = "ConfigCreate" ) -// // EphemeralHeat -// const ( // // condition reasons @@ -365,9 +353,7 @@ const ( EphemeralHeatReady ConditionReason = "EphemeralHeatReady" ) -// // IPSet -// const ( // // condition reasones @@ -383,9 +369,7 @@ const ( IPSetCondReasonCreated ConditionReason = "OpenStackIPSetCreated" ) -// // MACAddress -// const ( // // condition types @@ -418,9 +402,7 @@ const ( MACCondReasonMACNotFound ConditionReason = "OpenStackMACNotFound" ) -// // Net -// const ( // // condition types @@ -449,9 +431,7 @@ const ( NetCondReasonNetNotFound ConditionReason = "OpenStackNetNotFound" ) -// // NetAttach -// const ( // // condition types @@ -478,9 +458,7 @@ const ( NetAttachCondReasonCreateError ConditionReason = "OpenStackNetAttachCreateError" ) -// // NetConfig -// const ( // NetConfigWaiting - the network configuration is blocked by prerequisite objects NetConfigWaiting ConditionType = "Waiting" @@ -505,9 +483,7 @@ const ( NetConfigCondReasonIPReservation ConditionReason = "IPReservationCreated" ) -// // ProvisionServer -// const ( // ProvisionServerCondTypeWaiting - something else is causing the OpenStackProvisionServer to wait ProvisionServerCondTypeWaiting ConditionType = "Waiting" @@ -548,9 +524,7 @@ const ( OpenStackProvisionServerCondReasonCreated ConditionReason = "OpenStackProvisionServerCreated" ) -// // VMSet -// const ( // // condition types diff --git a/api/shared/osp.go b/api/shared/osp.go index 0ade0bb4..799cc5da 100644 --- a/api/shared/osp.go +++ b/api/shared/osp.go @@ -37,8 +37,8 @@ const ( ) // GetOSPVersion - returns unified ospdirectorv1beta1.OSPVersion for upstream/downstream version -// - TemplateVersion16_2 for eitner 16.2 or upstream train -// - TemplateVersion17_0 for eitner 17.0 or upstream wallaby +// - TemplateVersion16_2 for eitner 16.2 or upstream train +// - TemplateVersion17_0 for eitner 17.0 or upstream wallaby func GetOSPVersion(parsedVersion string) (OSPVersion, error) { switch parsedVersion { case string(TemplateVersionTrain): diff --git a/api/v1beta1/common_openstackcontrolplane.go b/api/v1beta1/common_openstackcontrolplane.go index 9f6248c4..0f92f3a3 100644 --- a/api/v1beta1/common_openstackcontrolplane.go +++ b/api/v1beta1/common_openstackcontrolplane.go @@ -14,11 +14,9 @@ import ( ctrl "sigs.k8s.io/controller-runtime" ) -// // GetControlPlane - Get OSP ControlPlane CR where e.g. the status information has the // OSP version: controlPlane.Status.OSPVersion // FIXME: We assume there is only one ControlPlane CR for now (enforced by webhook), but this might need to change -// func GetControlPlane( c client.Client, obj metav1.Object, diff --git a/api/v1beta1/common_openstacknet.go b/api/v1beta1/common_openstacknet.go index 98952325..3c2d681f 100644 --- a/api/v1beta1/common_openstacknet.go +++ b/api/v1beta1/common_openstacknet.go @@ -15,10 +15,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// // AddOSNetNameLowerLabels - add osnetcfg CR label reference which is used in // the in the osnetcfg controller to watch this resource and reconcile -// func AddOSNetNameLowerLabels( log logr.Logger, labels map[string]string, @@ -85,10 +83,8 @@ func AddOSNetNameLowerLabels( return labels } -// // AddOSNetConfigRefLabel - add osnetcfg CR label reference which is used in // the in the osnetcfg controller to watch this resource and reconcile -// func AddOSNetConfigRefLabel( c client.Client, namespace string, @@ -201,9 +197,7 @@ func GetOpenStackNetsMapWithLabel( return osNetMap, nil } -// // GetOsNetCfg - -// func GetOsNetCfg( c client.Client, namespace string, diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 86a37091..7a9e71f7 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -56,9 +56,7 @@ type HostStatus struct { NetworkDataSecretName string `json:"networkDataSecretName"` } -// // SyncIPsetStatus - sync relevant information from IPSet to CR status -// func SyncIPsetStatus( cond *shared.Condition, instanceStatus map[string]HostStatus, diff --git a/api/v1beta1/openstackdeploy_webhook.go b/api/v1beta1/openstackdeploy_webhook.go index 94777279..5367e99c 100644 --- a/api/v1beta1/openstackdeploy_webhook.go +++ b/api/v1beta1/openstackdeploy_webhook.go @@ -110,10 +110,8 @@ func (r *OpenStackDeploy) ValidateDelete() error { return nil } -// // Validates all NNCPs created by the used osnetcfg to be in condition.Reason == nmstateshared.NodeNetworkConfigurationPolicyConditionSuccessfullyConfigured. // If not, stop deployment. User can overwrite this via parameter spec.SkipNNCPValidation: true -// func (r *OpenStackDeploy) validateNNCP() error { // 1) get the osctlplane of the namespace (right now there can only be one) diff --git a/api/v1beta2/common_openstackcontrolplane.go b/api/v1beta2/common_openstackcontrolplane.go index b980c338..fe7665da 100644 --- a/api/v1beta2/common_openstackcontrolplane.go +++ b/api/v1beta2/common_openstackcontrolplane.go @@ -15,11 +15,9 @@ import ( ctrl "sigs.k8s.io/controller-runtime" ) -// // GetControlPlane - Get OSP ControlPlane CR where e.g. the status information has the // OSP version: controlPlane.Status.OSPVersion // FIXME: We assume there is only one ControlPlane CR for now (enforced by webhook), but this might need to change -// func GetControlPlane( c client.Client, obj metav1.Object, diff --git a/api/v1beta2/common_types.go b/api/v1beta2/common_types.go index a6ee15bd..7af63a47 100644 --- a/api/v1beta2/common_types.go +++ b/api/v1beta2/common_types.go @@ -57,9 +57,7 @@ type HostStatus struct { NetworkDataSecretName string `json:"networkDataSecretName"` } -// // SyncIPsetStatus - sync relevant information from IPSet to CR status -// func SyncIPsetStatus( cond *shared.Condition, instanceStatus map[string]HostStatus, diff --git a/api/v1beta2/groupversion_info.go b/api/v1beta2/groupversion_info.go index 5780c968..5a80d237 100644 --- a/api/v1beta2/groupversion_info.go +++ b/api/v1beta2/groupversion_info.go @@ -15,8 +15,8 @@ limitations under the License. */ // Package v1beta2 contains API Schema definitions for the osp-director v1beta2 API group -//+kubebuilder:object:generate=true -//+groupName=osp-director.openstack.org +// +kubebuilder:object:generate=true +// +groupName=osp-director.openstack.org package v1beta2 import ( diff --git a/controllers/openstackbaremetalset_controller.go b/controllers/openstackbaremetalset_controller.go index e9e5b044..e5d9548e 100644 --- a/controllers/openstackbaremetalset_controller.go +++ b/controllers/openstackbaremetalset_controller.go @@ -1235,10 +1235,12 @@ func (r *OpenStackBaremetalSetReconciler) baremetalHostCleanup( return nil } -/* deleteOwnerRefLabeledObjects - cleans up namespaced objects outside the default namespace - using the owner reference labels added. - List of objects which get cleaned: - - user-data secret, openshift-machine-api namespace +/* +deleteOwnerRefLabeledObjects - cleans up namespaced objects outside the default namespace + + using the owner reference labels added. + List of objects which get cleaned: + - user-data secret, openshift-machine-api namespace */ func (r *OpenStackBaremetalSetReconciler) deleteOwnerRefLabeledObjects( ctx context.Context, @@ -1305,9 +1307,7 @@ func (r *OpenStackBaremetalSetReconciler) getPasswordSecret( return passwordSecret, ctrl.Result{}, nil } -// -// check/update instance status for annotated for deletion marked BMs -// +// check/update instance status for annotated for deletion marked BMs func (r *OpenStackBaremetalSetReconciler) checkBMHsAnnotatedForDeletion( ctx context.Context, instance *ospdirectorv1beta1.OpenStackBaremetalSet, diff --git a/controllers/openstackclient_controller.go b/controllers/openstackclient_controller.go index 5dac75d7..d7359fb2 100644 --- a/controllers/openstackclient_controller.go +++ b/controllers/openstackclient_controller.go @@ -18,6 +18,7 @@ package controllers import ( "context" + "errors" "fmt" "time" @@ -25,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/api/equality" k8s_errors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -586,8 +588,12 @@ func (r *OpenStackClientReconciler) podCreateOrUpdate( } if imageUpdate && isPodUpdate { - // init container image is mutable but does nothing so force a delete - return &common.ForbiddenPodSpecChangeError{Field: "Spec.InitContainers[0].Image"} + // init container image is mutable but does nothing so force a delete by triggering NewForbidden + return k8s_errors.NewForbidden( + schema.GroupResource{Group: "", Resource: "pods"}, // Specify the group and resource type + pod.Name, + errors.New("Cannot update Pod spec field - Spec.InitContainers[0].Image"), // Specify the error message + ) } err := controllerutil.SetControllerReference(instance, pod, r.Scheme) @@ -603,7 +609,16 @@ func (r *OpenStackClientReconciler) podCreateOrUpdate( return nil }) if err != nil { - if common.IsForbiddenPodSpecChangeError(err) || k8s_errors.IsInvalid(err) { + var forbiddenPodSpecChangeErr *k8s_errors.StatusError + + forbiddenPodSpec := false + if errors.As(err, &forbiddenPodSpecChangeErr) { + if forbiddenPodSpecChangeErr.ErrStatus.Reason == metav1.StatusReasonForbidden { + forbiddenPodSpec = true + } + } + + if forbiddenPodSpec || k8s_errors.IsInvalid(err) { // Delete pod when an unsupported change was requested, like // e.g. additional controller VM got up. We just re-create the // openstackclient pod @@ -651,9 +666,7 @@ func (r *OpenStackClientReconciler) podCreateOrUpdate( return nil } -// // NetworkAttachmentDefinition, SriovNetwork and SriovNetworkNodePolicy -// func (r *OpenStackClientReconciler) verifyNetworkAttachments( ctx context.Context, instance *ospdirectorv1beta1.OpenStackClient, @@ -711,9 +724,7 @@ func (r *OpenStackClientReconciler) verifyNetworkAttachments( return ctrl.Result{}, nil } -// // PVCs -// func (r *OpenStackClientReconciler) createPVCs( ctx context.Context, instance *ospdirectorv1beta1.OpenStackClient, diff --git a/controllers/openstackconfiggenerator_controller.go b/controllers/openstackconfiggenerator_controller.go index 49785434..9007e6d0 100644 --- a/controllers/openstackconfiggenerator_controller.go +++ b/controllers/openstackconfiggenerator_controller.go @@ -701,9 +701,7 @@ func (r *OpenStackConfigGeneratorReconciler) verifyNodeResourceStatus( return msg, true, nil } -// // Fencing considerations -// func (r *OpenStackConfigGeneratorReconciler) createFencingEnvironmentFiles( ctx context.Context, instance *ospdirectorv1beta1.OpenStackConfigGenerator, @@ -797,9 +795,7 @@ func (r *OpenStackConfigGeneratorReconciler) createFencingEnvironmentFiles( return renderedFencingTemplate, nil } -// // generate TripleoDeploy configmap with environment file containing predictible IPs -// func (r *OpenStackConfigGeneratorReconciler) createTripleoDeployCM( ctx context.Context, instance *ospdirectorv1beta1.OpenStackConfigGenerator, @@ -949,9 +945,7 @@ func (r *OpenStackConfigGeneratorReconciler) getClusterServiceEndpoint( return "", k8s_errors.NewNotFound(appsv1.Resource("service"), fmt.Sprint(labelSelector)) } -// // Render VM role nic templates, but only for tripleo roles -// func (r *OpenStackConfigGeneratorReconciler) createVMRoleNicTemplates( instance *ospdirectorv1beta1.OpenStackConfigGenerator, ospVersion shared.OSPVersion, @@ -1008,10 +1002,8 @@ func (r *OpenStackConfigGeneratorReconciler) createVMRoleNicTemplates( return roleNicTemplates, nil } -// // Verify if ConfigGeneratorInputLabel label is set on the CM which is used to limit // the CMs to watch -// func (r *OpenStackConfigGeneratorReconciler) addConfigGeneratorInputLabel( ctx context.Context, instance *ospdirectorv1beta1.OpenStackConfigGenerator, diff --git a/controllers/openstackcontrolplane_controller.go b/controllers/openstackcontrolplane_controller.go index 75aeb549..7852d005 100644 --- a/controllers/openstackcontrolplane_controller.go +++ b/controllers/openstackcontrolplane_controller.go @@ -426,9 +426,7 @@ func (r *OpenStackControlPlaneReconciler) getNormalizedStatus(status *ospdirecto return s } -// // create or get hash of "tripleo-passwords" controlplane.TripleoPasswordSecret secret -// func (r *OpenStackControlPlaneReconciler) createOrGetTripleoPasswords( ctx context.Context, instance *ospdirectorv1beta2.OpenStackControlPlane, @@ -592,10 +590,9 @@ func (r *OpenStackControlPlaneReconciler) createOrUpdatePasswordSecret( return nil } -// // Secret - used for deployment to ssh into the overcloud nodes, -// gets added to the controller VMs cloud-admin user using cloud-init // +// gets added to the controller VMs cloud-admin user using cloud-init func (r *OpenStackControlPlaneReconciler) createOrGetDeploymentSecret( ctx context.Context, instance *ospdirectorv1beta2.OpenStackControlPlane, @@ -735,9 +732,7 @@ func (r *OpenStackControlPlaneReconciler) verifyConfigMapExist( return ctrl.Result{}, nil } -// // Create VMSets -// func (r *OpenStackControlPlaneReconciler) createOrUpdateVMSets( ctx context.Context, instance *ospdirectorv1beta2.OpenStackControlPlane, @@ -1008,9 +1003,7 @@ func (r *OpenStackControlPlaneReconciler) ensureVIPs( return ctrl.Result{}, nil } -// // verify if API storageversionmigration is required -// func (r *OpenStackControlPlaneReconciler) ensureStorageVersionMigration( ctx context.Context, instance *ospdirectorv1beta2.OpenStackControlPlane, @@ -1032,7 +1025,7 @@ func (r *OpenStackControlPlaneReconciler) ensureStorageVersionMigration( } if err := r.List(ctx, smList, listOpts...); err != nil { - err = fmt.Errorf("Error listing services for %s: %v", smList.GroupVersionKind().Kind, err) + err = fmt.Errorf("Error listing services for %s: %w", smList.GroupVersionKind().Kind, err) return ctrl.Result{}, err } diff --git a/controllers/openstackipset_controller.go b/controllers/openstackipset_controller.go index 490c92a0..f3e88729 100644 --- a/controllers/openstackipset_controller.go +++ b/controllers/openstackipset_controller.go @@ -327,9 +327,7 @@ func (r *OpenStackIPSetReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -// // create hostnames for the requested number of systems -// func (r *OpenStackIPSetReconciler) createNewHostnames( instance *ospdirectorv1beta1.OpenStackIPSet, cond *shared.Condition, diff --git a/controllers/openstacknet_controller.go b/controllers/openstacknet_controller.go index ad10351a..5aad5665 100644 --- a/controllers/openstacknet_controller.go +++ b/controllers/openstacknet_controller.go @@ -266,9 +266,7 @@ func (r *OpenStackNetReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -// // createOrUpdateNetworkAttachmentDefinition - create or update NetworkAttachmentDefinition -// func (r *OpenStackNetReconciler) createOrUpdateNetworkAttachmentDefinition( ctx context.Context, instance *ospdirectorv1beta1.OpenStackNet, diff --git a/controllers/openstacknetconfig_controller.go b/controllers/openstacknetconfig_controller.go index 48520b5a..6193358a 100644 --- a/controllers/openstacknetconfig_controller.go +++ b/controllers/openstacknetconfig_controller.go @@ -797,9 +797,7 @@ func (r *OpenStackNetConfigReconciler) osnetCleanup( return nil } -// // create or update the OpenStackMACAddress object -// func (r *OpenStackNetConfigReconciler) createOrUpdateOpenStackMACAddress( ctx context.Context, instance *ospdirectorv1beta1.OpenStackNetConfig, @@ -1050,9 +1048,7 @@ func (r *OpenStackNetConfigReconciler) getMACStatus( } -// // create or update the OpenStackMACAddress object -// func (r *OpenStackNetConfigReconciler) ensureMACReservation( instance *ospdirectorv1beta1.OpenStackNetConfig, cond *shared.Condition, @@ -1143,9 +1139,7 @@ func (r *OpenStackNetConfigReconciler) ensureMACReservation( return nodeMACReservation, nil } -// // allMACReservations - get all reservations from static + dynamic created -// func (r *OpenStackNetConfigReconciler) allMACReservations( instance *ospdirectorv1beta1.OpenStackNetConfig, macAddress *ospdirectorv1beta1.OpenStackMACAddress, @@ -1167,9 +1161,7 @@ func (r *OpenStackNetConfigReconciler) allMACReservations( return reservations } -// // add reservations from deleted nodes if Spec.PreserveReservations -// func (r *OpenStackNetConfigReconciler) preserveMACReservations( macAddress *ospdirectorv1beta1.OpenStackMACAddress, roleMACReservation *map[string]ospdirectorv1beta1.OpenStackMACNodeReservation, @@ -1190,9 +1182,7 @@ func (r *OpenStackNetConfigReconciler) preserveMACReservations( } -// // create or update the OpenStackMACAddress object -// func (r *OpenStackNetConfigReconciler) ensureIPReservation( ctx context.Context, instance *ospdirectorv1beta1.OpenStackNetConfig, @@ -1300,10 +1290,8 @@ func (r *OpenStackNetConfigReconciler) ensureIPReservation( return osNet.Spec.RoleReservations, nil } -// // ensureIPs - create IP reservations for all nodes of a role. // If there is already an existing IP its being reused -// func (r *OpenStackNetConfigReconciler) ensureIPs( instance *ospdirectorv1beta1.OpenStackNetConfig, cond *shared.Condition, @@ -1471,9 +1459,7 @@ func (r *OpenStackNetConfigReconciler) ensureIPs( return nil } -// // getNetDesiredCount - get the total of all networks subnets -// func (r *OpenStackNetConfigReconciler) getNetDesiredCount( networks []ospdirectorv1beta1.Network, ) int { diff --git a/controllers/openstackvmset_controller.go b/controllers/openstackvmset_controller.go index 70818e6a..4eeac144 100644 --- a/controllers/openstackvmset_controller.go +++ b/controllers/openstackvmset_controller.go @@ -1165,9 +1165,7 @@ func (r *OpenStackVMSetReconciler) vmCreateInstance( return nil } -// // check if specified password secret exists -// func (r *OpenStackVMSetReconciler) getPasswordSecret( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, @@ -1203,9 +1201,7 @@ func (r *OpenStackVMSetReconciler) getPasswordSecret( return string(passwordSecret.Data["NodeRootPassword"]), ctrl.Result{}, nil } -// // Create CloudInitSecret secret for the vmset -// func (r *OpenStackVMSetReconciler) createCloudInitSecret( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, @@ -1239,9 +1235,7 @@ func (r *OpenStackVMSetReconciler) createCloudInitSecret( return nil } -// // NetworkAttachmentDefinition, SriovNetwork and SriovNetworkNodePolicy -// func (r *OpenStackVMSetReconciler) verifyNetworkAttachments( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, @@ -1323,9 +1317,7 @@ func (r *OpenStackVMSetReconciler) verifyNetworkAttachments( return nadMap, ctrl.Result{}, nil } -// -// check/update instance status for annotated for deletion marked VMs -// +// check/update instance status for annotated for deletion marked VMs func (r *OpenStackVMSetReconciler) checkVMsAnnotatedForDeletion( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, @@ -1432,9 +1424,7 @@ func (r *OpenStackVMSetReconciler) getDeletedVMOSPHostnames( return annotatedVMs, nil } -// -// Create BaseImage for the VMSet -// +// Create BaseImage for the VMSet func (r *OpenStackVMSetReconciler) createBaseImage( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, @@ -1595,9 +1585,7 @@ func (r *OpenStackVMSetReconciler) virtualMachineDeprovision( return virtualMachine.Name, nil } -// -// Create/Update NetworkData -// +// Create/Update NetworkData func (r *OpenStackVMSetReconciler) createNetworkData( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, @@ -1682,9 +1670,7 @@ func (r *OpenStackVMSetReconciler) createNetworkData( return vmDetails, nil } -// -// Create the VM objects -// +// Create the VM objects func (r *OpenStackVMSetReconciler) createVMs( ctx context.Context, instance *ospdirectorv1beta2.OpenStackVMSet, diff --git a/go.mod b/go.mod index b6c3eb3c..529db95f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/openstack-k8s-operators/osp-director-operator -go 1.18 +go 1.19 exclude k8s.io/cluster-bootstrap v0.0.0 diff --git a/go.sum b/go.sum index 63d323bf..8a9610e2 100644 --- a/go.sum +++ b/go.sum @@ -1097,7 +1097,6 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= diff --git a/pkg/bindata_util/render.go b/pkg/bindata_util/render.go index 50959cb3..18a5b562 100644 --- a/pkg/bindata_util/render.go +++ b/pkg/bindata_util/render.go @@ -99,7 +99,7 @@ func RenderTemplate(path string, d *RenderData) ([]*unstructured.Unstructured, e for { u := unstructured.Unstructured{} if err := decoder.Decode(&u); err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return nil, errors.Wrapf(err, "failed to unmarshal manifest %s", path) diff --git a/pkg/common/configmap.go b/pkg/common/configmap.go index 20d67591..5d171a3b 100644 --- a/pkg/common/configmap.go +++ b/pkg/common/configmap.go @@ -80,12 +80,12 @@ func createOrUpdateConfigMap( return nil }) if err != nil { - return "", op, fmt.Errorf("error create/updating configmap: %v", err) + return "", op, fmt.Errorf("error create/updating configmap: %w", err) } configMapHash, err := ObjectHash(configMap) if err != nil { - return "", op, fmt.Errorf("error calculating configuration hash: %v", err) + return "", op, fmt.Errorf("error calculating configuration hash: %w", err) } return configMapHash, op, nil @@ -128,7 +128,7 @@ func createOrGetCustomConfigMap( configMapHash, err := ObjectHash(configMap) if err != nil { - return "", fmt.Errorf("error calculating configuration hash: %v", err) + return "", fmt.Errorf("error calculating configuration hash: %w", err) } return configMapHash, nil @@ -215,7 +215,7 @@ func CreateOrGetCustomConfigMap( configMapHash, err := ObjectHash(configMap) if err != nil { - return "", fmt.Errorf("error calculating configuration hash: %v", err) + return "", fmt.Errorf("error calculating configuration hash: %w", err) } return configMapHash, nil @@ -237,12 +237,11 @@ func GetConfigMapAndHashWithName( } configMapHash, err := ObjectHash(configMap) if err != nil { - return configMap, "", fmt.Errorf("error calculating configuration hash: %v", err) + return configMap, "", fmt.Errorf("error calculating configuration hash: %w", err) } return configMap, configMapHash, nil } -// // GetConfigMap - Get config map // // if the config map is not found, requeue after requeueTimeout in seconds @@ -260,7 +259,7 @@ func GetConfigMap( err := r.GetClient().Get(ctx, types.NamespacedName{Name: configMapName, Namespace: object.GetNamespace()}, configMap) if err != nil { if k8s_errors.IsNotFound(err) { - cond.Message = fmt.Sprintf("%s config map does not exist: %v", configMapName, err) + cond.Message = fmt.Sprintf("%s config map does not exist: %v", configMapName, err.Error()) cond.Reason = conditionDetails.ConditionNotFoundReason cond.Type = conditionDetails.ConditionNotFoundType @@ -268,7 +267,7 @@ func GetConfigMap( return configMap, ctrl.Result{RequeueAfter: time.Duration(requeueTimeout) * time.Second}, nil } - cond.Message = fmt.Sprintf("Error getting %s config map: %v", configMapName, err) + cond.Message = fmt.Sprintf("Error getting %s config map: %v", configMapName, err.Error()) cond.Reason = conditionDetails.ConditionErrordReason cond.Type = conditionDetails.ConditionErrorType err = WrapErrorForObject(cond.Message, object, err) diff --git a/pkg/common/errors.go b/pkg/common/errors.go deleted file mode 100644 index 694b2a91..00000000 --- a/pkg/common/errors.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2022 Red Hat - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package common - -import ( - "fmt" -) - -// ForbiddenPodSpecChangeError - error returned when Pod must be recreate -type ForbiddenPodSpecChangeError struct { - Field string -} - -func (e *ForbiddenPodSpecChangeError) Error() string { - return fmt.Sprintf("cannot update Pod spec field: %s", e.Field) -} - -// IsForbiddenPodSpecChangeError - -func IsForbiddenPodSpecChangeError(err error) bool { - _, ok := err.(*ForbiddenPodSpecChangeError) - return ok -} diff --git a/pkg/common/fencing.go b/pkg/common/fencing.go index 24fb931d..6170b887 100644 --- a/pkg/common/fencing.go +++ b/pkg/common/fencing.go @@ -4,6 +4,7 @@ import ( "archive/tar" "bytes" "compress/gzip" + "errors" "fmt" "io" @@ -49,7 +50,7 @@ func GetCustomFencingRoles(customBinaryData map[string][]byte) ([]string, error) header, err := tarReader.Next() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } diff --git a/pkg/common/hash.go b/pkg/common/hash.go index 6a4a7c3b..0e539918 100644 --- a/pkg/common/hash.go +++ b/pkg/common/hash.go @@ -29,7 +29,7 @@ func ObjectHash(i interface{}) (string, error) { // Convert the hashSource to a byte slice so that it can be hashed hashBytes, err := json.Marshal(i) if err != nil { - return "", fmt.Errorf("unable to convert to JSON: %v", err) + return "", fmt.Errorf("unable to convert to JSON: %w", err) } hash := sha256.Sum256(hashBytes) return rand.SafeEncodeString(fmt.Sprint(hash)), nil diff --git a/pkg/common/ipam.go b/pkg/common/ipam.go index 100332fc..7b44e2cd 100644 --- a/pkg/common/ipam.go +++ b/pkg/common/ipam.go @@ -220,9 +220,7 @@ func IPToBigInt(IPv6Addr net.IP) *big.Int { return IPv6Int } -// // GetCidrParts - returns addr and cidr suffix -// func GetCidrParts(cidr string) (string, int, error) { ipAddr, net, err := net.ParseCIDR(cidr) if err != nil { diff --git a/pkg/common/pod.go b/pkg/common/pod.go index c481259f..2ba5833d 100644 --- a/pkg/common/pod.go +++ b/pkg/common/pod.go @@ -63,7 +63,7 @@ func DeletePodsWithLabel( client.MatchingLabels(labelSelectorMap), ) if err != nil && !k8s_errors.IsNotFound(err) { - err = fmt.Errorf("Error DeleteAllOf Pod %v", err) + err = fmt.Errorf("Error DeleteAllOf Pod %w", err) return err } diff --git a/pkg/common/pvc.go b/pkg/common/pvc.go index 78c33718..772331d6 100644 --- a/pkg/common/pvc.go +++ b/pkg/common/pvc.go @@ -56,12 +56,12 @@ func CreateOrUpdatePvc(ctx context.Context, r ReconcilerCommon, obj metav1.Objec err := controllerutil.SetOwnerReference(obj, pvc, r.GetScheme()) if err != nil { - return fmt.Errorf("error set controller reverence for PVC: %v", err) + return fmt.Errorf("error set controller reverence for PVC: %w", err) } return nil }) if err != nil { - return nil, op, fmt.Errorf("error create/updating pvc: %v", err) + return nil, op, fmt.Errorf("error create/updating pvc: %w", err) } return pvc, op, nil diff --git a/pkg/common/replicaset.go b/pkg/common/replicaset.go index dbffbfdd..515de2d9 100644 --- a/pkg/common/replicaset.go +++ b/pkg/common/replicaset.go @@ -40,7 +40,7 @@ func DeleteReplicasetsWithLabel( client.MatchingLabels(labelSelectorMap), ) if err != nil && !k8s_errors.IsNotFound(err) { - err = fmt.Errorf("Error DeleteAllOf ReplicaSet: %v", err) + err = fmt.Errorf("Error DeleteAllOf ReplicaSet: %w", err) return err } diff --git a/pkg/common/secret.go b/pkg/common/secret.go index 0521eecc..1aaf63ec 100644 --- a/pkg/common/secret.go +++ b/pkg/common/secret.go @@ -58,7 +58,7 @@ func GetSecret( secretHash, err := ObjectHash(secret) if err != nil { - return nil, "", fmt.Errorf("error calculating configuration hash: %v", err) + return nil, "", fmt.Errorf("error calculating configuration hash: %w", err) } return secret, secretHash, nil } @@ -101,12 +101,12 @@ func CreateOrUpdateSecret( return nil }) if err != nil { - return "", op, fmt.Errorf("error create/updating secret: %v", err) + return "", op, fmt.Errorf("error create/updating secret: %w", err) } secretHash, err := ObjectHash(secret) if err != nil { - return "", "", fmt.Errorf("error calculating configuration hash: %v", err) + return "", "", fmt.Errorf("error calculating configuration hash: %w", err) } return secretHash, op, err @@ -217,7 +217,7 @@ func createOrUpdateSecret( secretHash, err := ObjectHash(secret) if err != nil { - return "", op, fmt.Errorf("error calculating configuration hash: %v", err) + return "", op, fmt.Errorf("error calculating configuration hash: %w", err) } return secretHash, op, nil @@ -265,7 +265,7 @@ func createOrGetCustomSecret( secretHash, err := ObjectHash(secret) if err != nil { - return "", fmt.Errorf("error calculating configuration hash: %v", err) + return "", fmt.Errorf("error calculating configuration hash: %w", err) } return secretHash, nil @@ -321,16 +321,14 @@ func DeleteSecretsWithLabel( client.MatchingLabels(labelSelectorMap), ) if err != nil && !k8s_errors.IsNotFound(err) { - err = fmt.Errorf("Error DeleteAllOf Secret: %v", err) + err = fmt.Errorf("Error DeleteAllOf Secret: %w", err) return err } return nil } -// // DeleteSecretsWithName - Delete names secret object in namespace -// func DeleteSecretsWithName( ctx context.Context, r ReconcilerCommon, @@ -363,7 +361,6 @@ func DeleteSecretsWithName( return nil } -// // GetDataFromSecret - Get data from Secret // // if the secret or data is not found, requeue after requeueTimeout in seconds @@ -383,7 +380,7 @@ func GetDataFromSecret( secret, _, err := GetSecret(ctx, r, secretName, object.GetNamespace()) if err != nil { if k8s_errors.IsNotFound(err) { - cond.Message = fmt.Sprintf("%s secret does not exist: %v", secretName, err) + cond.Message = fmt.Sprintf("%s secret does not exist: %v", secretName, err.Error()) cond.Reason = conditionDetails.ConditionNotFoundReason cond.Type = conditionDetails.ConditionNotFoundType @@ -391,7 +388,7 @@ func GetDataFromSecret( return data, ctrl.Result{RequeueAfter: time.Duration(requeueTimeout) * time.Second}, nil } - cond.Message = fmt.Sprintf("Error getting %s Secret: %v", secretName, err) + cond.Message = fmt.Sprintf("Error getting %s Secret: %v", secretName, err.Error()) cond.Reason = conditionDetails.ConditionErrordReason cond.Type = conditionDetails.ConditionErrorType err = WrapErrorForObject(cond.Message, object, err) diff --git a/pkg/common/service.go b/pkg/common/service.go index cbbd9821..11d03935 100644 --- a/pkg/common/service.go +++ b/pkg/common/service.go @@ -45,7 +45,7 @@ func DeleteServicesWithLabel( } if err := r.GetClient().List(ctx, serviceList, listOpts...); err != nil { - err = fmt.Errorf("Error listing services for %s: %v", obj.GetName(), err) + err = fmt.Errorf("Error listing services for %s: %w", obj.GetName(), err) return err } @@ -53,7 +53,7 @@ func DeleteServicesWithLabel( for _, pod := range serviceList.Items { err := r.GetClient().Delete(ctx, &pod) if err != nil && !k8s_errors.IsNotFound(err) { - err = fmt.Errorf("Error deleting service %s: %v", pod.Name, err) + err = fmt.Errorf("Error deleting service %s: %w", pod.Name, err) return err } } @@ -75,7 +75,7 @@ func GetServicesListWithLabel( // otherwise we hit "Error listing services for labels: map[ ... ] - unable to get: default because of unknown namespace for the cache" serviceList, err := r.GetKClient().CoreV1().Services(namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelectorString}) if err != nil { - err = fmt.Errorf("Error listing services for labels: %v - %v", labelSelectorMap, err) + err = fmt.Errorf("Error listing services for labels: %v - %w", labelSelectorMap, err) return nil, err } diff --git a/pkg/common/template_util.go b/pkg/common/template_util.go index e917d806..88bfcf30 100644 --- a/pkg/common/template_util.go +++ b/pkg/common/template_util.go @@ -141,7 +141,8 @@ func ExecuteTemplateData(templateData string, data interface{}) (string, error) // ExecuteTemplateFile creates a template from the file and // execute it with the specified data // Note: mschuppert - can be removed when all operators switched -// to the above ones. +// +// to the above ones. func ExecuteTemplateFile(filename string, data interface{}) (string, error) { templates := os.Getenv("OPERATOR_TEMPLATES") diff --git a/pkg/openstackconfiggenerator/configmap.go b/pkg/openstackconfiggenerator/configmap.go index 60d8e2ff..c7a322f7 100644 --- a/pkg/openstackconfiggenerator/configmap.go +++ b/pkg/openstackconfiggenerator/configmap.go @@ -52,13 +52,14 @@ type roleNetworkType struct { } // information to build NodePortMap entry: -// IPaddr: 192.168.24.9 -// IPAddrSubnet : 192.168.24.9/24 -// IPAddrURI: 192.168.24.9 -// IPv6addr: 2001:DB8:24::9 -// IPv6AddrSubnet : 2001:DB8:24::9/64 -// IPv6AddrURI: [2001:DB8:24::9] -// Network: flattened network details +// +// IPaddr: 192.168.24.9 +// IPAddrSubnet : 192.168.24.9/24 +// IPAddrURI: 192.168.24.9 +// IPv6addr: 2001:DB8:24::9 +// IPv6AddrSubnet : 2001:DB8:24::9/64 +// IPv6AddrURI: [2001:DB8:24::9] +// Network: flattened network details type roleIPType struct { IPaddr string IPAddrURI string @@ -236,10 +237,9 @@ func CreateConfigMapParams( } -// // createNetworksMap - create map with network details and map of subnet -> network_lower name used when creating the rolesMap -// to get the network name from the subnet name // +// to get the network name from the subnet name func createNetworksMap( ospVersion shared.OSPVersion, netConfig *ospdirectorv1beta1.OpenStackNetConfig, @@ -369,9 +369,7 @@ func IsRoleIncluded(roleName string, instance *ospdirectorv1beta1.OpenStackConfi } -// // createRolesMap - create map with all roles -// func createRolesMap( ctx context.Context, r common.ReconcilerCommon, @@ -510,9 +508,7 @@ func createRolesMap( return nil } -// // isVMRole - check if role is VMset and tripleo role -// func isVMRole( ctx context.Context, r common.ReconcilerCommon, diff --git a/pkg/openstackipset/funcs.go b/pkg/openstackipset/funcs.go index 16f57e1f..0a161413 100644 --- a/pkg/openstackipset/funcs.go +++ b/pkg/openstackipset/funcs.go @@ -18,9 +18,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" ) -// // EnsureIPs - Creates IPSet and verify/wait for IPs created -// func EnsureIPs( ctx context.Context, r common.ReconcilerCommon, @@ -130,9 +128,7 @@ func EnsureIPs( return status, reconcile.Result{}, nil } -// // createOrUpdateIPSet - Creates or updates IPSet -// func createOrUpdateIPSet( ctx context.Context, r common.ReconcilerCommon, diff --git a/pkg/openstacknet/funcs.go b/pkg/openstacknet/funcs.go index b268f647..6a9b066a 100644 --- a/pkg/openstacknet/funcs.go +++ b/pkg/openstacknet/funcs.go @@ -49,9 +49,7 @@ func GetOpenStackNetsBindingMap( return osNetBindings, nil } -// // GetAllIPReservations - get all reservations from the osnet (already synamic created, static configured + just now new created) -// func GetAllIPReservations( osNet *ospdirectorv1beta1.OpenStackNet, newReservations []ospdirectorv1beta1.IPReservation, diff --git a/pkg/openstacknetattachment/funcs.go b/pkg/openstacknetattachment/funcs.go index 8868ea09..800170f8 100644 --- a/pkg/openstacknetattachment/funcs.go +++ b/pkg/openstacknetattachment/funcs.go @@ -13,9 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// // GetOpenStackNetAttachmentWithLabel - Return OpenStackNet with labels -// func GetOpenStackNetAttachmentWithLabel( ctx context.Context, r common.ReconcilerCommon, diff --git a/pkg/openstacknetconfig/funcs.go b/pkg/openstacknetconfig/funcs.go index 24e26feb..1d7d8a1e 100644 --- a/pkg/openstacknetconfig/funcs.go +++ b/pkg/openstacknetconfig/funcs.go @@ -12,9 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// // WaitOnIPsCreated - Wait for IPs created on all configured networks -// func WaitOnIPsCreated( r common.ReconcilerCommon, obj client.Object, From f65f0f0fb20998ac242a28853f9f866969adfa74 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Thu, 13 Apr 2023 08:29:47 +0200 Subject: [PATCH 4/5] update to ginkgo v2 (cherry picked from commit 9695ba59022d37571e5c79e943a8bbdc4b33f01b) --- api/v1beta1/webhook_suite_test.go | 49 +++++++++++++++--------------- api/v1beta2/webhook_suite_test.go | 48 ++++++++++++++--------------- controllers/suite_test.go | 50 ++++++++++++++----------------- go.mod | 7 +++-- go.sum | 2 ++ 5 files changed, 78 insertions(+), 78 deletions(-) diff --git a/api/v1beta1/webhook_suite_test.go b/api/v1beta1/webhook_suite_test.go index 15f6f178..1b02d53e 100644 --- a/api/v1beta1/webhook_suite_test.go +++ b/api/v1beta1/webhook_suite_test.go @@ -1,12 +1,9 @@ /* - - +Copyright 2023. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,36 +14,43 @@ limitations under the License. package v1beta1 import ( + "context" + "crypto/tls" + "fmt" + "net" + "path/filepath" "testing" + "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + admissionv1beta1 "k8s.io/api/admission/v1beta1" //+kubebuilder:scaffold:imports - - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/rest" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -/* mpryc: golangci - comment out unused variables var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment var ctx context.Context var cancel context.CancelFunc -*/ func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) - RunSpecsWithDefaultAndCustomReporters(t, - "Webhook Suite", - []Reporter{printer.NewlineReporter{}}) + RunSpecs(t, "Webhook Suite") } -/* mschuppert: disable checks for now var _ = BeforeSuite(func() { logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) @@ -61,7 +65,9 @@ var _ = BeforeSuite(func() { }, } - cfg, err := testEnv.Start() + var err error + // cfg is defined in this file globally. + cfg, err = testEnv.Start() Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) @@ -90,19 +96,15 @@ var _ = BeforeSuite(func() { }) Expect(err).NotTo(HaveOccurred()) - err = (&OpenStackNetAttachment{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) - - err = (&OpenStackIPSet{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) + //err = (&Glance{}).SetupWebhookWithManager(mgr) + //Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:webhook go func() { + defer GinkgoRecover() err = mgr.Start(ctx) - if err != nil { - Expect(err).NotTo(HaveOccurred()) - } + Expect(err).NotTo(HaveOccurred()) }() // wait for the webhook server to get ready @@ -117,7 +119,7 @@ var _ = BeforeSuite(func() { return nil }).Should(Succeed()) -}, 60) +}) var _ = AfterSuite(func() { cancel() @@ -125,4 +127,3 @@ var _ = AfterSuite(func() { err := testEnv.Stop() Expect(err).NotTo(HaveOccurred()) }) -*/ diff --git a/api/v1beta2/webhook_suite_test.go b/api/v1beta2/webhook_suite_test.go index 92264131..efa8d158 100644 --- a/api/v1beta2/webhook_suite_test.go +++ b/api/v1beta2/webhook_suite_test.go @@ -1,12 +1,9 @@ /* - - +Copyright 2023. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,35 +14,43 @@ limitations under the License. package v1beta2 import ( + "context" + "crypto/tls" + "fmt" + "net" + "path/filepath" "testing" + "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + admissionv1beta1 "k8s.io/api/admission/v1beta1" //+kubebuilder:scaffold:imports - - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/rest" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -/* var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment var ctx context.Context var cancel context.CancelFunc -*/ + func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) - RunSpecsWithDefaultAndCustomReporters(t, - "Webhook Suite", - []Reporter{printer.NewlineReporter{}}) + RunSpecs(t, "Webhook Suite") } -/* var _ = BeforeSuite(func() { logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) @@ -60,7 +65,9 @@ var _ = BeforeSuite(func() { }, } - cfg, err := testEnv.Start() + var err error + // cfg is defined in this file globally. + cfg, err = testEnv.Start() Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) @@ -89,14 +96,8 @@ var _ = BeforeSuite(func() { }) Expect(err).NotTo(HaveOccurred()) - err = (&OpenStackVMSet{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) - - err = (&OpenStackControlPlane{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) - - err = (&OpenStackBackup{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) + // err = (&OpenStackVMSet{}).SetupWebhookWithManager(mgr) + // Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:webhook @@ -118,7 +119,7 @@ var _ = BeforeSuite(func() { return nil }).Should(Succeed()) -}, 60) +}) var _ = AfterSuite(func() { cancel() @@ -126,4 +127,3 @@ var _ = AfterSuite(func() { err := testEnv.Stop() Expect(err).NotTo(HaveOccurred()) }) -*/ diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 4000f88a..9656d8e3 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -1,12 +1,9 @@ /* - - +Copyright 2023. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,60 +14,59 @@ limitations under the License. package controllers import ( + "path/filepath" "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - // +kubebuilder:scaffold:imports + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + //+kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -/* mpryc: golangci - comment out unused variables var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment -*/ func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) - RunSpecsWithDefaultAndCustomReporters(t, - "Controller Suite", - []Reporter{printer.NewlineReporter{}}) + RunSpecs(t, "Controller Suite") } -/* mschuppert: disable checks for now -var _ = BeforeSuite(func(done Done) { - logf.SetLogger(zap.LoggerTo(GinkgoWriter, true)) +var _ = BeforeSuite(func() { + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) By("bootstrapping test environment") testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, } var err error + // cfg is defined in this file globally. cfg, err = testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - err = ospdirectorv1beta1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) + Expect(cfg).NotTo(BeNil()) - // +kubebuilder:scaffold:scheme + //+kubebuilder:scaffold:scheme k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).ToNot(HaveOccurred()) - Expect(k8sClient).ToNot(BeNil()) + Expect(err).NotTo(HaveOccurred()) + Expect(k8sClient).NotTo(BeNil()) - close(done) -}, 60) +}) var _ = AfterSuite(func() { By("tearing down the test environment") err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) + Expect(err).NotTo(HaveOccurred()) }) -*/ diff --git a/go.mod b/go.mod index 529db95f..e0585c6b 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20200626054723-37f83d1996bc github.com/metal3-io/baremetal-operator/apis v0.0.0-20220105105621-0ee9ce37c7bc github.com/nmstate/kubernetes-nmstate v0.33.0 - github.com/onsi/ginkgo v1.16.5 + github.com/onsi/ginkgo/v2 v2.9.1 github.com/onsi/gomega v1.27.4 github.com/openshift/cluster-api v0.0.0-20191129101638-b09907ac6668 github.com/openshift/sriov-network-operator v0.0.0-20201204053545-49045c36efb9 @@ -45,11 +45,14 @@ require ( github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/swag v0.21.1 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect + github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + golang.org/x/tools v0.7.0 // indirect kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect ) @@ -101,7 +104,6 @@ require ( github.com/moby/spdystream v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/openshift/api v0.0.0 // indirect github.com/openshift/client-go v0.0.0 // indirect github.com/openshift/custom-resource-status v1.1.2 // indirect @@ -131,7 +133,6 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 8a9610e2..88be56e2 100644 --- a/go.sum +++ b/go.sum @@ -1099,6 +1099,7 @@ github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vv github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= +github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.2-0.20180831124310-ae19f1b56d53/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -1987,6 +1988,7 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 8e861e4017dd85ac5d951a01d7b076b7099e5d1a Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Fri, 14 Apr 2023 13:38:46 +0200 Subject: [PATCH 5/5] set vars for run local in Makefile (cherry picked from commit dddaa3ce34945daccf8c6d937c8586245712d380) --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3dbb551c..5f9090d8 100644 --- a/Makefile +++ b/Makefile @@ -157,8 +157,14 @@ build: generate fmt vet ## Build manager binary. go build -o bin/manager main.go .PHONY: run +run: export METRICS_PORT?=8080 +run: export HEALTH_PORT?=8081 +run: export OPERATOR_TEMPLATES=./templates +run: export WATCH_NAMESPACE=openstack,openshift-machine-api,openshift-sriov-network-operator +run: export ENABLE_WEBHOOKS=false run: manifests generate fmt vet ## Run a controller from your host. - go run ./main.go -metrics-bind-address ${METRICS_BIND_ADDRESS} + go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" + .PHONY: docker-build docker-build: test ## Build docker image with the manager.