Skip to content

Commit

Permalink
Bump capi v1.5.0-beta.1
Browse files Browse the repository at this point in the history
Bump golang version to v1.20
Bump golangci-lint to v1.53.3
  • Loading branch information
Sunnatillo committed Jul 25, 2023
1 parent 4467b6d commit 466b2b2
Show file tree
Hide file tree
Showing 25 changed files with 570 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: '1.19'
go-version: '1.20'
- name: Generate release artifacts and notes
run: |
make release
Expand Down
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
5 changes: 2 additions & 3 deletions controllers/ippool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"
)

const (
Expand Down Expand Up @@ -177,7 +176,7 @@ func (r *IPPoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manage
For(&ipamv1.IPPool{}).
WithOptions(options).
Watches(
&source.Kind{Type: &ipamv1.IPClaim{}},
&ipamv1.IPClaim{},
handler.EnqueueRequestsFromMapFunc(r.IPClaimToIPPool),
).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Expand All @@ -187,7 +186,7 @@ func (r *IPPoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manage
// IPClaimToIPPool will return a reconcile request for a
// Metal3DataTemplate if the event is for a
// IPClaim and that IPClaim references a Metal3DataTemplate.
func (r *IPPoolReconciler) IPClaimToIPPool(obj client.Object) []ctrl.Request {
func (r *IPPoolReconciler) IPClaimToIPPool(ctx context.Context, obj client.Object) []ctrl.Request {
if m3ipc, ok := obj.(*ipamv1.IPClaim); ok {
if m3ipc.Spec.Pool.Name != "" {
namespace := m3ipc.Spec.Pool.Namespace
Expand Down
4 changes: 3 additions & 1 deletion controllers/ippool_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ var _ = Describe("IPPool controller", func() {
Name: "abc",
Namespace: "myns",
DeletionTimestamp: &timestampNow,
Finalizers: []string{"ippool.ipam.metal3.io"},
},
Spec: ipamv1.IPPoolSpec{ClusterName: pointer.String("abc")},
},
Expand All @@ -159,6 +160,7 @@ var _ = Describe("IPPool controller", func() {
Name: "abc",
Namespace: "myns",
DeletionTimestamp: &timestampNow,
Finalizers: []string{"ippool.ipam.metal3.io"},
},
Spec: ipamv1.IPPoolSpec{ClusterName: pointer.String("abc")},
},
Expand Down Expand Up @@ -343,7 +345,7 @@ var _ = Describe("IPPool controller", func() {
func(tc TestCaseM3IPCToM3IPP) {
r := IPPoolReconciler{}
obj := client.Object(tc.IPClaim)
reqs := r.IPClaimToIPPool(obj)
reqs := r.IPClaimToIPPool(context.Background(), obj)

if tc.ExpectRequest {
Expect(len(reqs)).To(Equal(1), "Expected 1 request, found %d", len(reqs))
Expand Down
Loading

0 comments on commit 466b2b2

Please sign in to comment.