Skip to content

Commit 3f823cc

Browse files
committed
refactor pause logic
remove pause logic from linodemachine fix linting fix linting fix tests :seedling: Bump github.com/linode/linodego from 1.48.0 to 1.48.1 Bumps [github.com/linode/linodego](https://github.com/linode/linodego) from 1.48.0 to 1.48.1. - [Release notes](https://github.com/linode/linodego/releases) - [Commits](linode/linodego@v1.48.0...v1.48.1) --- updated-dependencies: - dependency-name: github.com/linode/linodego dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> :seedling: Bump sigs.k8s.io/controller-runtime in the kubernetes group Bumps the kubernetes group with 1 update: [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime). Updates `sigs.k8s.io/controller-runtime` from 0.20.2 to 0.20.3 - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](kubernetes-sigs/controller-runtime@v0.20.2...v0.20.3) --- updated-dependencies: - dependency-name: sigs.k8s.io/controller-runtime dependency-type: direct:production update-type: version-update:semver-patch dependency-group: kubernetes ... Signed-off-by: dependabot[bot] <[email protected]> don't update firewall if label exists remove extra char fix test add pause condition back into lc and lm, fix tests fix linting remove extra return fix missing values :seedling: Bump github.com/onsi/ginkgo/v2 from 2.22.2 to 2.23.0 Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.22.2 to 2.23.0. - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](onsi/ginkgo@v2.22.2...v2.23.0) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> remove values fix packages fixx tests fix linting fix tests attempt to fix test add expect to k8s call add label to linode vpc to prevent clash in uppdate removed pause condition because happens in Reconcile fix comments, add annotation test address comments fix comments add test for linode cluster
1 parent c6337fb commit 3f823cc

File tree

11 files changed

+192
-126
lines changed

11 files changed

+192
-126
lines changed

cloud/scope/firewall.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020

2121
"k8s.io/client-go/util/retry"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
"sigs.k8s.io/cluster-api/util/patch"
2324
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2425

@@ -34,12 +35,14 @@ type FirewallScope struct {
3435
PatchHelper *patch.Helper
3536
LinodeClient LinodeClient
3637
LinodeFirewall *infrav1alpha2.LinodeFirewall
38+
Cluster *clusterv1.Cluster
3739
}
3840

3941
// FirewallScopeParams defines the input parameters used to create a new Scope.
4042
type FirewallScopeParams struct {
4143
Client K8sClient
4244
LinodeFirewall *infrav1alpha2.LinodeFirewall
45+
Cluster *clusterv1.Cluster
4346
}
4447

4548
func validateFirewallScopeParams(params FirewallScopeParams) error {
@@ -75,6 +78,7 @@ func NewFirewallScope(ctx context.Context, linodeClientConfig ClientConfig, para
7578
LinodeClient: linodeClient,
7679
LinodeFirewall: params.LinodeFirewall,
7780
PatchHelper: helper,
81+
Cluster: params.Cluster,
7882
}, nil
7983
}
8084

cloud/scope/placement_group.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2425
"sigs.k8s.io/cluster-api/util/patch"
2526
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2627

@@ -36,12 +37,14 @@ type PlacementGroupScope struct {
3637
PatchHelper *patch.Helper
3738
LinodeClient LinodeClient
3839
LinodePlacementGroup *infrav1alpha2.LinodePlacementGroup
40+
Cluster *clusterv1.Cluster
3941
}
4042

4143
// PlacementGroupScopeParams defines the input parameters used to create a new Scope.
4244
type PlacementGroupScopeParams struct {
4345
Client K8sClient
4446
LinodePlacementGroup *infrav1alpha2.LinodePlacementGroup
47+
Cluster *clusterv1.Cluster
4548
}
4649

4750
func validatePlacementGroupScope(params PlacementGroupScopeParams) error {
@@ -118,6 +121,7 @@ func NewPlacementGroupScope(ctx context.Context, linodeClientConfig ClientConfig
118121
LinodeClient: linodeClient,
119122
LinodePlacementGroup: params.LinodePlacementGroup,
120123
PatchHelper: helper,
124+
Cluster: params.Cluster,
121125
}, nil
122126
}
123127

cloud/scope/vpc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323

24+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2425
"sigs.k8s.io/cluster-api/util/patch"
2526
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2627

@@ -36,12 +37,14 @@ type VPCScope struct {
3637
PatchHelper *patch.Helper
3738
LinodeClient LinodeClient
3839
LinodeVPC *infrav1alpha2.LinodeVPC
40+
Cluster *clusterv1.Cluster
3941
}
4042

4143
// VPCScopeParams defines the input parameters used to create a new Scope.
4244
type VPCScopeParams struct {
4345
Client K8sClient
4446
LinodeVPC *infrav1alpha2.LinodeVPC
47+
Cluster *clusterv1.Cluster
4548
}
4649

4750
func validateVPCScopeParams(params VPCScopeParams) error {
@@ -77,6 +80,7 @@ func NewVPCScope(ctx context.Context, linodeClientConfig ClientConfig, params VP
7780
LinodeClient: linodeClient,
7881
LinodeVPC: params.LinodeVPC,
7982
PatchHelper: helper,
83+
Cluster: params.Cluster,
8084
}, nil
8185
}
8286

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ require (
1313
github.com/go-logr/logr v1.4.2
1414
github.com/google/go-cmp v0.7.0
1515
github.com/google/uuid v1.6.0
16-
github.com/linode/linodego v1.48.0
17-
github.com/onsi/ginkgo/v2 v2.22.2
16+
github.com/linode/linodego v1.48.1
17+
github.com/onsi/ginkgo/v2 v2.23.0
1818
github.com/onsi/gomega v1.36.2
1919
github.com/stretchr/testify v1.10.0
2020
go.opentelemetry.io/contrib/exporters/autoexport v0.59.0
@@ -31,7 +31,7 @@ require (
3131
k8s.io/client-go v0.32.2
3232
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
3333
sigs.k8s.io/cluster-api v1.9.5
34-
sigs.k8s.io/controller-runtime v0.20.2
34+
sigs.k8s.io/controller-runtime v0.20.3
3535
)
3636

3737
require (
@@ -132,12 +132,12 @@ require (
132132
go.uber.org/ratelimit v0.2.0 // indirect
133133
go.uber.org/zap v1.27.0 // indirect
134134
golang.org/x/net v0.35.0 // indirect
135-
golang.org/x/oauth2 v0.26.0 // indirect
135+
golang.org/x/oauth2 v0.27.0 // indirect
136136
golang.org/x/sys v0.30.0 // indirect
137137
golang.org/x/term v0.29.0 // indirect
138138
golang.org/x/text v0.22.0 // indirect
139139
golang.org/x/time v0.7.0 // indirect
140-
golang.org/x/tools v0.28.0 // indirect
140+
golang.org/x/tools v0.30.0 // indirect
141141
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
142142
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
143143
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
177177
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
178178
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
179179
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
180-
github.com/linode/linodego v1.48.0 h1:Xn00rWYSpK5arNEFwymW58jpsdnK8axxhwS/9+cFkQ0=
181-
github.com/linode/linodego v1.48.0/go.mod h1:k/lRz48xUtGaeVYyvF2X2iNxMpt8JJ+DR4I77R8I1Vg=
180+
github.com/linode/linodego v1.48.1 h1:Ojw1S+K5jJr1dggO8/H6r4FINxXnJbOU5GkbpaTfmhU=
181+
github.com/linode/linodego v1.48.1/go.mod h1:fc3t60If8X+yZTFAebhCnNDFrhwQhq9HDU92WnBousQ=
182182
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
183183
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
184184
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
@@ -200,8 +200,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
200200
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
201201
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
202202
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
203-
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
204-
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
203+
github.com/onsi/ginkgo/v2 v2.23.0 h1:FA1xjp8ieYDzlgS5ABTpdUDB7wtngggONc8a7ku2NqQ=
204+
github.com/onsi/ginkgo/v2 v2.23.0/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM=
205205
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
206206
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
207207
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
@@ -347,8 +347,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
347347
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
348348
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
349349
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
350-
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
351-
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
350+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
351+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
352352
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
353353
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
354354
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -375,8 +375,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
375375
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
376376
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
377377
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
378-
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
379-
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
378+
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
379+
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
380380
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
381381
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
382382
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -433,8 +433,8 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 h1:CPT0ExVicCzcp
433433
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
434434
sigs.k8s.io/cluster-api v1.9.5 h1:68164Q201Y5ANVkhyrOZenoMbfL2SEBjVYZs/ihhSro=
435435
sigs.k8s.io/cluster-api v1.9.5/go.mod h1:DyqyZ4jRvKGKewDRn1Q4OCHaVjsdTogymbO6mrgHEDI=
436-
sigs.k8s.io/controller-runtime v0.20.2 h1:/439OZVxoEc02psi1h4QO3bHzTgu49bb347Xp4gW1pc=
437-
sigs.k8s.io/controller-runtime v0.20.2/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
436+
sigs.k8s.io/controller-runtime v0.20.3 h1:I6Ln8JfQjHH7JbtCD2HCYHoIzajoRxPNuvhvcDbZgkI=
437+
sigs.k8s.io/controller-runtime v0.20.3/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
438438
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
439439
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
440440
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA=

internal/controller/linodecluster_controller.go

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3131
"k8s.io/client-go/tools/record"
32+
"k8s.io/client-go/util/retry"
3233
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3334
kutil "sigs.k8s.io/cluster-api/util"
3435
conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
35-
"sigs.k8s.io/cluster-api/util/patch"
3636
"sigs.k8s.io/cluster-api/util/paused"
3737
"sigs.k8s.io/cluster-api/util/predicates"
3838
ctrl "sigs.k8s.io/controller-runtime"
@@ -115,57 +115,44 @@ func (r *LinodeClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
115115
return ctrl.Result{}, fmt.Errorf("failed to create cluster scope: %w", err)
116116
}
117117

118-
return r.reconcile(ctx, clusterScope, logger)
119-
}
120-
121-
func (r *LinodeClusterReconciler) reconcilePause(ctx context.Context, clusterScope *scope.ClusterScope, logger logr.Logger) error {
122-
// Pausing a cluster pauses the VPC as well.
123-
// First thing to do is handle a paused Cluster. Paused clusters shouldn't be deleted.
124-
isPaused, conditionChanged, err := paused.EnsurePausedCondition(ctx, clusterScope.Client, clusterScope.Cluster, clusterScope.LinodeCluster)
118+
isPaused, _, err := paused.EnsurePausedCondition(ctx, clusterScope.Client, clusterScope.Cluster, clusterScope.LinodeCluster)
125119
if err != nil {
126-
return err
120+
return ctrl.Result{}, err
127121
}
128-
if !(isPaused || conditionChanged) {
129-
return nil
122+
if isPaused {
123+
logger.Info("linodeCluster or linked cluster is marked as paused, won't reconcile.")
124+
return ctrl.Result{}, nil
130125
}
131126

132-
if clusterScope.LinodeCluster.Spec.VPCRef == nil {
133-
logger.Info("Paused reconciliation is skipped due to missing VPC ref")
127+
return r.reconcile(ctx, clusterScope, logger)
128+
}
129+
130+
func (r *LinodeClusterReconciler) reconcileVPCLabel(ctx context.Context, clusterScope *scope.ClusterScope, logger logr.Logger) error {
131+
if clusterScope.Cluster == nil || clusterScope.LinodeCluster.Spec.VPCRef == nil {
132+
logger.Info("label reconciliation is skipped due to missing VPC ref/Cluster ref")
134133
return nil
135134
}
136-
137135
linodeVPC := infrav1alpha2.LinodeVPC{
138136
ObjectMeta: metav1.ObjectMeta{
139137
Namespace: clusterScope.LinodeCluster.Spec.VPCRef.Namespace,
140138
Name: clusterScope.LinodeCluster.Spec.VPCRef.Name,
141139
},
142140
}
143-
144141
if err := clusterScope.Client.Get(ctx, client.ObjectKeyFromObject(&linodeVPC), &linodeVPC); err != nil {
145142
return err
146143
}
147-
148-
annotations := linodeVPC.ObjectMeta.GetAnnotations()
149-
if annotations == nil {
150-
annotations = map[string]string{}
151-
}
152-
153-
if isPaused {
154-
logger.Info("CAPI cluster is paused, pausing VPC")
155-
// if we're paused, we should slap the pause annotation on our children
156-
// get the vpc & add the annotation
157-
annotations[clusterv1.PausedAnnotation] = pauseAnnotationValue
158-
} else {
159-
// we are not paused here, but were previously paused (we can get here only if conditionChanged is true.
160-
logger.Info("CAPI cluster is no longer paused, removing pause annotation from VPC")
161-
delete(annotations, clusterv1.PausedAnnotation)
144+
labels := linodeVPC.ObjectMeta.GetLabels()
145+
if labels == nil {
146+
labels = map[string]string{}
162147
}
163-
linodeVPC.SetAnnotations(annotations)
164-
vpcPatchHelper, err := patch.NewHelper(&linodeVPC, clusterScope.Client)
165-
if err != nil {
166-
return fmt.Errorf("failed to build patch helper for linode VPC object: %w", err)
148+
if _, ok := labels[clusterv1.ClusterNameLabel]; ok {
149+
return nil
167150
}
168-
return vpcPatchHelper.Patch(ctx, &linodeVPC)
151+
labels[clusterv1.ClusterNameLabel] = clusterScope.Cluster.Name
152+
linodeVPC.SetLabels(labels)
153+
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
154+
return clusterScope.Client.Update(ctx, &linodeVPC)
155+
})
169156
}
170157

171158
//nolint:cyclop // can't make it simpler with existing API
@@ -189,9 +176,11 @@ func (r *LinodeClusterReconciler) reconcile(
189176
}()
190177

191178
labels := map[string]string{
192-
clusterv1.ClusterNameLabel: clusterScope.LinodeCluster.Name,
193179
clusterv1.MachineControlPlaneLabel: "",
194180
}
181+
if clusterScope.Cluster != nil {
182+
labels[clusterv1.ClusterNameLabel] = clusterScope.Cluster.Name
183+
}
195184
if err := r.TracedClient().List(ctx, &clusterScope.LinodeMachines, client.InNamespace(clusterScope.LinodeCluster.Namespace), client.MatchingLabels(labels)); err != nil {
196185
return res, err
197186
}
@@ -201,7 +190,7 @@ func (r *LinodeClusterReconciler) reconcile(
201190
return res, err
202191
}
203192

204-
if err := r.reconcilePause(ctx, clusterScope, logger); err != nil {
193+
if err := r.reconcileVPCLabel(ctx, clusterScope, logger); err != nil {
205194
return res, err
206195
}
207196

internal/controller/linodecluster_controller_test.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"go.uber.org/mock/gomock"
2626
corev1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/apimachinery/pkg/types"
2829
"k8s.io/utils/ptr"
2930
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3031
conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
@@ -61,6 +62,10 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
6162
Namespace: defaultNamespace,
6263
OwnerReferences: ownerRefs,
6364
}
65+
cluster := clusterv1.Cluster{
66+
ObjectMeta: metadata,
67+
Spec: clusterv1.ClusterSpec{},
68+
}
6469
linodeCluster := infrav1alpha2.LinodeCluster{
6570
ObjectMeta: metadata,
6671
Spec: infrav1alpha2.LinodeClusterSpec{
@@ -72,6 +77,9 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
7277
ObjectMeta: metav1.ObjectMeta{
7378
Name: "vpctest",
7479
Namespace: defaultNamespace,
80+
Labels: map[string]string{
81+
clusterv1.ClusterNameLabel: linodeCluster.ObjectMeta.Name,
82+
},
7583
},
7684
Spec: infrav1alpha2.LinodeVPCSpec{
7785
Region: "us-ord",
@@ -98,6 +106,7 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
98106
BeforeAll(func(ctx SpecContext) {
99107
cScope.Client = k8sClient
100108
Expect(k8sClient.Create(ctx, &linodeCluster)).To(Succeed())
109+
Expect(k8sClient.Create(ctx, &cluster)).To(Succeed())
101110
})
102111

103112
ctlrSuite.BeforeEach(func(ctx context.Context, mck Mock) {
@@ -181,7 +190,7 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
181190
cScope.LinodeClient = mck.LinodeClient
182191
// Set VPC as ready
183192
linodeVPC.Status.Ready = true
184-
k8sClient.Status().Update(ctx, &linodeVPC)
193+
Expect(k8sClient.Status().Update(ctx, &linodeVPC)).To(Succeed())
185194

186195
// Create and mark firewall as ready if using firewall ref
187196
if cScope.LinodeCluster.Spec.NodeBalancerFirewallRef != nil {
@@ -329,8 +338,7 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
329338
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
330339
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
331340
Expect(linodeCluster.Status.Ready).To(BeTrue())
332-
Expect(linodeCluster.Status.Conditions).To(HaveLen(4))
333-
Expect(conditions.Get(&linodeCluster, clusterv1.PausedV1Beta2Condition).Status).To(Equal(metav1.ConditionFalse))
341+
Expect(linodeCluster.Status.Conditions).To(HaveLen(3))
334342
Expect(conditions.Get(&linodeCluster, string(clusterv1.ReadyCondition)).Status).To(Equal(metav1.ConditionTrue))
335343
Expect(conditions.Get(&linodeCluster, ConditionPreflightLinodeNBFirewallReady)).NotTo(BeNil())
336344
Expect(conditions.Get(&linodeCluster, ConditionPreflightLinodeVPCReady)).NotTo(BeNil())
@@ -342,6 +350,29 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
342350
Expect(linodeCluster.Spec.ControlPlaneEndpoint.Port).To(Equal(int32(controlPlaneEndpointPort)))
343351
}),
344352
),
353+
Path(
354+
Call("cluster is paused", func(ctx context.Context, mck Mock) {
355+
cScope.LinodeClient = mck.LinodeClient
356+
cluster.Spec.Paused = true
357+
Expect(k8sClient.Update(ctx, &cluster)).To(Succeed())
358+
}),
359+
Result("cluster does nothing", func(ctx context.Context, mck Mock) {
360+
reconciler.Client = k8sClient
361+
_, err := reconciler.Reconcile(ctx, reconcile.Request{types.NamespacedName{Name: clusterName, Namespace: defaultNamespace}})
362+
Expect(err).NotTo(HaveOccurred())
363+
364+
By("checking paused conditions")
365+
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
366+
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
367+
Expect(linodeCluster.Status.Ready).To(BeTrue())
368+
Expect(linodeCluster.Status.Conditions).To(HaveLen(4))
369+
Expect(conditions.Get(&linodeCluster, string(clusterv1.PausedV1Beta2Condition)).Status).To(Equal(metav1.ConditionTrue))
370+
Expect(conditions.Get(&linodeCluster, string(clusterv1.ReadyCondition)).Status).To(Equal(metav1.ConditionTrue))
371+
Expect(conditions.Get(&linodeCluster, ConditionPreflightLinodeNBFirewallReady)).NotTo(BeNil())
372+
Expect(conditions.Get(&linodeCluster, ConditionPreflightLinodeVPCReady)).NotTo(BeNil())
373+
374+
}),
375+
),
345376
),
346377
)
347378
})
@@ -448,7 +479,7 @@ var _ = Describe("cluster-lifecycle-dns", Ordered, Label("cluster", "cluster-lif
448479
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
449480
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
450481
Expect(linodeCluster.Status.Ready).To(BeTrue())
451-
Expect(linodeCluster.Status.Conditions).To(HaveLen(2))
482+
Expect(linodeCluster.Status.Conditions).To(HaveLen(1))
452483
readyCond := conditions.Get(&linodeCluster, string(clusterv1.ReadyCondition))
453484
Expect(readyCond).NotTo(BeNil())
454485

@@ -722,7 +753,7 @@ var _ = Describe("dns-override-endpoint", Ordered, Label("cluster", "dns-overrid
722753
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
723754
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
724755
Expect(linodeCluster.Status.Ready).To(BeTrue())
725-
Expect(linodeCluster.Status.Conditions).To(HaveLen(2))
756+
Expect(linodeCluster.Status.Conditions).To(HaveLen(1))
726757
cond := conditions.Get(&linodeCluster, string(clusterv1.ReadyCondition))
727758
Expect(cond).NotTo(BeNil())
728759

0 commit comments

Comments
 (0)