Skip to content

Commit 72793a8

Browse files
committed
chore: fix all linting issues
Signed-off-by: Jan Larwig <jan@larwig.com>
1 parent 5595b31 commit 72793a8

10 files changed

Lines changed: 87 additions & 67 deletions

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ linters:
2828
logcheck:
2929
type: "module"
3030
description: Checks Go logging calls for Kubernetes logging conventions.
31+
lll:
32+
line-length: 200
3133
revive:
3234
rules:
3335
- name: comment-spacings
@@ -45,6 +47,9 @@ linters:
4547
- dupl
4648
- lll
4749
path: internal/*
50+
- linters:
51+
- lll
52+
path: webhook/*
4853
paths:
4954
- third_party$
5055
- builtin$

cloud/sdk_client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
testSDKImageID = "22222222-2222-4222-8222-222222222222"
2929
testSDKSecurityGroup = "44444444-4444-4444-8444-444444444444"
3030
testBoolTrue = "true"
31+
testSDKPublicIP = "203.0.113.10"
3132
)
3233

3334
func TestSDKClientCreateServerUsesExpectedPayload(t *testing.T) {
@@ -146,7 +147,7 @@ func TestSDKClientEnsureAPIServerLoadBalancerCreatesExpectedPayload(t *testing.T
146147
if err != nil {
147148
t.Fatalf("EnsureAPIServerLoadBalancer() error = %v", err)
148149
}
149-
if loadBalancer.ID != "apiserver-test" || loadBalancer.IP != "203.0.113.10" || loadBalancer.Port != 6443 {
150+
if loadBalancer.ID != "apiserver-test" || loadBalancer.IP != testSDKPublicIP || loadBalancer.Port != 6443 {
150151
t.Fatalf("EnsureAPIServerLoadBalancer() = %#v", loadBalancer)
151152
}
152153

cmd/manager/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func main() {
186186
Client: mgr.GetClient(),
187187
Scheme: mgr.GetScheme(),
188188
CloudClientFactory: cloud.NewClient,
189-
Recorder: mgr.GetEventRecorderFor("stackitcluster-controller"),
189+
Recorder: mgr.GetEventRecorder("stackitcluster-controller"),
190190
}).SetupWithManager(mgr); err != nil {
191191
setupLog.Error(err, "Failed to create controller", "controller", "stackitcluster")
192192
os.Exit(1)
@@ -195,7 +195,7 @@ func main() {
195195
Client: mgr.GetClient(),
196196
Scheme: mgr.GetScheme(),
197197
CloudClientFactory: cloud.NewClient,
198-
Recorder: mgr.GetEventRecorderFor("stackitmachine-controller"),
198+
Recorder: mgr.GetEventRecorder("stackitmachine-controller"),
199199
}).SetupWithManager(mgr); err != nil {
200200
setupLog.Error(err, "Failed to create controller", "controller", "stackitmachine")
201201
os.Exit(1)

controller/stackitcluster_bastion.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (r *StackitClusterReconciler) reconcileBastion(
5353
}
5454
s.ClearBastionStatus()
5555
if r.Recorder != nil {
56-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "BastionDeleted", "Deleted bastion")
56+
r.Recorder.Eventf(sc, nil, corev1.EventTypeNormal, "BastionDeleted", "Delete", "Deleted bastion")
5757
}
5858
}
5959
s.SetConditions(metav1.ConditionTrue, "Skipped", "bastion disabled", infrav1.ClusterBastionReadyCondition)
@@ -82,7 +82,10 @@ func (r *StackitClusterReconciler) reconcileBastion(
8282
s.ClearBastionStatus()
8383
s.SetNotReady("Recreating", "recreating bastion because cloudInitRef content changed", infrav1.ClusterBastionReadyCondition, infrav1.ClusterReadyCondition)
8484
if r.Recorder != nil {
85-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "BastionRecreating", "Recreating bastion because cloudInitRef content changed")
85+
r.Recorder.Eventf(
86+
sc, nil, corev1.EventTypeNormal, "BastionRecreating", "Recreate",
87+
"Recreating bastion because cloudInitRef content changed",
88+
)
8689
}
8790
return ctrl.Result{RequeueAfter: retryableErrorRequeueAfter}, false, nil
8891
}
@@ -94,7 +97,9 @@ func (r *StackitClusterReconciler) reconcileBastion(
9497
}
9598
s.SetBastionStatus(bastion, bastionCloudInitHash(cloudInit))
9699
if !hadBastionStatus && r.Recorder != nil {
97-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "BastionCreated", "Created bastion %s", bastion.ServerID)
100+
r.Recorder.Eventf(
101+
sc, nil, corev1.EventTypeNormal, "BastionCreated", "Create", "Created bastion %s", bastion.ServerID,
102+
)
98103
}
99104
if bastion.ServerState != "" && bastion.ServerState != "ACTIVE" {
100105
s.SetNotReady("Provisioning", fmt.Sprintf("bastion server state is %s", bastion.ServerState), infrav1.ClusterBastionReadyCondition, infrav1.ClusterReadyCondition)

controller/stackitcluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
apierrors "k8s.io/apimachinery/pkg/api/errors"
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/apimachinery/pkg/types"
27-
"k8s.io/client-go/tools/record"
27+
"k8s.io/client-go/tools/events"
2828
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2929
clusterutil "sigs.k8s.io/cluster-api/util"
3030
ctrl "sigs.k8s.io/controller-runtime"
@@ -47,7 +47,7 @@ type StackitClusterReconciler struct {
4747
// CloudClientFactory builds a cloud.Client from parsed credentials. It is
4848
// injected so tests can swap in the in-memory fake.
4949
CloudClientFactory cloud.Factory
50-
Recorder record.EventRecorder
50+
Recorder events.EventRecorder
5151
}
5252

5353
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=stackitclusters,verbs=get;list;watch;create;update;patch;delete

controller/stackitcluster_controller_test.go

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
apierrors "k8s.io/apimachinery/pkg/api/errors"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apimachinery/pkg/types"
24-
"k8s.io/utils/ptr"
2524
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2625
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2726

@@ -89,9 +88,9 @@ var _ = Describe("StackitCluster Controller", func() {
8988
Expect(got.Status.APIServerEndpoint).To(Equal(got.Spec.ControlPlaneEndpoint))
9089
Expect(got.Status.APIServerLoadBalancerID).NotTo(BeEmpty())
9190
Expect(got.Status.FailureDomains).To(ConsistOf(
92-
clusterv1.FailureDomain{Name: "eu01-1", ControlPlane: ptr.To(true), Attributes: map[string]string{"region": "eu01"}},
93-
clusterv1.FailureDomain{Name: "eu01-2", ControlPlane: ptr.To(true), Attributes: map[string]string{"region": "eu01"}},
94-
clusterv1.FailureDomain{Name: "eu01-3", ControlPlane: ptr.To(true), Attributes: map[string]string{"region": "eu01"}},
91+
clusterv1.FailureDomain{Name: "eu01-1", ControlPlane: new(true), Attributes: map[string]string{"region": "eu01"}},
92+
clusterv1.FailureDomain{Name: "eu01-2", ControlPlane: new(true), Attributes: map[string]string{"region": "eu01"}},
93+
clusterv1.FailureDomain{Name: "eu01-3", ControlPlane: new(true), Attributes: map[string]string{"region": "eu01"}},
9594
))
9695
Expect(fakeCloud.LoadBalancerCount()).To(Equal(1))
9796
expectCondition(got.Status.Conditions, infrav1.ClusterReadyCondition, metav1.ConditionTrue, "Available")
@@ -212,51 +211,19 @@ var _ = Describe("StackitCluster Controller", func() {
212211
})
213212

214213
It("creates the bastion with cloud-init user data from a ConfigMap", func() {
215-
got := &infrav1.StackitCluster{}
216-
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
217-
cloudInitName := "bastion-cloud-init-" + clusterName
218-
cloudInit := "#cloud-config\npackages:\n- htop\n"
219-
createCloudInitConfigMap(ctx, cloudInitName, namespace, "userData", cloudInit)
220-
got.Spec.Bastion = validBastionSpec()
221-
got.Spec.Bastion.CloudInitRef = &infrav1.StackitBastionCloudInitRef{
222-
Kind: "ConfigMap",
223-
Name: cloudInitName,
224-
Key: "userData",
225-
}
226-
Expect(k8sClient.Update(ctx, got)).To(Succeed())
227-
228-
result, err := reconciler.Reconcile(ctx, request)
229-
Expect(err).NotTo(HaveOccurred())
230-
Expect(result).To(Equal(reconcile.Result{}))
231-
232-
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
233-
Expect(got.Status.Bastion.ServerID).NotTo(BeEmpty())
234-
Expect(got.Status.Bastion.CloudInitHash).To(Equal(bastionCloudInitHash([]byte(cloudInit))))
235-
Expect(string(fakeCloud.ServerUserData(got.Status.Bastion.ServerID))).To(Equal(cloudInit))
214+
expectBastionCloudInit(
215+
ctx, reconciler, request, stackitKey, fakeCloud,
216+
"ConfigMap", "bastion-cloud-init-"+clusterName,
217+
"#cloud-config\npackages:\n- htop\n", createCloudInitConfigMap,
218+
)
236219
})
237220

238221
It("creates the bastion with cloud-init user data from a Secret", func() {
239-
got := &infrav1.StackitCluster{}
240-
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
241-
cloudInitName := "bastion-cloud-init-secret-" + clusterName
242-
cloudInit := "#cloud-config\npackages:\n- jq\n"
243-
createCloudInitSecret(ctx, cloudInitName, namespace, "userData", cloudInit)
244-
got.Spec.Bastion = validBastionSpec()
245-
got.Spec.Bastion.CloudInitRef = &infrav1.StackitBastionCloudInitRef{
246-
Kind: "Secret",
247-
Name: cloudInitName,
248-
Key: "userData",
249-
}
250-
Expect(k8sClient.Update(ctx, got)).To(Succeed())
251-
252-
result, err := reconciler.Reconcile(ctx, request)
253-
Expect(err).NotTo(HaveOccurred())
254-
Expect(result).To(Equal(reconcile.Result{}))
255-
256-
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
257-
Expect(got.Status.Bastion.ServerID).NotTo(BeEmpty())
258-
Expect(got.Status.Bastion.CloudInitHash).To(Equal(bastionCloudInitHash([]byte(cloudInit))))
259-
Expect(string(fakeCloud.ServerUserData(got.Status.Bastion.ServerID))).To(Equal(cloudInit))
222+
expectBastionCloudInit(
223+
ctx, reconciler, request, stackitKey, fakeCloud,
224+
"Secret", "bastion-cloud-init-secret-"+clusterName,
225+
"#cloud-config\npackages:\n- jq\n", createCloudInitSecret,
226+
)
260227
})
261228

262229
It("marks the bastion not ready when cloud-init ref is missing", func() {
@@ -379,7 +346,7 @@ var _ = Describe("StackitCluster Controller", func() {
379346
It("does not call the cloud API when the owning Cluster is paused", func() {
380347
cluster := &clusterv1.Cluster{}
381348
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, cluster)).To(Succeed())
382-
cluster.Spec.Paused = ptr.To(true)
349+
cluster.Spec.Paused = new(true)
383350
Expect(k8sClient.Update(ctx, cluster)).To(Succeed())
384351

385352
cloudClientFactoryCalls := 0
@@ -517,6 +484,36 @@ var _ = Describe("StackitCluster Controller", func() {
517484
})
518485
})
519486

487+
func expectBastionCloudInit(
488+
ctx context.Context,
489+
reconciler *StackitClusterReconciler,
490+
request reconcile.Request,
491+
stackitKey types.NamespacedName,
492+
fakeCloud *cloudfake.Client,
493+
kind, cloudInitName, cloudInit string,
494+
createCloudInit func(context.Context, string, string, string, string),
495+
) {
496+
got := &infrav1.StackitCluster{}
497+
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
498+
createCloudInit(ctx, cloudInitName, got.Namespace, "userData", cloudInit)
499+
got.Spec.Bastion = validBastionSpec()
500+
got.Spec.Bastion.CloudInitRef = &infrav1.StackitBastionCloudInitRef{
501+
Kind: kind,
502+
Name: cloudInitName,
503+
Key: "userData",
504+
}
505+
Expect(k8sClient.Update(ctx, got)).To(Succeed())
506+
507+
result, err := reconciler.Reconcile(ctx, request)
508+
Expect(err).NotTo(HaveOccurred())
509+
Expect(result).To(Equal(reconcile.Result{}))
510+
511+
Expect(k8sClient.Get(ctx, stackitKey, got)).To(Succeed())
512+
Expect(got.Status.Bastion.ServerID).NotTo(BeEmpty())
513+
Expect(got.Status.Bastion.CloudInitHash).To(Equal(bastionCloudInitHash([]byte(cloudInit))))
514+
Expect(string(fakeCloud.ServerUserData(got.Status.Bastion.ServerID))).To(Equal(cloudInit))
515+
}
516+
520517
func newStackitCluster(name, namespace string, lbEnabled bool) *infrav1.StackitCluster {
521518
return &infrav1.StackitCluster{
522519
ObjectMeta: metav1.ObjectMeta{

controller/stackitcluster_infrastructure.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ func (r *StackitClusterReconciler) reconcileNormal(ctx context.Context, s *scope
9393
if lb != nil {
9494
sc.Status.APIServerLoadBalancerID = lb.ID
9595
if !hadLoadBalancerID && lb.ID != "" && r.Recorder != nil {
96-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "LoadBalancerCreated", "Created API server load balancer %s", lb.ID)
96+
r.Recorder.Eventf(
97+
sc, nil, corev1.EventTypeNormal, "LoadBalancerCreated", "Create",
98+
"Created API server load balancer %s", lb.ID,
99+
)
97100
}
98101
}
99102
if lb == nil || lb.IP == "" {
@@ -107,7 +110,10 @@ func (r *StackitClusterReconciler) reconcileNormal(ctx context.Context, s *scope
107110
s.SetAPIServerEndpoint(endpoint)
108111
s.SetConditions(metav1.ConditionTrue, "Available", "", infrav1.ClusterLoadBalancerReadyCondition)
109112
if r.Recorder != nil {
110-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "LoadBalancerReady", "API server load balancer is ready at %s", lb.IP)
113+
r.Recorder.Eventf(
114+
sc, nil, corev1.EventTypeNormal, "LoadBalancerReady", "SetReady",
115+
"API server load balancer is ready at %s", lb.IP,
116+
)
111117
}
112118
} else if sc.Spec.ControlPlaneEndpoint.Host != "" {
113119
sc.Status.APIServerEndpoint = sc.Spec.ControlPlaneEndpoint
@@ -210,7 +216,10 @@ func (r *StackitClusterReconciler) reconcileDelete(ctx context.Context, s *scope
210216
}
211217
sc.Status.APIServerLoadBalancerID = ""
212218
if r.Recorder != nil {
213-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "LoadBalancerDeleted", "Deleted API server load balancer %s", loadBalancerID)
219+
r.Recorder.Eventf(
220+
sc, nil, corev1.EventTypeNormal, "LoadBalancerDeleted", "Delete",
221+
"Deleted API server load balancer %s", loadBalancerID,
222+
)
214223
}
215224
}
216225
if hasBastionStatus(sc.Status.Bastion) {
@@ -227,7 +236,7 @@ func (r *StackitClusterReconciler) reconcileDelete(ctx context.Context, s *scope
227236
}
228237
s.ClearBastionStatus()
229238
if r.Recorder != nil {
230-
r.Recorder.Eventf(sc, corev1.EventTypeNormal, "BastionDeleted", "Deleted bastion")
239+
r.Recorder.Eventf(sc, nil, corev1.EventTypeNormal, "BastionDeleted", "Delete", "Deleted bastion")
231240
}
232241
}
233242
}

controller/stackitmachine_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
corev1 "k8s.io/api/core/v1"
2424
apierrors "k8s.io/apimachinery/pkg/api/errors"
2525
"k8s.io/apimachinery/pkg/runtime"
26-
"k8s.io/client-go/tools/record"
26+
"k8s.io/client-go/tools/events"
2727
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2828
clusterutil "sigs.k8s.io/cluster-api/util"
2929
ctrl "sigs.k8s.io/controller-runtime"
@@ -44,7 +44,7 @@ type StackitMachineReconciler struct {
4444

4545
// CloudClientFactory builds a cloud.Client from parsed credentials.
4646
CloudClientFactory cloud.Factory
47-
Recorder record.EventRecorder
47+
Recorder events.EventRecorder
4848
}
4949

5050
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=stackitmachines,verbs=get;list;watch;create;update;patch;delete

controller/stackitmachine_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
apierrors "k8s.io/apimachinery/pkg/api/errors"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/apimachinery/pkg/types"
24-
"k8s.io/utils/ptr"
2524
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2625
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2726

@@ -237,7 +236,7 @@ var _ = Describe("StackitMachine Controller", func() {
237236
createBootstrapSecret(ctx, bootstrapName)
238237
cluster := &clusterv1.Cluster{}
239238
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: clusterName, Namespace: namespace}, cluster)).To(Succeed())
240-
cluster.Spec.Paused = ptr.To(true)
239+
cluster.Spec.Paused = new(true)
241240
Expect(k8sClient.Update(ctx, cluster)).To(Succeed())
242241

243242
cloudClientFactoryCalls := 0

controller/stackitmachine_infrastructure.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ func (r *StackitMachineReconciler) reconcileNormal(ctx context.Context, s *scope
8585
)
8686
}
8787
if created && r.Recorder != nil {
88-
r.Recorder.Eventf(sm, corev1.EventTypeNormal, "InstanceCreated", "Created instance %s", server.ID)
88+
r.Recorder.Eventf(
89+
sm, nil, corev1.EventTypeNormal, "InstanceCreated", "Create", "Created instance %s", server.ID,
90+
)
8991
}
9092

9193
sm.Status.InstanceState = server.State
@@ -147,7 +149,7 @@ func (r *StackitMachineReconciler) reconcileDelete(ctx context.Context, s *scope
147149
if sm.Status.InstanceID == "" && !needsLoadBalancerCleanup {
148150
controllerutil.RemoveFinalizer(sm, infrav1.MachineFinalizer)
149151
if r.Recorder != nil {
150-
r.Recorder.Eventf(sm, corev1.EventTypeNormal, "InstanceDeleted", "Deleted instance")
152+
r.Recorder.Eventf(sm, nil, corev1.EventTypeNormal, "InstanceDeleted", "Delete", "Deleted instance")
151153
}
152154
return nil
153155
}
@@ -167,7 +169,7 @@ func (r *StackitMachineReconciler) reconcileDelete(ctx context.Context, s *scope
167169
if sm.Status.InstanceID == "" {
168170
controllerutil.RemoveFinalizer(sm, infrav1.MachineFinalizer)
169171
if r.Recorder != nil {
170-
r.Recorder.Eventf(sm, corev1.EventTypeNormal, "InstanceDeleted", "Deleted instance")
172+
r.Recorder.Eventf(sm, nil, corev1.EventTypeNormal, "InstanceDeleted", "Delete", "Deleted instance")
171173
}
172174
return nil
173175
}
@@ -178,7 +180,9 @@ func (r *StackitMachineReconciler) reconcileDelete(ctx context.Context, s *scope
178180
s.ClearInstance()
179181
controllerutil.RemoveFinalizer(sm, infrav1.MachineFinalizer)
180182
if r.Recorder != nil {
181-
r.Recorder.Eventf(sm, corev1.EventTypeNormal, "InstanceDeleted", "Deleted instance %s", instanceID)
183+
r.Recorder.Eventf(
184+
sm, nil, corev1.EventTypeNormal, "InstanceDeleted", "Delete", "Deleted instance %s", instanceID,
185+
)
182186
}
183187
return nil
184188
}

0 commit comments

Comments
 (0)