Skip to content

Commit

Permalink
Bump capi v1.5.0-beta.1 and golang version to v1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunnatillo committed Jul 14, 2023
1 parent 4467b6d commit 7469130
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 530 deletions.
8 changes: 4 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ linters:

linters-settings:
gosec:
go: "1.19"
go: "1.20"
severity: medium
confidence: medium
excludes:
Expand Down Expand Up @@ -81,9 +81,9 @@ linters-settings:
allow-leading-space: false
require-specific: true
staticcheck:
go: "1.19"
go: "1.20"
stylecheck:
go: "1.19"
go: "1.20"
gocritic:
enabled-tags:
- experimental
Expand All @@ -102,7 +102,7 @@ linters-settings:
- whyNoLint
- wrapperFunc
unused:
go: "1.19"
go: "1.20"
issues:
exclude-rules:
- path: _test\.go
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

# Support FROM override
ARG BUILD_IMAGE=docker.io/golang:1.19.9@sha256:86af5649fa1d9265d3fe7caf633231340b93e4164b96e14bc4e1131a191c1ddd
ARG BUILD_IMAGE=docker.io/golang:1.20.4@sha256:3fccedea46315261e4b6205bcffe91ece1e2aea60c23aab0f033f35461849b42
ARG BASE_IMAGE=gcr.io/distroless/static:nonroot@sha256:9ecc53c269509f63c69a266168e4a687c7eb8c0cfd753bd8bfcaa4f58a90876f

# Build the manager binary on golang image
Expand Down
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/metal3-io/ip-address-manager/api

go 1.19
go 1.20

require (
github.com/onsi/ginkgo/v2 v2.11.0
Expand Down
19 changes: 10 additions & 9 deletions api/v1alpha1/ipaddress_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (c *IPAddress) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -38,7 +39,7 @@ func (c *IPAddress) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *IPAddress) ValidateCreate() error {
func (c *IPAddress) ValidateCreate() (admission.Warnings, error) {
allErrs := field.ErrorList{}
if c.Spec.Pool.Name == "" {
allErrs = append(allErrs,
Expand Down Expand Up @@ -71,17 +72,17 @@ func (c *IPAddress) ValidateCreate() error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("IPAddress").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("IPAddress").GroupKind(), c.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *IPAddress) ValidateUpdate(old runtime.Object) error {
func (c *IPAddress) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
allErrs := field.ErrorList{}
oldIPAddress, ok := old.(*IPAddress)
if !ok || oldIPAddress == nil {
return apierrors.NewInternalError(errors.New("unable to convert existing object"))
return nil, apierrors.NewInternalError(errors.New("unable to convert existing object"))
}

if c.Spec.Address != oldIPAddress.Spec.Address {
Expand Down Expand Up @@ -147,12 +148,12 @@ func (c *IPAddress) ValidateUpdate(old runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("IPAddress").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("IPAddress").GroupKind(), c.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *IPAddress) ValidateDelete() error {
return nil
func (c *IPAddress) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
13 changes: 8 additions & 5 deletions api/v1alpha1/ipaddress_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ func TestIPAddressCreateValidation(t *testing.T) {
},
}

_, createErr := obj.ValidateCreate()
if tt.expectErr {
g.Expect(obj.ValidateCreate()).NotTo(Succeed())
g.Expect(createErr).To(HaveOccurred())
} else {
g.Expect(obj.ValidateCreate()).To(Succeed())
g.Expect(createErr).NotTo(HaveOccurred())
}

g.Expect(obj.ValidateDelete()).To(Succeed())
_, validateError := obj.ValidateDelete()
g.Expect(validateError).NotTo(HaveOccurred())
})
}
}
Expand Down Expand Up @@ -306,10 +308,11 @@ func TestIPAddressUpdateValidation(t *testing.T) {
old = nil
}

_, err := newAdd.ValidateUpdate(old)
if tt.expectErr {
g.Expect(newAdd.ValidateUpdate(old)).NotTo(Succeed())
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(newAdd.ValidateUpdate(old)).To(Succeed())
g.Expect(err).NotTo(HaveOccurred())
}
})
}
Expand Down
19 changes: 10 additions & 9 deletions api/v1alpha1/ipclaim_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (c *IPClaim) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -38,7 +39,7 @@ func (c *IPClaim) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *IPClaim) ValidateCreate() error {
func (c *IPClaim) ValidateCreate() (admission.Warnings, error) {
allErrs := field.ErrorList{}
if c.Spec.Pool.Name == "" {
allErrs = append(allErrs,
Expand All @@ -51,17 +52,17 @@ func (c *IPClaim) ValidateCreate() error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("IPClaim").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("IPClaim").GroupKind(), c.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *IPClaim) ValidateUpdate(old runtime.Object) error {
func (c *IPClaim) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
allErrs := field.ErrorList{}
oldIPClaim, ok := old.(*IPClaim)
if !ok || oldIPClaim == nil {
return apierrors.NewInternalError(errors.New("unable to convert existing object"))
return nil, apierrors.NewInternalError(errors.New("unable to convert existing object"))
}

if c.Spec.Pool.Name != oldIPClaim.Spec.Pool.Name {
Expand Down Expand Up @@ -91,12 +92,12 @@ func (c *IPClaim) ValidateUpdate(old runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("IPClaim").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("IPClaim").GroupKind(), c.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *IPClaim) ValidateDelete() error {
return nil
func (c *IPClaim) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
14 changes: 8 additions & 6 deletions api/v1alpha1/ipclaim_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ func TestIPClaimCreateValidation(t *testing.T) {
},
}

_, createErr := obj.ValidateCreate()
if tt.expectErr {
g.Expect(obj.ValidateCreate()).NotTo(Succeed())
g.Expect(createErr).To(HaveOccurred())
} else {
g.Expect(obj.ValidateCreate()).To(Succeed())
g.Expect(createErr).NotTo(HaveOccurred())
}

g.Expect(obj.ValidateDelete()).To(Succeed())
_, validateError := obj.ValidateDelete()
g.Expect(validateError).NotTo(HaveOccurred())
})
}
}
Expand Down Expand Up @@ -205,11 +207,11 @@ func TestIPClaimUpdateValidation(t *testing.T) {
} else {
old = nil
}

_, err := newClm.ValidateUpdate(old)
if tt.expectErr {
g.Expect(newClm.ValidateUpdate(old)).NotTo(Succeed())
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(newClm.ValidateUpdate(old)).To(Succeed())
g.Expect(err).NotTo(HaveOccurred())
}
})
}
Expand Down
17 changes: 9 additions & 8 deletions api/v1alpha1/ippool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (c *IPPool) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -40,16 +41,16 @@ func (c *IPPool) Default() {
}

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

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *IPPool) ValidateUpdate(old runtime.Object) error {
func (c *IPPool) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
allErrs := field.ErrorList{}
oldM3ipp, ok := old.(*IPPool)
if !ok || oldM3ipp == nil {
return apierrors.NewInternalError(errors.New("unable to convert existing object"))
return nil, apierrors.NewInternalError(errors.New("unable to convert existing object"))
}

if !reflect.DeepEqual(c.Spec.NamePrefix, oldM3ipp.Spec.NamePrefix) {
Expand Down Expand Up @@ -86,9 +87,9 @@ func (c *IPPool) ValidateUpdate(old runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("Metal3Data").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("Metal3Data").GroupKind(), c.Name, allErrs)
}

func (c *IPPool) checkPoolBonds(old *IPPool) ([]IPAddressStr, []IPAddressStr) {
Expand Down Expand Up @@ -134,8 +135,8 @@ func (c *IPPool) isAddressInBonds(address IPAddressStr) bool {
}

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

// No further validation for now.
Expand Down
13 changes: 8 additions & 5 deletions api/v1alpha1/ippool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ func TestIPPoolValidation(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

_, createErr := tt.c.ValidateCreate()
if tt.expectErr {
g.Expect(tt.c.ValidateCreate()).NotTo(Succeed())
g.Expect(createErr).To(HaveOccurred())
} else {
g.Expect(tt.c.ValidateCreate()).To(Succeed())
g.Expect(createErr).NotTo(HaveOccurred())
}

g.Expect(tt.c.ValidateDelete()).To(Succeed())
_, deleteErr := tt.c.ValidateDelete()
g.Expect(deleteErr).NotTo(HaveOccurred())
})
}
}
Expand Down Expand Up @@ -189,10 +191,11 @@ func TestIPPoolUpdateValidation(t *testing.T) {
oldPool = nil
}

_, err := newPool.ValidateUpdate(oldPool)
if tt.expectErr {
g.Expect(newPool.ValidateUpdate(oldPool)).NotTo(Succeed())
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(newPool.ValidateUpdate(oldPool)).To(Succeed())
g.Expect(err).NotTo(HaveOccurred())
}
})
}
Expand Down
Loading

0 comments on commit 7469130

Please sign in to comment.