fix: using embedded struct for selector

This commit is contained in:
Dario Tranchitella
2022-12-29 17:49:45 +01:00
parent f6c1ad68da
commit f73a5b17f4
7 changed files with 19 additions and 17 deletions
+6 -5
View File
@@ -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",
},
+6 -4
View File
@@ -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",
},
+3 -4
View File
@@ -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
}
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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")
}
+1 -1
View File
@@ -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"
}
+1 -1
View File
@@ -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")
}