Skip to content

Commit 899248c

Browse files
committed
respect delete-for-move annotation (Backport #1074)
1 parent 53aad37 commit 899248c

17 files changed

Lines changed: 72 additions & 77 deletions

.github/workflows/e2e-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
registry-1.docker.io:443
102102
auth.docker.io:443
103103
production.cloudflare.docker.com:443
104+
production.cloudfront.docker.com:443
104105
storage.googleapis.com:443
105106
registry.k8s.io:443
106107
*.pkg.dev:443

.github/workflows/e2e-upgrade-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
registry-1.docker.io:443
6464
auth.docker.io:443
6565
production.cloudflare.docker.com:443
66+
production.cloudfront.docker.com:443
6667
storage.googleapis.com:443
6768
registry.k8s.io:443
6869
*.pkg.dev:443

.github/workflows/go-analyze.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
*.githubusercontent.com:443
5454
auth.docker.io:443
5555
production.cloudflare.docker.com:443
56+
production.cloudfront.docker.com:443
5657
vuln.go.dev:443
5758
storage.googleapis.com:443
5859
golangci-lint.run:443

.github/workflows/pull_request_ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ jobs:
104104
registry-1.docker.io:443
105105
auth.docker.io:443
106106
production.cloudflare.docker.com:443
107+
production.cloudfront.docker.com:443
107108
gcr.io:443
108109
storage.googleapis.com:443
109110

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ docs:
154154

155155
.PHONY: test
156156
test: generate fmt vet envtest ## Run tests.
157-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use ${ENVTEST_K8S_VERSION#v} --bin-dir $(CACHE_BIN) -p path)" go test -race -timeout 60s `go list ./... | grep -v ./mock$$` -coverprofile cover.out.tmp
157+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use ${ENVTEST_K8S_VERSION#v} --bin-dir $(CACHE_BIN) -p path)" go test -timeout 60s `go list ./... | grep -v ./mock$$` -coverpkg=./... -coverprofile cover.out.tmp
158158
grep -v "zz_generated.*" cover.out.tmp > cover.out
159159
rm cover.out.tmp
160160

internal/controller/linodecluster_controller.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,11 @@ type LinodeClusterReconciler struct {
7474
// Reconcile is part of the main kubernetes reconciliation loop which aims to
7575
// move the current state of the cluster closer to the desired state.
7676

77-
func (r *LinodeClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
77+
func (r *LinodeClusterReconciler) Reconcile(ctx context.Context, linodeCluster *infrav1alpha2.LinodeCluster) (ctrl.Result, error) {
7878
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout))
7979
defer cancel()
8080

81-
logger := ctrl.LoggerFrom(ctx).WithName("LinodeClusterReconciler").WithValues("name", req.String())
82-
linodeCluster := &infrav1alpha2.LinodeCluster{}
83-
if err := r.TracedClient().Get(ctx, req.NamespacedName, linodeCluster); err != nil {
84-
logger.Info("Failed to fetch Linode cluster", "error", err.Error())
85-
86-
return ctrl.Result{}, client.IgnoreNotFound(err)
87-
}
81+
logger := ctrl.LoggerFrom(ctx).WithName("LinodeClusterReconciler").WithValues("name", linodeCluster.Name, "namespace", linodeCluster.Namespace)
8882

8983
cluster, err := kutil.GetOwnerCluster(ctx, r.TracedClient(), linodeCluster.ObjectMeta)
9084
if err != nil {
@@ -544,7 +538,7 @@ func (r *LinodeClusterReconciler) SetupWithManager(mgr ctrl.Manager, options crc
544538
Watches(
545539
&infrav1alpha2.LinodeMachine{},
546540
handler.EnqueueRequestsFromMapFunc(linodeMachineToLinodeCluster(r.TracedClient(), mgr.GetLogger())),
547-
).Complete(wrappedruntimereconciler.NewRuntimeReconcilerWithTracing(r, wrappedruntimereconciler.DefaultDecorator()))
541+
).Complete(reconciler.AsReconcilerWithTracing(r.TracedClient(), r))
548542
if err != nil {
549543
return fmt.Errorf("failed to build controller: %w", err)
550544
}

internal/controller/linodecluster_controller_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"sigs.k8s.io/cluster-api/util/paused"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
36-
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3736

3837
infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2"
3938
"github.com/linode/cluster-api-provider-linode/cloud/scope"
@@ -289,9 +288,7 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
289288
}),
290289
Result("no capl cluster error", func(ctx context.Context, mck Mock) {
291290
reconciler.Client = k8sClient
292-
_, err := reconciler.Reconcile(ctx, reconcile.Request{
293-
NamespacedName: client.ObjectKeyFromObject(cScope.LinodeCluster),
294-
})
291+
_, err := reconciler.Reconcile(ctx, cScope.LinodeCluster)
295292
Expect(err).NotTo(HaveOccurred())
296293
Expect(linodeCluster.Status.Ready).To(BeFalseBecause("failed to get Cluster/no-capl-cluster: clusters.cluster.x-k8s.io \"no-capl-cluster\" not found"))
297294
}),
@@ -373,7 +370,7 @@ var _ = Describe("pause handling", Label("cluster", "pause"), func() {
373370
DnsClientConfig: scope.ClientConfig{Token: "test-token"},
374371
}
375372

376-
_, err := reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(linodeCluster)})
373+
_, err := reconciler.Reconcile(ctx, linodeCluster)
377374
Expect(err).NotTo(HaveOccurred())
378375

379376
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(linodeCluster), linodeCluster)).To(Succeed())

internal/controller/linodefirewall_controller_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func findObjectsForObject(logger logr.Logger, tracedClient client.Client) handle
5555
logger.Info("LinodeFirewall(s) not found for %s")
5656

5757
return nil
58-
case err != nil:
58+
default:
5959
logger.Error(err, "Failed to get LinodeFirewalls")
6060

6161
return nil

internal/controller/linodeobjectstoragebucket_controller.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
"github.com/linode/cluster-api-provider-linode/cloud/scope"
4545
"github.com/linode/cluster-api-provider-linode/cloud/services"
4646
wrappedruntimeclient "github.com/linode/cluster-api-provider-linode/observability/wrappers/runtimeclient"
47-
wrappedruntimereconciler "github.com/linode/cluster-api-provider-linode/observability/wrappers/runtimereconciler"
4847
"github.com/linode/cluster-api-provider-linode/util"
4948
"github.com/linode/cluster-api-provider-linode/util/reconciler"
5049
)
@@ -76,20 +75,11 @@ type LinodeObjectStorageBucketReconciler struct {
7675
//
7776
// For more details, check Reconcile and its Result here:
7877
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.17.0/pkg/reconcile
79-
func (r *LinodeObjectStorageBucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
78+
func (r *LinodeObjectStorageBucketReconciler) Reconcile(ctx context.Context, objectStorageBucket *infrav1alpha2.LinodeObjectStorageBucket) (ctrl.Result, error) {
8079
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout))
8180
defer cancel()
8281

83-
logger := r.Logger.WithValues("name", req.String())
84-
85-
objectStorageBucket := &infrav1alpha2.LinodeObjectStorageBucket{}
86-
if err := r.TracedClient().Get(ctx, req.NamespacedName, objectStorageBucket); err != nil {
87-
if err = client.IgnoreNotFound(err); err != nil {
88-
logger.Error(err, "Failed to fetch LinodeObjectStorageBucket", "name", req.String())
89-
}
90-
91-
return ctrl.Result{}, err
92-
}
82+
logger := r.Logger.WithValues("name", objectStorageBucket.Name, "namespace", objectStorageBucket.Namespace)
9383

9484
if _, ok := objectStorageBucket.Labels[clusterv1.ClusterNameLabel]; ok {
9585
cluster, err := kutil.GetClusterFromMetadata(ctx, r.TracedClient(), objectStorageBucket.ObjectMeta)
@@ -254,7 +244,7 @@ func (r *LinodeObjectStorageBucketReconciler) SetupWithManager(mgr ctrl.Manager,
254244
&clusterv1.Cluster{},
255245
handler.EnqueueRequestsFromMapFunc(linodeObjectStorageBucketMapper),
256246
builder.WithPredicates(predicates.ClusterPausedTransitionsOrInfrastructureReady(mgr.GetScheme(), mgr.GetLogger())),
257-
).Complete(wrappedruntimereconciler.NewRuntimeReconcilerWithTracing(r, wrappedruntimereconciler.DefaultDecorator()))
247+
).Complete(reconciler.AsReconcilerWithTracing(r.TracedClient(), r))
258248
if err != nil {
259249
return fmt.Errorf("failed to build controller: %w", err)
260250
}

internal/controller/linodeobjectstoragebucket_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/linode/cluster-api-provider-linode/cloud/scope"
3838
"github.com/linode/cluster-api-provider-linode/mock"
3939
"github.com/linode/cluster-api-provider-linode/util"
40+
rec "github.com/linode/cluster-api-provider-linode/util/reconciler"
4041

4142
. "github.com/linode/cluster-api-provider-linode/mock/mocktest"
4243
. "github.com/onsi/ginkgo/v2"
@@ -329,7 +330,7 @@ var _ = Describe("errors", Label("bucket", "errors"), func() {
329330
}),
330331
Result("no error", func(ctx context.Context, mck Mock) {
331332
reconciler.Client = mck.K8sClient
332-
_, err := reconciler.Reconcile(ctx, reconcile.Request{
333+
_, err := rec.AsReconcilerWithTracing(mck.K8sClient, &reconciler).Reconcile(ctx, reconcile.Request{
333334
NamespacedName: client.ObjectKeyFromObject(bScope.Bucket),
334335
})
335336
Expect(err).NotTo(HaveOccurred())
@@ -342,18 +343,17 @@ var _ = Describe("errors", Label("bucket", "errors"), func() {
342343
Result("error", func(ctx context.Context, mck Mock) {
343344
reconciler.Client = mck.K8sClient
344345
reconciler.Logger = bScope.Logger
345-
_, err := reconciler.Reconcile(ctx, reconcile.Request{
346+
_, err := rec.AsReconcilerWithTracing(mck.K8sClient, &reconciler).Reconcile(ctx, reconcile.Request{
346347
NamespacedName: client.ObjectKeyFromObject(bScope.Bucket),
347348
})
348349
Expect(err.Error()).To(ContainSubstring("non-404 error"))
349-
Expect(mck.Logs()).To(ContainSubstring("Failed to fetch LinodeObjectStorageBucket"))
350350
}),
351351
),
352352
),
353353
Result("scope params is missing args", func(ctx context.Context, mck Mock) {
354354
reconciler.Client = mck.K8sClient
355355
reconciler.Logger = bScope.Logger
356-
_, err := reconciler.Reconcile(ctx, reconcile.Request{
356+
_, err := rec.AsReconcilerWithTracing(mck.K8sClient, &reconciler).Reconcile(ctx, reconcile.Request{
357357
NamespacedName: client.ObjectKeyFromObject(bScope.Bucket),
358358
})
359359
Expect(err.Error()).To(ContainSubstring("failed to create object storage bucket scope"))

0 commit comments

Comments
 (0)