From d515d784ed7e0b585e0af4c97d690f0c481ed884 Mon Sep 17 00:00:00 2001 From: ialidzhikov Date: Fri, 24 Nov 2023 14:37:14 +0200 Subject: [PATCH] Address TODO --- pkg/admission/validator/shoot.go | 4 ++-- pkg/apis/registry/v1alpha1/helper/helper.go | 13 ------------- .../registry/v1alpha1/helper/helper_test.go | 19 ------------------- skaffold.yaml | 1 - vendor/modules.txt | 1 + 5 files changed, 3 insertions(+), 35 deletions(-) diff --git a/pkg/admission/validator/shoot.go b/pkg/admission/validator/shoot.go index 53bfa7fe..3d296b56 100644 --- a/pkg/admission/validator/shoot.go +++ b/pkg/admission/validator/shoot.go @@ -20,6 +20,7 @@ import ( extensionswebhook "github.com/gardener/gardener/extensions/pkg/webhook" "github.com/gardener/gardener/pkg/apis/core" + gardencorehelper "github.com/gardener/gardener/pkg/apis/core/helper" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -27,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" api "github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry" - "github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry/v1alpha1/helper" "github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry/validation" ) @@ -117,7 +117,7 @@ func (s *shoot) validateRegistryCredentials(ctx context.Context, config *api.Reg if cache.SecretReferenceName != nil { secretRefFldPath := cacheFldPath.Child("secretReferenceName") - ref := helper.GetResourceByName(resources, *cache.SecretReferenceName) + ref := gardencorehelper.GetResourceByName(resources, *cache.SecretReferenceName) if ref == nil || ref.ResourceRef.Kind != "Secret" { allErrs = append(allErrs, field.Invalid(secretRefFldPath, *cache.SecretReferenceName, fmt.Sprintf("failed to find referenced resource with name %s and kind Secret", *cache.SecretReferenceName))) continue diff --git a/pkg/apis/registry/v1alpha1/helper/helper.go b/pkg/apis/registry/v1alpha1/helper/helper.go index ba079083..166366ed 100644 --- a/pkg/apis/registry/v1alpha1/helper/helper.go +++ b/pkg/apis/registry/v1alpha1/helper/helper.go @@ -15,8 +15,6 @@ package helper import ( - "github.com/gardener/gardener/pkg/apis/core" - "github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry/v1alpha1" ) @@ -24,14 +22,3 @@ import ( func GarbageCollectionEnabled(cache *v1alpha1.RegistryCache) bool { return cache.GarbageCollection == nil || cache.GarbageCollection.Enabled } - -// GetResourceByName returns the first NamedResourceReference with the given name in the given slice, or nil if not found. -// TODO(dimitar-kostadinov): Drop this func instead of the same helper func in gardener/gardener that was introduced with https://github.com/gardener/gardener/pull/8801. -func GetResourceByName(resources []core.NamedResourceReference, name string) *core.NamedResourceReference { - for _, resource := range resources { - if resource.Name == name { - return &resource - } - } - return nil -} diff --git a/pkg/apis/registry/v1alpha1/helper/helper_test.go b/pkg/apis/registry/v1alpha1/helper/helper_test.go index 07b8f81a..3a9a2615 100644 --- a/pkg/apis/registry/v1alpha1/helper/helper_test.go +++ b/pkg/apis/registry/v1alpha1/helper/helper_test.go @@ -17,10 +17,8 @@ package helper_test import ( "testing" - "github.com/gardener/gardener/pkg/apis/core" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - autoscalingv1 "k8s.io/api/autoscaling/v1" "github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry/v1alpha1" "github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry/v1alpha1/helper" @@ -41,21 +39,4 @@ var _ = Describe("Helpers", func() { Entry("garbageCollection.enabled is false", &v1alpha1.RegistryCache{GarbageCollection: &v1alpha1.GarbageCollection{Enabled: false}}, false), Entry("garbageCollection.enabled is true", &v1alpha1.RegistryCache{GarbageCollection: &v1alpha1.GarbageCollection{Enabled: true}}, true), ) - - DescribeTable("#GetResourceByName", - func(resourceRefs []core.NamedResourceReference, secretReferenceName string, expected *core.NamedResourceReference) { - Expect(helper.GetResourceByName(resourceRefs, secretReferenceName)).To(Equal(expected)) - }, - Entry("resourceRefs is nil", nil, "foo", nil), - Entry("resourceRefs is empty", []core.NamedResourceReference{}, "foo", nil), - Entry("resourceRefs doesn't contains secret ref name", []core.NamedResourceReference{{Name: "bar"}, {Name: "baz"}}, "foo", nil), - Entry("resourceRefs contains secret ref name", - []core.NamedResourceReference{ - {Name: "foo"}, - {Name: "bar", ResourceRef: autoscalingv1.CrossVersionObjectReference{Name: "ref", Kind: "Secret"}}, - {Name: "baz"}, - }, - "bar", - &core.NamedResourceReference{Name: "bar", ResourceRef: autoscalingv1.CrossVersionObjectReference{Name: "ref", Kind: "Secret"}}), - ) }) diff --git a/skaffold.yaml b/skaffold.yaml index 5cde4d48..7c594344 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -58,7 +58,6 @@ build: - pkg/apis/registry/helper - pkg/apis/registry/install - pkg/apis/registry/v1alpha1 - - pkg/apis/registry/v1alpha1/helper - pkg/apis/registry/validation - pkg/constants - vendor diff --git a/vendor/modules.txt b/vendor/modules.txt index 81d5b57f..41762506 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -99,6 +99,7 @@ github.com/gardener/gardener/pkg/api/extensions github.com/gardener/gardener/pkg/apis/authentication github.com/gardener/gardener/pkg/apis/authentication/v1alpha1 github.com/gardener/gardener/pkg/apis/core +github.com/gardener/gardener/pkg/apis/core/helper github.com/gardener/gardener/pkg/apis/core/install github.com/gardener/gardener/pkg/apis/core/v1beta1 github.com/gardener/gardener/pkg/apis/core/v1beta1/constants