From e6d708ef7e5e2f13c936102a9a921f19af7ed9f7 Mon Sep 17 00:00:00 2001 From: Dmitry Volodin Date: Wed, 12 Feb 2025 17:00:19 +0300 Subject: [PATCH] :seedling: Add alias to GenericProviderReconciler type --- .golangci.yaml | 4 ++-- Makefile | 2 +- api/v1alpha2/conditions_consts.go | 4 ++-- api/v1alpha2/provider_types.go | 7 +++++-- cmd/plugin/cmd/init_test.go | 4 ++-- controller/alias.go | 21 +++++++++++++++++++++ internal/controller/manifests_downloader.go | 11 ++++------- internal/controller/phases.go | 4 ++-- internal/controller/phases_test.go | 8 ++++---- test/e2e/air_gapped_test.go | 4 ++-- test/e2e/compressed_manifests_test.go | 6 +++--- test/e2e/minimal_configuration_test.go | 20 ++++++++++---------- 12 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 controller/alias.go diff --git a/.golangci.yaml b/.golangci.yaml index f56b3f82b..58371ac09 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,8 +1,6 @@ run: timeout: 5m go: "1.23" - skip-files: - - "zz_generated.*\\.go$" allow-parallel-runners: true linters: @@ -145,6 +143,8 @@ issues: # supported will be caught by the default case in the switches. - "missing cases in switch of type v1.PlatformType: (\\.*)" exclude-use-default: false + exclude-files: + - "zz_generated.*\\.go$" exclude-rules: - linters: - staticcheck diff --git a/Makefile b/Makefile index d2f5bffef..bf27be9b1 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ GOTESTSUM_VER := v1.11.0 GOTESTSUM_BIN := gotestsum GOTESTSUM := $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER) -GINKGO_VER := v2.20.1 +GINKGO_VER := v2.22.2 GINKGO_BIN := ginkgo GINKGO := $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER) diff --git a/api/v1alpha2/conditions_consts.go b/api/v1alpha2/conditions_consts.go index 4fa32235c..4a4c40c04 100644 --- a/api/v1alpha2/conditions_consts.go +++ b/api/v1alpha2/conditions_consts.go @@ -29,13 +29,13 @@ const ( // IncorrectVersionFormatReason documents that the provider version is in the incorrect format. IncorrectVersionFormatReason = "IncorrectVersionFormat" - // IncorrectCoreProviderNameReason documents that the provider name is incorrect. + // IncorrectCoreProviderNameReason documents that the Core provider name is incorrect. IncorrectCoreProviderNameReason = "IncorrectCoreProviderNameReason" // EmptyVersionReason documents that the provider version is in the incorrect format. EmptyVersionReason = "EmptyVersionReason" - // FetchConfigValidationError documents that the FetchConfig is configured incorrectly. + // FetchConfigValidationErrorReason documents that the FetchConfig is configured incorrectly. FetchConfigValidationErrorReason = "FetchConfigValidationError" // UnknownProviderReason documents that the provider name is not the name of a known provider. diff --git a/api/v1alpha2/provider_types.go b/api/v1alpha2/provider_types.go index 119cd8cc1..b4c4c2997 100644 --- a/api/v1alpha2/provider_types.go +++ b/api/v1alpha2/provider_types.go @@ -23,8 +23,11 @@ import ( ) const ( - ProviderFinalizer = "provider.cluster.x-k8s.io" - ConfigMapVersionLabelName = "provider.cluster.x-k8s.io/version" + ProviderFinalizer = "provider.cluster.x-k8s.io" + + ConfigMapVersionLabel = "provider.cluster.x-k8s.io/version" + ConfigMapTypeLabel = "provider.cluster.x-k8s.io/type" + ConfigMapNameLabel = "provider.cluster.x-k8s.io/name" CompressedAnnotation = "provider.cluster.x-k8s.io/compressed" diff --git a/cmd/plugin/cmd/init_test.go b/cmd/plugin/cmd/init_test.go index d584e12f8..01c791003 100644 --- a/cmd/plugin/cmd/init_test.go +++ b/cmd/plugin/cmd/init_test.go @@ -35,7 +35,7 @@ import ( "sigs.k8s.io/cluster-api-operator/util" ) -func TestCheckCAPIOpearatorAvailability(t *testing.T) { +func TestCheckCAPIOperatorAvailability(t *testing.T) { tests := []struct { name string want bool @@ -425,7 +425,7 @@ func getGenericProvider(ctx context.Context, client ctrlclient.Client, providerK } return provider, nil - case "RuntimExtensionProvider": + case "RuntimeExtensionProvider": provider := &operatorv1.RuntimeExtensionProvider{} if err := client.Get(ctx, types.NamespacedName{Name: providerName, Namespace: providerNamespace}, provider); err != nil { return nil, err diff --git a/controller/alias.go b/controller/alias.go new file mode 100644 index 000000000..89a0f0bab --- /dev/null +++ b/controller/alias.go @@ -0,0 +1,21 @@ +/* +Copyright 2025 The Kubernetes Authors. + +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 controller + +import providercontroller "sigs.k8s.io/cluster-api-operator/internal/controller" + +type GenericProviderReconciler = providercontroller.GenericProviderReconciler diff --git a/internal/controller/manifests_downloader.go b/internal/controller/manifests_downloader.go index f5c37482a..f8bdb2abd 100644 --- a/internal/controller/manifests_downloader.go +++ b/internal/controller/manifests_downloader.go @@ -38,9 +38,6 @@ import ( ) const ( - configMapVersionLabel = "provider.cluster.x-k8s.io/version" - configMapTypeLabel = "provider.cluster.x-k8s.io/type" - configMapNameLabel = "provider.cluster.x-k8s.io/name" configMapSourceLabel = "provider.cluster.x-k8s.io/source" configMapSourceAnnotation = "provider.cluster.x-k8s.io/source" operatorManagedLabel = "managed-by.operator.cluster.x-k8s.io" @@ -292,10 +289,10 @@ func providerLabelSelector(provider operatorv1.GenericProvider) *metav1.LabelSel // ProviderLabels returns default set of labels that identify a config map with downloaded manifests. func ProviderLabels(provider operatorv1.GenericProvider) map[string]string { labels := map[string]string{ - configMapVersionLabel: provider.GetSpec().Version, - configMapTypeLabel: provider.GetType(), - configMapNameLabel: provider.GetName(), - operatorManagedLabel: "true", + operatorv1.ConfigMapVersionLabel: provider.GetSpec().Version, + operatorv1.ConfigMapTypeLabel: provider.GetType(), + operatorv1.ConfigMapNameLabel: provider.GetName(), + operatorManagedLabel: "true", } if provider.GetSpec().FetchConfig != nil && provider.GetSpec().FetchConfig.OCI != "" { diff --git a/internal/controller/phases.go b/internal/controller/phases.go index ae5c4b7f8..79b5d901f 100644 --- a/internal/controller/phases.go +++ b/internal/controller/phases.go @@ -311,10 +311,10 @@ func (p *phaseReconciler) configmapRepository(ctx context.Context, labelSelector errMsg := "from the Name" if cm.Labels != nil { - ver, ok := cm.Labels[operatorv1.ConfigMapVersionLabelName] + ver, ok := cm.Labels[operatorv1.ConfigMapVersionLabel] if ok { version = ver - errMsg = "from the Label " + operatorv1.ConfigMapVersionLabelName + errMsg = "from the Label " + operatorv1.ConfigMapVersionLabel } } diff --git a/internal/controller/phases_test.go b/internal/controller/phases_test.go index f605cb8bc..b9ab7c360 100644 --- a/internal/controller/phases_test.go +++ b/internal/controller/phases_test.go @@ -529,10 +529,10 @@ releaseSeries: Name: testCurrentVersion, Namespace: "default", Labels: map[string]string{ - configMapVersionLabel: testCurrentVersion, - configMapTypeLabel: core.GetType(), - configMapNameLabel: core.GetName(), - operatorManagedLabel: "true", + operatorv1.ConfigMapVersionLabel: testCurrentVersion, + operatorv1.ConfigMapTypeLabel: core.GetType(), + operatorv1.ConfigMapNameLabel: core.GetName(), + operatorManagedLabel: "true", }, }, Data: map[string]string{"metadata": metadata, "components": ""}, diff --git a/test/e2e/air_gapped_test.go b/test/e2e/air_gapped_test.go index b98a0def9..f82ed1347 100644 --- a/test/e2e/air_gapped_test.go +++ b/test/e2e/air_gapped_test.go @@ -102,7 +102,7 @@ var _ = Describe("Install Core Provider in an air-gapped environment", func() { HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition), ), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version)) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -129,7 +129,7 @@ var _ = Describe("Install Core Provider in an air-gapped environment", func() { HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition), ), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version)) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) diff --git a/test/e2e/compressed_manifests_test.go b/test/e2e/compressed_manifests_test.go index 30bcfc28d..adffa1e26 100644 --- a/test/e2e/compressed_manifests_test.go +++ b/test/e2e/compressed_manifests_test.go @@ -67,7 +67,7 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition), ), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version)) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -94,7 +94,7 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the HaveStatusCondition(&infraProvider.Status.Conditions, operatorv1.ProviderInstalledCondition), ), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(infraProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(infraProvider.Status.InstalledVersion, ptr.To(infraProvider.Spec.Version)) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -168,7 +168,7 @@ var _ = Describe("Create and delete a provider with manifests that don't fit the HaveStatusCondition(&infraProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(infraProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(infraProvider.Status.InstalledVersion, ptr.To(infraProvider.Spec.Version)) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) diff --git a/test/e2e/minimal_configuration_test.go b/test/e2e/minimal_configuration_test.go index 4c3551fc5..1afb3c115 100644 --- a/test/e2e/minimal_configuration_test.go +++ b/test/e2e/minimal_configuration_test.go @@ -112,7 +112,7 @@ metadata: HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(coreProvider.Status.InstalledVersion, &coreProvider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -154,7 +154,7 @@ metadata: HaveStatusCondition(&bootstrapProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(bootstrapProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(bootstrapProvider.Status.InstalledVersion, &bootstrapProvider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -189,7 +189,7 @@ metadata: HaveStatusCondition(&cpProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(cpProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(cpProvider.Status.InstalledVersion, &cpProvider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -224,7 +224,7 @@ metadata: HaveStatusCondition(&infraProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(infraProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(infraProvider.Status.InstalledVersion, &infraProvider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -266,7 +266,7 @@ metadata: HaveStatusCondition(&addonProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(addonProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(addonProvider.Status.InstalledVersion, &addonProvider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -310,7 +310,7 @@ metadata: HaveStatusCondition(&ipamProvider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(ipamProvider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(ipamProvider.Status.InstalledVersion, &ipamProvider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -426,7 +426,7 @@ metadata: HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(provider.Status.InstalledVersion, &provider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -513,7 +513,7 @@ metadata: HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(provider.Status.InstalledVersion, &provider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -600,7 +600,7 @@ metadata: HaveStatusCondition(&provider.Status.Conditions, operatorv1.ProviderInstalledCondition)), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(provider.Status.InstalledVersion, &provider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...) @@ -609,7 +609,7 @@ metadata: provider.Spec.Version = "v0.0.2" Expect(bootstrapCluster.Update(ctx, provider)).To(Succeed()) - By("Waiting for status.IntalledVersion to be set") + By("Waiting for status.InstalledVersion to be set") WaitFor(ctx, For(provider).In(bootstrapCluster).ToSatisfy(func() bool { return ptr.Equal(provider.Status.InstalledVersion, &provider.Spec.Version) }), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)