Skip to content

Commit

Permalink
Update all dependencies (#317)
Browse files Browse the repository at this point in the history
## Description


This PR update many many dependencies. Some of the bigger ones are:

Go is updated to 1.21
sigs.k8s.io/cluster-api to v1.6.0
sigs.k8s.io/controller-runtime to v0.16.3
tink to v0.9.0
rufio to v0.3.2

## Why is this needed



Fixes: #

## How Has This Been Tested?



`make test` is happy but this will need some manual smoke testing and more.
I have started some smoke testing and found issues. The last few commits address these issues. I have more tests to run. Will update if anything additional is found.
I found one more issue with the namespace watching in the controller manager options. This is fixed. I tested by creating a 4 node cluster (1 cp 3 workers). I did some scale up and down successfully. 


## How are existing users impacted? What migration steps/scripts do we need?





## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
mergify[bot] authored Jan 10, 2024
2 parents 2119da1 + 4cc0cc5 commit c1573ca
Show file tree
Hide file tree
Showing 22 changed files with 406 additions and 860 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
CGO_ENABLED: 0
GO_VERSION: '1.20'
GO_VERSION: '1.21'

jobs:
validate:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GO_VERSION: '1.20'
GO_VERSION: '1.21'

jobs:
manager-image:
Expand Down
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ linters-settings:
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
gosimple:
go: "1.20"
go: "1.21"
staticcheck:
go: "1.20"
go: "1.21"
stylecheck:
go: "1.20"
go: "1.21"
unused:
go: "1.20"
go: "1.21"
tagliatelle:
case:
# use-field-name: true
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.

# Build the manager binary
ARG GOVER=1.20
ARG GOVER=1.21
FROM golang:${GOVER} as builder

WORKDIR /workspace
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ GO_INSTALL = ./scripts/go_install.sh
# Binaries.
CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/[email protected]

GOLANGCI_LINT_VER := v1.53.3
GOLANGCI_LINT_VER := v1.54.2
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)

KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)

KUBECTL_VER := v1.23.0
KUBECTL_VER := v1.28.2
KUBECTL_BIN := kubectl
KUBECTL := $(TOOLS_BIN_DIR)/$(KUBECTL_BIN)-$(KUBECTL_VER)

KIND_VER := v0.12.0
KIND_VER := v0.20.0
KIND_BIN := kind
KIND := $(TOOLS_BIN_DIR)/$(KIND_BIN)-$(KIND_VER)

Expand Down Expand Up @@ -107,7 +107,7 @@ endif
# Build time versioning details.
LDFLAGS := $(shell hack/version.sh)

GOLANG_VERSION := 1.20
GOLANG_VERSION := 1.21

## --------------------------------------
## Help
Expand Down
15 changes: 9 additions & 6 deletions api/v1beta1/tinkerbellcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

const (
osUbuntu = "ubuntu"
defaultUbuntuVersion = "20.04"
)

var _ admission.Validator = &TinkerbellCluster{}

// SetupWebhookWithManager sets up and registers the webhook with the manager.
func (c *TinkerbellCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).For(c).Complete() //nolint:wrapcheck
Expand All @@ -37,18 +40,18 @@ func (c *TinkerbellCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-tinkerbellcluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=tinkerbellclusters,versions=v1beta1,name=default.tinkerbellcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

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

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *TinkerbellCluster) ValidateUpdate(_ runtime.Object) error {
return nil
func (c *TinkerbellCluster) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
return nil, nil
}

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

func defaultVersionForOSDistro(distro string) string {
Expand Down
15 changes: 9 additions & 6 deletions api/v1beta1/tinkerbellmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

var _ admission.Validator = &TinkerbellMachine{}

// SetupWebhookWithManager sets up and registers the webhook with the manager.
func (m *TinkerbellMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).For(m).Complete() //nolint:wrapcheck
Expand All @@ -30,14 +33,14 @@ func (m *TinkerbellMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-tinkerbellmachine,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=tinkerbellmachines,versions=v1beta1,name=validation.tinkerbellmachine.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (m *TinkerbellMachine) ValidateCreate() error {
func (m *TinkerbellMachine) ValidateCreate() (admission.Warnings, error) {
allErrs := m.validateSpec()

return aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
return nil, aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (m *TinkerbellMachine) ValidateUpdate(oldRaw runtime.Object) error {
func (m *TinkerbellMachine) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
allErrs := m.validateSpec()

old, _ := oldRaw.(*TinkerbellMachine)
Expand All @@ -50,12 +53,12 @@ func (m *TinkerbellMachine) ValidateUpdate(oldRaw runtime.Object) error {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "providerID"), "is immutable once set"))
}

return aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
return nil, aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
}

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

func (m *TinkerbellMachine) validateSpec() field.ErrorList {
Expand Down
13 changes: 8 additions & 5 deletions api/v1beta1/tinkerbellmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
func Test_valid_tinkerbell_machine(t *testing.T) {
t.Parallel()
g := NewWithT(t)

existingValidMachine := &v1beta1.TinkerbellMachine{}

for _, machine := range []v1beta1.TinkerbellMachine{
Expand Down Expand Up @@ -82,8 +81,10 @@ func Test_valid_tinkerbell_machine(t *testing.T) {
},
},
} {
g.Expect(machine.ValidateCreate()).ToNot(HaveOccurred())
g.Expect(machine.ValidateUpdate(existingValidMachine)).ToNot(HaveOccurred())
_, err := machine.ValidateCreate()
g.Expect(err).ToNot(HaveOccurred())
_, err = machine.ValidateUpdate(existingValidMachine)
g.Expect(err).ToNot(HaveOccurred())
}
}

Expand Down Expand Up @@ -128,7 +129,9 @@ func Test_invalid_tinkerbell_machine(t *testing.T) {
},
},
} {
g.Expect(machine.ValidateCreate()).To(HaveOccurred())
g.Expect(machine.ValidateUpdate(existingValidMachine)).To(HaveOccurred())
_, err := machine.ValidateCreate()
g.Expect(err).To(HaveOccurred())
_, err = machine.ValidateUpdate(existingValidMachine)
g.Expect(err).To(HaveOccurred())
}
}
17 changes: 10 additions & 7 deletions api/v1beta1/tinkerbellmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

var _ admission.Validator = &TinkerbellMachineTemplate{}

// SetupWebhookWithManager sets up and registers the webhook with the manager.
func (m *TinkerbellMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).For(m).Complete() //nolint:wrapcheck
Expand All @@ -33,7 +36,7 @@ func (m *TinkerbellMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) er
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-tinkerbellmachinetemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=tinkerbellmachinetemplates,versions=v1beta1,name=validation.tinkerbellmachinetemplate.infrastructure.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (m *TinkerbellMachineTemplate) ValidateCreate() error {
func (m *TinkerbellMachineTemplate) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList

spec := m.Spec.Template.Spec
Expand All @@ -47,21 +50,21 @@ func (m *TinkerbellMachineTemplate) ValidateCreate() error {
allErrs = append(allErrs, field.Forbidden(fieldBasePath.Child("hardwareName"), "cannot be set in templates"))
}

return aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
return nil, aggregateObjErrors(m.GroupVersionKind().GroupKind(), m.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (m *TinkerbellMachineTemplate) ValidateUpdate(old runtime.Object) error {
func (m *TinkerbellMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
oldTinkerbellMachineTemplate, _ := old.(*TinkerbellMachineTemplate)

if !reflect.DeepEqual(m.Spec, oldTinkerbellMachineTemplate.Spec) {
return apierrors.NewBadRequest("TinkerbellMachineTemplate.Spec is immutable")
return nil, apierrors.NewBadRequest("TinkerbellMachineTemplate.Spec is immutable")
}

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (m *TinkerbellMachineTemplate) ValidateDelete() error {
return nil
func (m *TinkerbellMachineTemplate) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
6 changes: 4 additions & 2 deletions controllers/machine_reconcile_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (

"github.com/go-logr/logr"
rufiov1 "github.com/tinkerbell/rufio/api/v1alpha1"
tinkv1 "github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
tinkv1 "github.com/tinkerbell/tink/api/v1alpha1"

infrastructurev1 "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
"github.com/tinkerbell/cluster-api-provider-tinkerbell/internal/templates"
Expand Down Expand Up @@ -519,8 +519,10 @@ func (scope *machineReconcileScope) assignedHardware() (*tinkv1.Hardware, error)
//nolint:lll
func byHardwareAffinity(hardware []tinkv1.Hardware, preferred []infrastructurev1.WeightedHardwareAffinityTerm) (func(i int, j int) bool, error) {
scores := map[client.ObjectKey]int32{}
// compute scores for each item based on the preferred term weightss
// compute scores for each item based on the preferred term weights
for _, term := range preferred {
term := term

selector, err := metav1.LabelSelectorAsSelector(&term.HardwareAffinityTerm.LabelSelector)
if err != nil {
return nil, fmt.Errorf("constructing label selector: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion controllers/machine_reconcile_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package controllers //nolint:testpackage

import (
"testing"
Expand Down
5 changes: 2 additions & 3 deletions controllers/tinkerbellcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ 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"

tinkv1 "github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
tinkv1 "github.com/tinkerbell/tink/api/v1alpha1"

infrastructurev1 "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
)
Expand Down Expand Up @@ -316,7 +315,7 @@ func (tcr *TinkerbellClusterReconciler) SetupWithManager(
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log, tcr.WatchFilterValue)).
WithEventFilter(predicates.ResourceIsNotExternallyManaged(log)).
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(mapper),
builder.WithPredicates(predicates.ClusterUnpaused(log)),
)
Expand Down
9 changes: 7 additions & 2 deletions controllers/tinkerbellcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

tinkv1 "github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
tinkv1 "github.com/tinkerbell/tink/api/v1alpha1"

infrastructurev1 "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
"github.com/tinkerbell/cluster-api-provider-tinkerbell/controllers"
Expand Down Expand Up @@ -195,7 +195,12 @@ func kubernetesClientWithObjects(t *testing.T, objects []runtime.Object) client.
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed(), "Adding CAPI objects to scheme should succeed")
g.Expect(corev1.AddToScheme(scheme)).To(Succeed(), "Adding Core V1 objects to scheme should succeed")

return fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(objects...).Build()
objs := []client.Object{
&infrastructurev1.TinkerbellMachine{},
&infrastructurev1.TinkerbellCluster{},
}

return fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(objects...).WithStatusSubresource(objs...).Build()
}

//nolint:unparam
Expand Down
Loading

0 comments on commit c1573ca

Please sign in to comment.