Skip to content

Commit

Permalink
Address TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
ialidzhikov committed Nov 24, 2023
1 parent ebbf0b1 commit d515d78
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pkg/admission/validator/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ 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"
"k8s.io/apimachinery/pkg/util/validation/field"
"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"
)

Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions pkg/apis/registry/v1alpha1/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,10 @@
package helper

import (
"github.com/gardener/gardener/pkg/apis/core"

"github.com/gardener/gardener-extension-registry-cache/pkg/apis/registry/v1alpha1"
)

// GarbageCollectionEnabled returns whether the garbage collection is enabled for the given cache.
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
}
19 changes: 0 additions & 19 deletions pkg/apis/registry/v1alpha1/helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"}}),
)
})
1 change: 0 additions & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d515d78

Please sign in to comment.