From f73a5b17f440932dc198419bec7af02f9503e900 Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Thu, 29 Dec 2022 16:34:59 +0100 Subject: [PATCH] fix: using embedded struct for selector --- e2e/pod_priority_class_test.go | 11 ++++++----- e2e/pod_runtime_class_test.go | 10 ++++++---- pkg/api/allowed_list.go | 7 +++---- pkg/api/zz_generated.deepcopy.go | 2 +- pkg/webhook/ingress/errors.go | 2 +- pkg/webhook/pvc/errors.go | 2 +- pkg/webhook/utils/error.go | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/e2e/pod_priority_class_test.go b/e2e/pod_priority_class_test.go index fff8555c..f2251f79 100644 --- a/e2e/pod_priority_class_test.go +++ b/e2e/pod_priority_class_test.go @@ -7,16 +7,17 @@ package e2e import ( "context" + "strconv" + "strings" - capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" - "github.com/clastix/capsule/pkg/api" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" v1 "k8s.io/api/scheduling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strconv" - "strings" + + capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" + "github.com/clastix/capsule/pkg/api" ) var _ = Describe("enforcing a Priority Class", func() { @@ -36,7 +37,7 @@ var _ = Describe("enforcing a Priority Class", func() { Exact: []string{"gold"}, Regex: "pc\\-\\w+", }, - Selector: metav1.LabelSelector{ + LabelSelector: metav1.LabelSelector{ MatchLabels: map[string]string{ "env": "customers", }, diff --git a/e2e/pod_runtime_class_test.go b/e2e/pod_runtime_class_test.go index 14d7bd49..e6739da6 100644 --- a/e2e/pod_runtime_class_test.go +++ b/e2e/pod_runtime_class_test.go @@ -7,14 +7,16 @@ package e2e import ( "context" - "github.com/clastix/capsule/pkg/api" + "strconv" + "strings" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" nodev1 "k8s.io/api/node/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strconv" - "strings" + + "github.com/clastix/capsule/pkg/api" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" ) @@ -36,7 +38,7 @@ var _ = Describe("enforcing a Runtime Class", func() { Exact: []string{"legacy"}, Regex: "^hardened-.*$", }, - Selector: metav1.LabelSelector{ + LabelSelector: metav1.LabelSelector{ MatchLabels: map[string]string{ "env": "customers", }, diff --git a/pkg/api/allowed_list.go b/pkg/api/allowed_list.go index 8d0a9e4f..0784ec6e 100644 --- a/pkg/api/allowed_list.go +++ b/pkg/api/allowed_list.go @@ -16,13 +16,12 @@ import ( // +kubebuilder:object:generate=true type SelectorAllowedListSpec struct { - AllowedListSpec `json:",inline"` - - Selector metav1.LabelSelector `json:",inline"` + AllowedListSpec `json:",inline"` + metav1.LabelSelector `json:",inline"` } func (in *SelectorAllowedListSpec) SelectorMatch(obj client.Object) bool { - selector, err := metav1.LabelSelectorAsSelector(&in.Selector) + selector, err := metav1.LabelSelectorAsSelector(&in.LabelSelector) if err != nil { return false } diff --git a/pkg/api/zz_generated.deepcopy.go b/pkg/api/zz_generated.deepcopy.go index d6545982..9419894f 100644 --- a/pkg/api/zz_generated.deepcopy.go +++ b/pkg/api/zz_generated.deepcopy.go @@ -223,7 +223,7 @@ func (in *ResourceQuotaSpec) DeepCopy() *ResourceQuotaSpec { func (in *SelectorAllowedListSpec) DeepCopyInto(out *SelectorAllowedListSpec) { *out = *in in.AllowedListSpec.DeepCopyInto(&out.AllowedListSpec) - in.Selector.DeepCopyInto(&out.Selector) + in.LabelSelector.DeepCopyInto(&out.LabelSelector) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelectorAllowedListSpec. diff --git a/pkg/webhook/ingress/errors.go b/pkg/webhook/ingress/errors.go index 79f6b5be..c8191c01 100644 --- a/pkg/webhook/ingress/errors.go +++ b/pkg/webhook/ingress/errors.go @@ -77,7 +77,7 @@ func appendClassError(spec api.SelectorAllowedListSpec) (append string) { append += fmt.Sprintf(", or matching the regex %s", spec.Regex) } - if len(spec.Selector.MatchLabels) > 0 || len(spec.Selector.MatchExpressions) > 0 { + if len(spec.MatchLabels) > 0 || len(spec.MatchExpressions) > 0 { append += fmt.Sprintf(", or matching the label selector defined in the Tenant") } diff --git a/pkg/webhook/pvc/errors.go b/pkg/webhook/pvc/errors.go index dc83403e..54660f39 100644 --- a/pkg/webhook/pvc/errors.go +++ b/pkg/webhook/pvc/errors.go @@ -30,7 +30,7 @@ func appendError(spec api.SelectorAllowedListSpec) (append string) { append += fmt.Sprintf(", or matching the regex %s", spec.Regex) } - if len(spec.Selector.MatchLabels) > 0 || len(spec.Selector.MatchExpressions) > 0 { + if len(spec.MatchLabels) > 0 || len(spec.MatchExpressions) > 0 { append += ", or matching the label selector defined in the Tenant" } diff --git a/pkg/webhook/utils/error.go b/pkg/webhook/utils/error.go index c64f21bd..24a34799 100644 --- a/pkg/webhook/utils/error.go +++ b/pkg/webhook/utils/error.go @@ -29,7 +29,7 @@ func AllowedValuesErrorMessage(allowed api.SelectorAllowedListSpec, err string) extra = append(extra, fmt.Sprintf(" use one matching the following regex (%s)", allowed.Regex)) } - if len(allowed.Selector.MatchLabels) > 0 || len(allowed.Selector.MatchExpressions) > 0 { + if len(allowed.MatchLabels) > 0 || len(allowed.MatchExpressions) > 0 { extra = append(extra, ", or matching the label selector defined in the Tenant") }