Skip to content

Commit fe0dd96

Browse files
committed
chore: adjust etcd space calculation and NOSPACE alarm dismissal
chore: replace span/log/recorder with emit
1 parent 76e651c commit fe0dd96

32 files changed

Lines changed: 856 additions & 471 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ testbin/*
4040
*.swp
4141
*.swo
4242
*~
43+
44+
.claude

.golangci.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ linters:
264264
# msg: Use slog instead
265265
- pattern: ^(record|events)\.NewFakeRecorder(For)?$
266266
msg: Use pkg/operator/util/recorder/fake_recorder.go instead.
267+
- pattern: ^trace\.Span\.AddEvent$
268+
msg: use emit.Warnf/Infof with SinkSpanEvent instead
269+
- pattern: ^slog\.Logger\.(Warn|Info)Context$
270+
msg: use emit.Warnf/emit.Infof instead
271+
- pattern: ^recorder\.Recorder\.(Warnf|Normalf)$
272+
msg: use emit.Warnf/emit.Infof instead
273+
- pattern: ^NewWithT$
274+
pkg: ^github\.com/onsi/gomega$
275+
msg: use G() from the test package instead
267276
revive:
268277
rules:
269278
- name: exported
@@ -338,6 +347,13 @@ linters:
338347
- gocritic
339348
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
340349
path: *testFiles
350+
- linters:
351+
- forbidigo
352+
path: pkg/operator/util/emit/emit\.go
353+
# volume_stats_test cannot import the test package: test imports volume_stats (cycle)
354+
- linters:
355+
- forbidigo
356+
path: pkg/reconcilers/etcd_cluster/volume_stats/volume_stats_test\.go
341357

342358
run:
343359
timeout: 10m

api/v1alpha1/webhook/hostedcontrolplane_webhook_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
. "github.com/onsi/gomega"
77
"github.com/teutonet/cluster-api-provider-hosted-control-plane/api/v1alpha1"
88
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/importcycle"
9+
. "github.com/teutonet/cluster-api-provider-hosted-control-plane/test"
910
"k8s.io/apimachinery/pkg/api/resource"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
"k8s.io/utils/ptr"
@@ -186,7 +187,7 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
186187

187188
for _, tt := range tests {
188189
t.Run(tt.name, func(t *testing.T) {
189-
g := NewWithT(t)
190+
g, _, _ := G(t)
190191
_, err := webhook.ValidateCreate(t.Context(), tt.hcp)
191192

192193
if tt.expectErr {
@@ -318,7 +319,7 @@ func TestHostedControlPlaneWebhook_ValidateUpdate(t *testing.T) {
318319

319320
for _, tt := range tests {
320321
t.Run(tt.name, func(t *testing.T) {
321-
g := NewWithT(t)
322+
g, _, _ := G(t)
322323
_, err := webhook.ValidateUpdate(t.Context(), tt.oldHCP, tt.newHCP)
323324

324325
if tt.expectErr {
@@ -332,7 +333,7 @@ func TestHostedControlPlaneWebhook_ValidateUpdate(t *testing.T) {
332333

333334
func TestHostedControlPlaneWebhook_ValidateDelete(t *testing.T) {
334335
webhook := &hostedControlPlaneWebhook{}
335-
g := NewWithT(t)
336+
g, _, _ := G(t)
336337

337338
hcp := &v1alpha1.HostedControlPlane{
338339
ObjectMeta: metav1.ObjectMeta{
@@ -386,7 +387,7 @@ func TestHostedControlPlaneWebhook_ParseVersion(t *testing.T) {
386387

387388
for _, tt := range tests {
388389
t.Run(tt.name, func(t *testing.T) {
389-
g := NewWithT(t)
390+
g, _, _ := G(t)
390391
hcp := &v1alpha1.HostedControlPlane{
391392
Spec: v1alpha1.HostedControlPlaneSpec{
392393
Version: tt.version,

pkg/hostedcontrolplane/controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/teutonet/cluster-api-provider-hosted-control-plane/api"
2020
"github.com/teutonet/cluster-api-provider-hosted-control-plane/api/v1alpha1"
2121
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/importcycle"
22+
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/operator/util/emit"
2223
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/operator/util/recorder"
2324
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/reconcilers/alias"
2425
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/reconcilers/apiserverresources"
@@ -383,7 +384,10 @@ func (r *hostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
383384
return ctrl.Result{}, fmt.Errorf("failed to retrieve owner Cluster: %w", err)
384385
}
385386
if cluster == nil {
386-
span.AddEvent("Cluster Controller has not yet set OwnerRef")
387+
emit.Info(ctx, emit.SinkSpanEvent, hostedControlPlane,
388+
"ClusterOwnerRefMissing", "OwnerRefCheck",
389+
"Cluster Controller has not yet set OwnerRef",
390+
)
387391
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
388392
}
389393

@@ -565,7 +569,6 @@ func (r *hostedControlPlaneReconciler) reconcileNormal(
565569
r.caCertificatesDuration,
566570
r.certificatesDuration,
567571
r.konnectivityServerAudience,
568-
recorder.FromContext(ctx),
569572
)
570573
kubeconfigReconciler := kubeconfig.NewKubeconfigReconciler(
571574
r.managementClusterClient,
@@ -582,7 +585,6 @@ func (r *hostedControlPlaneReconciler) reconcileNormal(
582585
r.etcdClientFactory,
583586
r.s3ClientFactory,
584587
r.volumeStatsProvider,
585-
recorder.FromContext(ctx),
586588
r.etcdComponentLabel,
587589
r.apiServerComponentLabel,
588590
r.controllerNamespace,

pkg/hostedcontrolplane/controller_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/reconcilers/alias"
1414
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/reconcilers/etcd_cluster/etcd_client"
1515
"github.com/teutonet/cluster-api-provider-hosted-control-plane/pkg/reconcilers/etcd_cluster/s3_client"
16-
"github.com/teutonet/cluster-api-provider-hosted-control-plane/test"
16+
. "github.com/teutonet/cluster-api-provider-hosted-control-plane/test"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1818
"k8s.io/apimachinery/pkg/runtime"
1919
"k8s.io/apimachinery/pkg/types"
@@ -33,7 +33,7 @@ var (
3333
_ *v1alpha1.HostedControlPlane,
3434
_ *capiv2.Cluster,
3535
) (s3_client.S3Client, error) {
36-
return test.NewS3ClientStub(), nil
36+
return NewS3ClientStub(), nil
3737
}
3838
etcdClientStubFactory = func(
3939
_ context.Context,
@@ -42,7 +42,7 @@ var (
4242
_ *capiv2.Cluster,
4343
_ int32,
4444
) (etcd_client.EtcdClient, error) {
45-
return test.NewEtcdClientStub(), nil
45+
return NewEtcdClientStub(), nil
4646
}
4747
workloadClusterClientStubFactory = func(
4848
_ context.Context,
@@ -66,7 +66,7 @@ func createTestReconciler(client client.Client) HostedControlPlaneReconciler {
6666
workloadClusterClientStubFactory,
6767
etcdClientStubFactory,
6868
s3ClientStubFactory,
69-
test.NewEtcdVolumeStatsProviderStub(),
69+
NewEtcdVolumeStatsProviderStub(),
7070
&recorder.InfiniteDiscardingFakeRecorder{},
7171
"test-namespace",
7272
)
@@ -214,7 +214,7 @@ func TestHostedControlPlaneReconciler_ReconcileWorkflow(t *testing.T) {
214214
for _, tt := range tests {
215215
t.Run(tt.name, func(t *testing.T) {
216216
ctx := t.Context()
217-
g := NewWithT(t)
217+
g, _, _ := G(t)
218218
scheme := runtime.NewScheme()
219219
g.Expect(capiv2.AddToScheme(scheme)).To(Succeed())
220220
g.Expect(v1alpha1.AddToScheme(scheme)).To(Succeed())
@@ -264,13 +264,13 @@ func TestHostedControlPlaneReconciler_ReconcileWorkflow(t *testing.T) {
264264

265265
func TestHostedControlPlaneReconciler_FinalizerManagement(t *testing.T) {
266266
scheme := runtime.NewScheme()
267-
g := NewWithT(t)
267+
g, _, _ := G(t)
268268
g.Expect(v1alpha1.AddToScheme(scheme)).To(Succeed())
269269
g.Expect(capiv2.AddToScheme(scheme)).To(Succeed())
270270

271271
t.Run("finalizer behavior during reconcile lifecycle", func(t *testing.T) {
272272
ctx := t.Context()
273-
g := NewWithT(t)
273+
g, _, _ := G(t)
274274
cluster := createTestCluster("test-cluster", "default")
275275
hostedControlPlane := withReplicas(
276276
withOwnerReference(createTestHostedControlPlane("test-hcp", "default"), cluster),
@@ -313,7 +313,7 @@ func TestHostedControlPlaneReconciler_FinalizerManagement(t *testing.T) {
313313

314314
t.Run("finalizer should be removed during deletion", func(t *testing.T) {
315315
ctx := t.Context()
316-
g := NewWithT(t)
316+
g, _, _ := G(t)
317317
cluster := createTestClusterWithPausedCondition("test-cluster", "default", false)
318318
hostedControlPlane := withDeletion(
319319
withOwnerReference(createTestHostedControlPlane("test-hcp", "default"), cluster),
@@ -360,13 +360,13 @@ func TestHostedControlPlaneReconciler_FinalizerManagement(t *testing.T) {
360360

361361
func TestHostedControlPlaneReconciler_OwnerReferenceValidation(t *testing.T) {
362362
scheme := runtime.NewScheme()
363-
g := NewWithT(t)
363+
g, _, _ := G(t)
364364
g.Expect(v1alpha1.AddToScheme(scheme)).To(Succeed())
365365
g.Expect(capiv2.AddToScheme(scheme)).To(Succeed())
366366

367367
t.Run("should requeue when owner cluster is not found", func(t *testing.T) {
368368
ctx := t.Context()
369-
g := NewWithT(t)
369+
g, _, _ := G(t)
370370
hostedControlPlane := createTestHostedControlPlane("test-hcp", "default")
371371

372372
fakeClient := fakeClient.NewClientBuilder().
@@ -393,7 +393,7 @@ func TestHostedControlPlaneReconciler_OwnerReferenceValidation(t *testing.T) {
393393

394394
t.Run("should proceed when valid owner cluster is found", func(t *testing.T) {
395395
ctx := t.Context()
396-
g := NewWithT(t)
396+
g, _, _ := G(t)
397397
cluster := createTestCluster("test-cluster", "default")
398398
hostedControlPlane := withReplicas(
399399
withOwnerReference(createTestHostedControlPlane("test-hcp", "default"), cluster),
@@ -430,13 +430,13 @@ func TestHostedControlPlaneReconciler_OwnerReferenceValidation(t *testing.T) {
430430

431431
func TestHostedControlPlaneReconciler_StatusConditions(t *testing.T) {
432432
scheme := runtime.NewScheme()
433-
g := NewWithT(t)
433+
g, _, _ := G(t)
434434
g.Expect(v1alpha1.AddToScheme(scheme)).To(Succeed())
435435
g.Expect(capiv2.AddToScheme(scheme)).To(Succeed())
436436

437437
t.Run("should set paused condition when cluster is paused", func(t *testing.T) {
438438
ctx := t.Context()
439-
g := NewWithT(t)
439+
g, _, _ := G(t)
440440
cluster := withPaused(createTestCluster("test-cluster", "default"), true)
441441
hostedControlPlane := withOwnerReference(createTestHostedControlPlane("test-hcp", "default"), cluster)
442442

@@ -482,7 +482,7 @@ func TestHostedControlPlaneReconciler_StatusConditions(t *testing.T) {
482482

483483
func TestHostedControlPlaneReconciler_ObservedGeneration(t *testing.T) {
484484
scheme := runtime.NewScheme()
485-
g := NewWithT(t)
485+
g, _, _ := G(t)
486486
g.Expect(v1alpha1.AddToScheme(scheme)).To(Succeed())
487487
g.Expect(capiv2.AddToScheme(scheme)).To(Succeed())
488488

@@ -534,7 +534,7 @@ func TestHostedControlPlaneReconciler_ObservedGeneration(t *testing.T) {
534534
for _, tt := range tests {
535535
t.Run(tt.name, func(t *testing.T) {
536536
ctx := t.Context()
537-
g := NewWithT(t)
537+
g, _, _ := G(t)
538538

539539
objs := []client.Object{tt.hostedControlPlane}
540540
if tt.cluster != nil {
@@ -584,7 +584,7 @@ func TestHostedControlPlaneReconciler_ObservedGeneration(t *testing.T) {
584584

585585
func TestHostedControlPlaneReconciler_NonExistentResource(t *testing.T) {
586586
scheme := runtime.NewScheme()
587-
g := NewWithT(t)
587+
g, _, _ := G(t)
588588
g.Expect(v1alpha1.AddToScheme(scheme)).To(Succeed())
589589

590590
fakeClient := fakeClient.NewClientBuilder().

0 commit comments

Comments
 (0)