Skip to content

Commit

Permalink
fix: using embedded struct for selector
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed Dec 29, 2022
1 parent f6c1ad6 commit f73a5b1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
11 changes: 6 additions & 5 deletions e2e/pod_priority_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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",
},
Expand Down
10 changes: 6 additions & 4 deletions e2e/pod_runtime_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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",
},
Expand Down
7 changes: 3 additions & 4 deletions pkg/api/allowed_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/webhook/ingress/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/pvc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/utils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit f73a5b1

Please sign in to comment.