Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies including controller-runtime. #54

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions api/v2/validation/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

type genericValidation[O client.Object] interface {
Expand All @@ -28,20 +29,20 @@ func (g *genericValidator[O, V]) Instance() V {
return v
}

func (g *genericValidator[O, V]) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (g *genericValidator[O, V]) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
var (
v = g.Instance()
o, ok = obj.(O)
allErrs field.ErrorList
)

if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("validator received unexpected type: %T", obj))
return nil, apierrors.NewBadRequest(fmt.Sprintf("validator received unexpected type: %T", obj))
}

accessor, err := meta.Accessor(obj)
if err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("failed to get accessor for object: %s", err))
return nil, apierrors.NewBadRequest(fmt.Sprintf("failed to get accessor for object: %s", err))
}

g.log.Info("validating resource creation", "name", accessor.GetName(), "namespace", accessor.GetNamespace())
Expand All @@ -50,17 +51,17 @@ func (g *genericValidator[O, V]) ValidateCreate(ctx context.Context, obj runtime
allErrs = append(allErrs, v.ValidateCreate(g.log, o)...)

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(
return nil, apierrors.NewInvalid(
obj.GetObjectKind().GroupVersionKind().GroupKind(),
accessor.GetName(),
allErrs,
)
}

func (g *genericValidator[O, V]) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (g *genericValidator[O, V]) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
var (
v = g.Instance()
oldO, oldOk = oldObj.(O)
Expand All @@ -69,19 +70,19 @@ func (g *genericValidator[O, V]) ValidateUpdate(ctx context.Context, oldObj, new
)

if !oldOk {
return apierrors.NewBadRequest(fmt.Sprintf("validator received unexpected type: %T", oldO))
return nil, apierrors.NewBadRequest(fmt.Sprintf("validator received unexpected type: %T", oldO))
}
if !newOk {
return apierrors.NewBadRequest(fmt.Sprintf("validator received unexpected type: %T", newO))
return nil, apierrors.NewBadRequest(fmt.Sprintf("validator received unexpected type: %T", newO))
}

oldAccessor, err := meta.Accessor(oldO)
if err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("failed to get accessor for object: %s", err))
return nil, apierrors.NewBadRequest(fmt.Sprintf("failed to get accessor for object: %s", err))
}
newAccessor, err := meta.Accessor(newO)
if err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("failed to get accessor for object: %s", err))
return nil, apierrors.NewBadRequest(fmt.Sprintf("failed to get accessor for object: %s", err))
}

g.log.Info("validating resource update", "name", newAccessor.GetName(), "namespace", newAccessor.GetNamespace())
Expand All @@ -90,18 +91,18 @@ func (g *genericValidator[O, V]) ValidateUpdate(ctx context.Context, oldObj, new
allErrs = append(allErrs, v.ValidateUpdate(g.log, oldO, newO)...)

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(
return nil, apierrors.NewInvalid(
newO.GetObjectKind().GroupVersionKind().GroupKind(),
newAccessor.GetName(),
allErrs,
)
}

func (_ *genericValidator[O, V]) ValidateDelete(ctx context.Context, obj runtime.Object) error {
return nil
func (_ *genericValidator[O, V]) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
return nil, nil
}

type (
Expand Down
4 changes: 2 additions & 2 deletions api/v2/validation/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func Test_firewallValidator_ValidateCreate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
v := NewFirewallValidator(testr.New(t))

got := v.ValidateCreate(context.Background(), tt.mutateFn(valid.DeepCopy()))
_, got := v.ValidateCreate(context.Background(), tt.mutateFn(valid.DeepCopy()))
if diff := cmp.Diff(tt.wantErr, got, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func Test_firewallValidator_ValidateUpdate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
v := NewFirewallValidator(testr.New(t))

got := v.ValidateUpdate(context.Background(), tt.oldF, tt.newF)
_, got := v.ValidateUpdate(context.Background(), tt.oldF, tt.newF)
if diff := cmp.Diff(tt.wantErr, got, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
Expand Down
4 changes: 2 additions & 2 deletions api/v2/validation/firewalldeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Test_firewallDeploymentValidator_ValidateCreate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
v := NewFirewallDeploymentValidator(testr.New(t))

got := v.ValidateCreate(context.Background(), tt.mutateFn(valid.DeepCopy()))
_, got := v.ValidateCreate(context.Background(), tt.mutateFn(valid.DeepCopy()))
if diff := cmp.Diff(tt.wantErr, got, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func Test_firewallDeploymentValidator_ValidateUpdate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
v := NewFirewallDeploymentValidator(testr.New(t))

got := v.ValidateUpdate(context.Background(), valid.DeepCopy(), tt.mutateFn(valid.DeepCopy()))
_, got := v.ValidateUpdate(context.Background(), valid.DeepCopy(), tt.mutateFn(valid.DeepCopy()))
if diff := cmp.Diff(tt.wantErr, got, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
Expand Down
4 changes: 2 additions & 2 deletions api/v2/validation/firewallset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Test_firewalSetValidator_ValidateCreate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
v := NewFirewallSetValidator(testr.New(t))

got := v.ValidateCreate(context.Background(), tt.mutateFn(valid.DeepCopy()))
_, got := v.ValidateCreate(context.Background(), tt.mutateFn(valid.DeepCopy()))
if diff := cmp.Diff(tt.wantErr, got, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
Expand Down Expand Up @@ -230,7 +230,7 @@ func Test_firewallSetValidator_ValidateUpdate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
v := NewFirewallSetValidator(testr.New(t))

got := v.ValidateUpdate(context.Background(), valid.DeepCopy(), tt.mutateFn(valid.DeepCopy()))
_, got := v.ValidateUpdate(context.Background(), valid.DeepCopy(), tt.mutateFn(valid.DeepCopy()))
if diff := cmp.Diff(tt.wantErr, got, testcommon.ErrorStringComparer()); diff != "" {
t.Errorf("error diff (+got -want):\n %s", diff)
}
Expand Down
18 changes: 12 additions & 6 deletions controllers/set/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -78,12 +80,16 @@ var _ = BeforeSuite(func() {
Expect(k8sClient).NotTo(BeNil())

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
MetricsBindAddress: "0",
LeaderElection: false,
CertDir: testEnv.WebhookInstallOptions.LocalServingCertDir,
Host: testEnv.WebhookInstallOptions.LocalServingHost,
Port: testEnv.WebhookInstallOptions.LocalServingPort,
Scheme: scheme.Scheme,
WebhookServer: webhook.NewServer(webhook.Options{
CertDir: testEnv.WebhookInstallOptions.LocalServingCertDir,
Host: testEnv.WebhookInstallOptions.LocalServingHost,
Port: testEnv.WebhookInstallOptions.LocalServingPort,
}),
Metrics: server.Options{
BindAddress: "0",
},
LeaderElection: false,
})
Expect(err).ToNot(HaveOccurred())

Expand Down
58 changes: 26 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@ require (
github.com/go-openapi/strfmt v0.23.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/metal-stack/metal-go v0.28.1
github.com/metal-stack/metal-lib v0.15.1
github.com/metal-stack/metal-go v0.28.4
github.com/metal-stack/metal-lib v0.16.2
github.com/metal-stack/v v1.0.3
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/stretchr/testify v1.9.0
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
sigs.k8s.io/controller-runtime v0.14.5
)

replace (
k8s.io/api => k8s.io/api v0.26.3
k8s.io/client-go => k8s.io/client-go v0.26.3
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
k8s.io/api v0.29.3
k8s.io/apimachinery v0.29.3
k8s.io/client-go v0.29.3
sigs.k8s.io/controller-runtime v0.16.5
)

require (
Expand All @@ -33,37 +27,37 @@ require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/flatcar/ignition v0.36.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.22.0 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/loads v0.21.5 // indirect
github.com/go-openapi/runtime v0.27.1 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-openapi/validate v0.22.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/gorilla/mux v1.8.1 // indirect
Expand All @@ -74,17 +68,17 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.4 // indirect
github.com/lestrrat-go/httprc v1.0.5 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.19 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.21 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/metal-stack/security v0.7.2 // indirect
github.com/metal-stack/security v0.8.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down Expand Up @@ -113,13 +107,13 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
Expand Down
Loading