Skip to content

Commit

Permalink
bumping capi to v1.6 and controller-runtime to v0.17 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
pokearu authored Jan 26, 2024
1 parent a9b1cb2 commit 1b741aa
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 702 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha3/condition_consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package v1alpha3

import clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
import clusterv1 "github.com/aws/etcdadm-controller/internal/thirdparty/api/v1alpha3"

const (
// EtcdMachinesSpecUpToDateCondition documents that the spec of the machines controlled by the EtcdadmCluster
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/etcdadmcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package v1alpha3

import (
etcdbp "github.com/aws/etcdadm-bootstrap-provider/api/v1alpha3"
clusterv1 "github.com/aws/etcdadm-controller/internal/thirdparty/api/v1alpha3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions api/v1beta1/etcdadmcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
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 @@ -57,33 +58,33 @@ func (r *EtcdadmCluster) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *EtcdadmCluster) ValidateCreate() error {
func (r *EtcdadmCluster) ValidateCreate() (admission.Warnings, error) {
etcdadmclusterlog.Info("validate create", "name", r.Name)

allErrs := r.validateCommon()
if len(allErrs) > 0 {
return apierrors.NewInvalid(GroupVersion.WithKind("EtcdadmCluster").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("EtcdadmCluster").GroupKind(), r.Name, allErrs)
}
return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *EtcdadmCluster) ValidateUpdate(old runtime.Object) error {
func (r *EtcdadmCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
etcdadmclusterlog.Info("validate update", "name", r.Name)

allErrs := r.validateCommon()
if len(allErrs) > 0 {
return apierrors.NewInvalid(GroupVersion.WithKind("EtcdadmCluster").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("EtcdadmCluster").GroupKind(), r.Name, allErrs)
}
return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *EtcdadmCluster) ValidateDelete() error {
func (r *EtcdadmCluster) ValidateDelete() (admission.Warnings, error) {
etcdadmclusterlog.Info("validate delete", "name", r.Name)

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

func (r *EtcdadmCluster) validateCommon() (allErrs field.ErrorList) {
Expand Down
26 changes: 13 additions & 13 deletions api/v1beta1/etcdadmcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestValidateCreate(t *testing.T) {
Expand All @@ -32,7 +32,7 @@ func TestValidateCreate(t *testing.T) {
"valid etcdadm cluster": {
in: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(3)),
Replicas: ptr.To(int32(3)),
},
Status: EtcdadmClusterStatus{},
},
Expand All @@ -48,7 +48,7 @@ func TestValidateCreate(t *testing.T) {
"zero replicas": {
in: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(0)),
Replicas: ptr.To(int32(0)),
},
Status: EtcdadmClusterStatus{},
},
Expand All @@ -57,7 +57,7 @@ func TestValidateCreate(t *testing.T) {
"even replicas": {
in: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(2)),
Replicas: ptr.To(int32(2)),
},
Status: EtcdadmClusterStatus{},
},
Expand All @@ -66,7 +66,7 @@ func TestValidateCreate(t *testing.T) {
"mismatched namespace": {
in: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(3)),
Replicas: ptr.To(int32(3)),
InfrastructureTemplate: corev1.ObjectReference{
Namespace: "fail",
},
Expand All @@ -79,7 +79,7 @@ func TestValidateCreate(t *testing.T) {
for name, tt := range cases {
t.Run(name, func(t *testing.T) {
g := NewWithT(t)
err := tt.in.ValidateCreate()
_, err := tt.in.ValidateCreate()
if tt.expectErr == "" {
g.Expect(err).To(BeNil())
} else {
Expand All @@ -97,13 +97,13 @@ func TestValidateUpdate(t *testing.T) {
"valid scale up": {
oldConf: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(3)),
Replicas: ptr.To(int32(3)),
},
Status: EtcdadmClusterStatus{},
},
newConf: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(5)),
Replicas: ptr.To(int32(5)),
},
Status: EtcdadmClusterStatus{},
},
Expand All @@ -112,13 +112,13 @@ func TestValidateUpdate(t *testing.T) {
"valid scale down": {
oldConf: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(3)),
Replicas: ptr.To(int32(3)),
},
Status: EtcdadmClusterStatus{},
},
newConf: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(1)),
Replicas: ptr.To(int32(1)),
},
Status: EtcdadmClusterStatus{},
},
Expand All @@ -127,13 +127,13 @@ func TestValidateUpdate(t *testing.T) {
"zero replicas": {
oldConf: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(3)),
Replicas: ptr.To(int32(3)),
},
Status: EtcdadmClusterStatus{},
},
newConf: &EtcdadmCluster{
Spec: EtcdadmClusterSpec{
Replicas: pointer.Int32(int32(0)),
Replicas: ptr.To(int32(0)),
},
Status: EtcdadmClusterStatus{},
},
Expand All @@ -143,7 +143,7 @@ func TestValidateUpdate(t *testing.T) {
for name, tt := range cases {
t.Run(name, func(t *testing.T) {
g := NewWithT(t)
err := tt.newConf.ValidateUpdate(tt.oldConf)
_, err := tt.newConf.ValidateUpdate(tt.oldConf)
if tt.expectErr != "" {
g.Expect(err).To(MatchError(ContainSubstring(tt.expectErr)))
} else {
Expand Down
4 changes: 2 additions & 2 deletions controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *EtcdadmClusterReconciler) SetupWithManager(ctx context.Context, mgr ctr
}

err = c.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(r.ClusterToEtcdadmCluster),
predicates.ClusterUnpausedAndInfrastructureReady(r.Log),
)
Expand Down Expand Up @@ -427,7 +427,7 @@ func (r *EtcdadmClusterReconciler) reconcileDelete(ctx context.Context, etcdClus

// ClusterToEtcdadmCluster is a handler.ToRequestsFunc to be used to enqueue requests for reconciliation
// for EtcdadmCluster based on updates to a Cluster.
func (r *EtcdadmClusterReconciler) ClusterToEtcdadmCluster(o client.Object) []ctrl.Request {
func (r *EtcdadmClusterReconciler) ClusterToEtcdadmCluster(ctx context.Context, o client.Object) []ctrl.Request {
c, ok := o.(*clusterv1.Cluster)
if !ok {
panic(fmt.Sprintf("Expected a Cluster but got a %T", o))
Expand Down
Loading

0 comments on commit 1b741aa

Please sign in to comment.