Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Bump k8s.io/api & friends to 0.27 #1462

Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/redhat-developer/go-toolset:builder-golang-1.18 as builder
FROM quay.io/redhat-developer/go-toolset:builder-golang-1.20 as builder

WORKDIR /workspace
COPY / /workspace/
Expand Down
17 changes: 9 additions & 8 deletions apis/binding/v1alpha1/servicebinding_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -46,25 +47,25 @@
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateCreate() error {
return checkNameAndSelector(r)
func (r *ServiceBinding) ValidateCreate() (admission.Warnings, error) {
return nil, checkNameAndSelector(r)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateUpdate(old runtime.Object) error {
func (r *ServiceBinding) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
oldSb, ok := old.(*ServiceBinding)
if !ok {
return errors.New("Old object is not service binding")
return nil, errors.New("Old object is not service binding")

Check warning on line 58 in apis/binding/v1alpha1/servicebinding_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/binding/v1alpha1/servicebinding_webhook.go#L58

Added line #L58 was not covered by tests
}
err := apis.CanUpdateBinding(r, oldSb)
if err != nil {
log.Error(err, "Update failed")
return err
return nil, err
}
return checkNameAndSelector(r)
return nil, checkNameAndSelector(r)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateDelete() error {
return nil
func (r *ServiceBinding) ValidateDelete() (admission.Warnings, error) {
return nil, nil

Check warning on line 70 in apis/binding/v1alpha1/servicebinding_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/binding/v1alpha1/servicebinding_webhook.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}
15 changes: 10 additions & 5 deletions apis/binding/v1alpha1/servicebinding_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var _ = Describe("Validation Webhook", func() {
Conditions: []v1.Condition{*apis.Conditions().NotBindingReady().Build()},
},
}
Expect(sb.ValidateUpdate(sb)).ShouldNot(HaveOccurred())
_, err := sb.ValidateUpdate(sb)
Expect(err).ToNot(HaveOccurred())
})

It("should not allow spec updates on ready bindings", func() {
Expand All @@ -29,7 +30,8 @@ var _ = Describe("Validation Webhook", func() {
}
sb := old.DeepCopy()
sb.Spec.BindAsFiles = true
Expect(sb.ValidateUpdate(old)).Should(HaveOccurred())
_, err := sb.ValidateUpdate(old)
Expect(err).To(HaveOccurred())
})

It("should allow metadata updates on ready bindings", func() {
Expand All @@ -43,7 +45,8 @@ var _ = Describe("Validation Webhook", func() {
sb.Annotations = map[string]string{
"foo": "bar",
}
Expect(sb.ValidateUpdate(old)).ShouldNot(HaveOccurred())
_, err := sb.ValidateUpdate(old)
Expect(err).ToNot(HaveOccurred())
})

It("should return error if both application name and selecter is specified during creation", func() {
Expand Down Expand Up @@ -71,7 +74,8 @@ var _ = Describe("Validation Webhook", func() {
Application: ref,
},
}
Expect(sb.ValidateCreate()).Should(HaveOccurred())
_, err := sb.ValidateCreate()
Expect(err).To(HaveOccurred())

})

Expand Down Expand Up @@ -100,7 +104,8 @@ var _ = Describe("Validation Webhook", func() {
Application: ref,
},
}
Expect(sb.ValidateUpdate(sb)).Should(HaveOccurred())
_, err := sb.ValidateUpdate(sb)
Expect(err).To(HaveOccurred())

})

Expand Down
13 changes: 7 additions & 6 deletions apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/util/jsonpath"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -35,19 +36,19 @@
var _ webhook.Validator = &ClusterWorkloadResourceMapping{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (m *ClusterWorkloadResourceMapping) ValidateCreate() error {
return m.validate()
func (m *ClusterWorkloadResourceMapping) ValidateCreate() (admission.Warnings, error) {
return nil, m.validate()

Check warning on line 40 in apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (m *ClusterWorkloadResourceMapping) ValidateUpdate(old runtime.Object) error {
return m.validate()
func (m *ClusterWorkloadResourceMapping) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
return nil, m.validate()

Check warning on line 45 in apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go#L44-L45

Added lines #L44 - L45 were not covered by tests
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (m *ClusterWorkloadResourceMapping) ValidateDelete() error {
func (m *ClusterWorkloadResourceMapping) ValidateDelete() (admission.Warnings, error) {

Check warning on line 49 in apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go#L49

Added line #L49 was not covered by tests
// don't currently need validation of resource removal
return nil
return nil, nil

Check warning on line 51 in apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/clusterworkloadresourcemapping_webhook.go#L51

Added line #L51 was not covered by tests
}

func (m *ClusterWorkloadResourceMapping) validate() error {
Expand Down
17 changes: 9 additions & 8 deletions apis/spec/v1beta1/servicebinding_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -52,28 +53,28 @@
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateCreate() error {
return checkNameAndSelector(r)
func (r *ServiceBinding) ValidateCreate() (admission.Warnings, error) {
return nil, checkNameAndSelector(r)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (sb *ServiceBinding) ValidateUpdate(old runtime.Object) error {
func (sb *ServiceBinding) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
oldSb, ok := old.(*ServiceBinding)
if !ok {
return errors.New("Old object is not service binding")
return nil, errors.New("Old object is not service binding")

Check warning on line 64 in apis/spec/v1beta1/servicebinding_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/servicebinding_webhook.go#L64

Added line #L64 was not covered by tests
}
err := apis.CanUpdateBinding(sb, oldSb)
if err != nil {
log.Error(err, "Update failed")
return err
return nil, err
}
return checkNameAndSelector(sb)
return nil, checkNameAndSelector(sb)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateDelete() error {
func (r *ServiceBinding) ValidateDelete() (admission.Warnings, error) {

Check warning on line 75 in apis/spec/v1beta1/servicebinding_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/servicebinding_webhook.go#L75

Added line #L75 was not covered by tests
log.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil

Check warning on line 79 in apis/spec/v1beta1/servicebinding_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/spec/v1beta1/servicebinding_webhook.go#L79

Added line #L79 was not covered by tests
}
15 changes: 10 additions & 5 deletions apis/spec/v1beta1/servicebinding_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var _ = Describe("Validation Webhook", func() {
Conditions: []v1.Condition{*apis.Conditions().NotBindingReady().Build()},
},
}
Expect(sb.ValidateUpdate(sb)).ShouldNot(HaveOccurred())
_, err := sb.ValidateUpdate(sb)
Expect(err).ToNot(HaveOccurred())
})

It("should not allow spec updates on ready bindings", func() {
Expand All @@ -29,7 +30,8 @@ var _ = Describe("Validation Webhook", func() {
}
sb := old.DeepCopy()
sb.Spec.Name = "foo"
Expect(sb.ValidateUpdate(old)).Should(HaveOccurred())
_, err := sb.ValidateUpdate(old)
Expect(err).To(HaveOccurred())
})

It("should allow metadata updates on ready bindings", func() {
Expand All @@ -43,7 +45,8 @@ var _ = Describe("Validation Webhook", func() {
sb.Annotations = map[string]string{
"foo": "bar",
}
Expect(sb.ValidateUpdate(old)).ShouldNot(HaveOccurred())
_, err := sb.ValidateUpdate(old)
Expect(err).ToNot(HaveOccurred())
})

It("should return error if both application name and selecter is specified during creation", func() {
Expand All @@ -68,7 +71,8 @@ var _ = Describe("Validation Webhook", func() {
Workload: ref,
},
}
Expect(sb.ValidateCreate()).Should(HaveOccurred())
_, err := sb.ValidateCreate()
Expect(err).To(HaveOccurred())

})

Expand All @@ -94,7 +98,8 @@ var _ = Describe("Validation Webhook", func() {
Workload: ref,
},
}
Expect(sb.ValidateUpdate(sb)).Should(HaveOccurred())
_, err := sb.ValidateUpdate(sb)
Expect(err).To(HaveOccurred())

})

Expand Down
5 changes: 4 additions & 1 deletion apis/webhooks/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

func SetupWithManager(mgr ctrl.Manager, serviceAccountName string) {
mgr.GetWebhookServer().Register("/mutate-servicebinding", &webhook.Admission{
Handler: &admissionHandler{serviceAccountName: serviceAccountName},
Handler: &admissionHandler{
serviceAccountName: serviceAccountName,
decoder: admission.NewDecoder(mgr.GetScheme()),
},

Check warning on line 20 in apis/webhooks/admission.go

View check run for this annotation

Codecov / codecov/patch

apis/webhooks/admission.go#L17-L20

Added lines #L17 - L20 were not covered by tests
})
}

Expand Down
21 changes: 11 additions & 10 deletions apis/webhooks/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

type MappingValidator struct {
Expand Down Expand Up @@ -49,32 +50,32 @@

var _ webhook.CustomValidator = &MappingValidator{}

func (validator *MappingValidator) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (validator *MappingValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
mapping := obj.(*v1beta1.ClusterWorkloadResourceMapping)
err := mapping.ValidateCreate()
_, err := mapping.ValidateCreate()
if err != nil {
log.Error(err, "Error validating mapping (create)", "mapping", mapping.Name)
}
return err
return nil, err
}

func (validator *MappingValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (validator *MappingValidator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
mapping := newObj.(*v1beta1.ClusterWorkloadResourceMapping)
if err := mapping.ValidateCreate(); err != nil {
if _, err := mapping.ValidateCreate(); err != nil {
log.Error(err, "Error validating mapping (update)", "mapping", mapping.Name)
return err
return nil, err
}
oldMapping := oldObj.(*v1beta1.ClusterWorkloadResourceMapping)
err := Serialize(ctx, oldMapping, validator.client, validator.lookup)
if err != nil {
return err
return nil, err

Check warning on line 71 in apis/webhooks/validator.go

View check run for this annotation

Codecov / codecov/patch

apis/webhooks/validator.go#L71

Added line #L71 was not covered by tests
}

return nil
return nil, nil
}

func (validator *MappingValidator) ValidateDelete(ctx context.Context, obj runtime.Object) error {
return nil
func (validator *MappingValidator) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
return nil, nil
}

func Serialize(ctx context.Context, mapping *v1beta1.ClusterWorkloadResourceMapping, client dynamic.Interface, lookup kubernetes.K8STypeLookup) error {
Expand Down
18 changes: 12 additions & 6 deletions apis/webhooks/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,35 @@ var _ = Describe("Validate", func() {

var _ = Describe("Create", func() {
It("should accept a valid mapping", func() {
err := validator.ValidateCreate(ctx, &mapping)
msg, err := validator.ValidateCreate(ctx, &mapping)
Expect(err).NotTo(HaveOccurred())
Expect(msg).To(BeEmpty())
})

It("should reject an invalid mapping", func() {
mapping.Spec.Versions[0].Volumes = "foo.bar"
err := validator.ValidateCreate(ctx, &mapping)
msg, err := validator.ValidateCreate(ctx, &mapping)
Expect(err).To(HaveOccurred())
Expect(msg).To(BeEmpty())
})
})

var _ = Describe("Update", func() {
It("should reject an invalid mapping", func() {
oldMapping := mapping.DeepCopy()
mapping.Spec.Versions[0].Volumes = "foo.bar"
err := validator.ValidateUpdate(ctx, oldMapping, &mapping)
msg, err := validator.ValidateUpdate(ctx, oldMapping, &mapping)
Expect(err).To(HaveOccurred())
Expect(msg).To(BeEmpty())
})

It("should accept a valid mapping", func() {
oldMapping := mapping.DeepCopy()
mapping.Spec.Versions[0].Volumes = ".spec.volumes"
validator.client = fake.NewSimpleDynamicClient(scheme)
err := validator.ValidateUpdate(ctx, oldMapping, &mapping)
msg, err := validator.ValidateUpdate(ctx, oldMapping, &mapping)
Expect(err).NotTo(HaveOccurred())
Expect(msg).To(BeEmpty())
})

It("should serialize old mappings into relevant service bindings", func() {
Expand Down Expand Up @@ -112,8 +116,9 @@ var _ = Describe("Validate", func() {
fooGVR := schema.GroupVersionResource{Group: "bar", Version: "v1", Resource: "foos"}
lookup.EXPECT().ResourceForKind(fooGVK).Return(&fooGVR, nil).Times(2)

err := validator.ValidateUpdate(ctx, oldMapping, &mapping)
msg, err := validator.ValidateUpdate(ctx, oldMapping, &mapping)
Expect(err).NotTo(HaveOccurred())
Expect(msg).To(BeEmpty())

oldData, err := json.Marshal(oldMapping)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -132,8 +137,9 @@ var _ = Describe("Validate", func() {

var _ = Describe("Delete", func() {
It("should not need to validate deletes", func() {
err := validator.ValidateDelete(ctx, &mapping)
msg, err := validator.ValidateDelete(ctx, &mapping)
Expect(err).NotTo(HaveOccurred())
Expect(msg).To(BeEmpty())
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,14 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
\n \ttype FooStatus struct{ \t // Represents the observations
of a foo's current state. \t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\" \t //
+patchMergeKey=type \t // +patchStrategy=merge \t // +listType=map
\t // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other fields
\t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down
Loading
Loading