Skip to content

Commit

Permalink
[fix] remove ConditionLoadBalancing condition (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
amold1 authored Aug 27, 2024
1 parent 691cbb8 commit 7ae3df4
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 29 deletions.
12 changes: 4 additions & 8 deletions controller/linodecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ import (
"github.com/linode/cluster-api-provider-linode/util/reconciler"
)

const (
ConditionLoadBalancing clusterv1.ConditionType = "ConditionLoadBalancing"
)
const lbTypeDNS string = "dns"

// LinodeClusterReconciler reconciles a LinodeCluster object
type LinodeClusterReconciler struct {
Expand Down Expand Up @@ -184,7 +182,6 @@ func (r *LinodeClusterReconciler) reconcile(
logger.Error(err, "Failed to add Linode machine to loadbalancer option")
return retryIfTransient(err)
}
conditions.MarkTrue(clusterScope.LinodeCluster, ConditionLoadBalancing)

return res, nil
}
Expand All @@ -206,7 +203,7 @@ func (r *LinodeClusterReconciler) reconcileCreate(ctx context.Context, logger lo
}

// handle creation for the loadbalancer for the control plane
if clusterScope.LinodeCluster.Spec.Network.LoadBalancerType == "dns" {
if clusterScope.LinodeCluster.Spec.Network.LoadBalancerType == lbTypeDNS {
handleDNS(clusterScope)
} else {
if err := handleNBCreate(ctx, logger, clusterScope); err != nil {
Expand All @@ -219,7 +216,7 @@ func (r *LinodeClusterReconciler) reconcileCreate(ctx context.Context, logger lo

func (r *LinodeClusterReconciler) reconcileDelete(ctx context.Context, logger logr.Logger, clusterScope *scope.ClusterScope) error {
logger.Info("deleting cluster")
if clusterScope.LinodeCluster.Spec.Network.NodeBalancerID == nil && !reconciler.ConditionTrue(clusterScope.LinodeCluster, ConditionLoadBalancing) {
if clusterScope.LinodeCluster.Spec.Network.NodeBalancerID == nil && clusterScope.LinodeCluster.Spec.Network.LoadBalancerType != lbTypeDNS {
logger.Info("NodeBalancer ID is missing, nothing to do")

if err := clusterScope.RemoveCredentialsRefFinalizer(ctx); err != nil {
Expand All @@ -236,9 +233,8 @@ func (r *LinodeClusterReconciler) reconcileDelete(ctx context.Context, logger lo
if err := removeMachineFromLB(ctx, logger, clusterScope); err != nil {
return fmt.Errorf("remove machine from loadbalancer: %w", err)
}
conditions.MarkFalse(clusterScope.LinodeCluster, ConditionLoadBalancing, "cleared loadbalancer", clusterv1.ConditionSeverityInfo, "")

if clusterScope.LinodeCluster.Spec.Network.LoadBalancerType != "dns" && clusterScope.LinodeCluster.Spec.Network.NodeBalancerID != nil {
if clusterScope.LinodeCluster.Spec.Network.LoadBalancerType != lbTypeDNS && clusterScope.LinodeCluster.Spec.Network.NodeBalancerID != nil {
err := clusterScope.LinodeClient.DeleteNodeBalancer(ctx, *clusterScope.LinodeCluster.Spec.Network.NodeBalancerID)
if util.IgnoreLinodeAPIError(err, http.StatusNotFound) != nil {
logger.Error(err, "failed to delete NodeBalancer")
Expand Down
6 changes: 3 additions & 3 deletions controller/linodecluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ var _ = Describe("cluster-lifecycle", Ordered, Label("cluster", "cluster-lifecyc
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
Expect(linodeCluster.Status.Ready).To(BeTrue())
Expect(linodeCluster.Status.Conditions).To(HaveLen(2))
Expect(linodeCluster.Status.Conditions).To(HaveLen(1))
Expect(linodeCluster.Status.Conditions[0].Type).To(Equal(clusterv1.ReadyCondition))

By("checking NB id")
Expand Down Expand Up @@ -321,7 +321,7 @@ var _ = Describe("cluster-lifecycle-dns", Ordered, Label("cluster", "cluster-lif
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
Expect(linodeCluster.Status.Ready).To(BeTrue())
Expect(linodeCluster.Status.Conditions).To(HaveLen(2))
Expect(linodeCluster.Status.Conditions).To(HaveLen(1))
Expect(linodeCluster.Status.Conditions[0].Type).To(Equal(clusterv1.ReadyCondition))

By("checking controlPlaneEndpoint/NB host and port")
Expand Down Expand Up @@ -527,7 +527,7 @@ var _ = Describe("dns-override-endpoint", Ordered, Label("cluster", "dns-overrid
clusterKey := client.ObjectKeyFromObject(&linodeCluster)
Expect(k8sClient.Get(ctx, clusterKey, &linodeCluster)).To(Succeed())
Expect(linodeCluster.Status.Ready).To(BeTrue())
Expect(linodeCluster.Status.Conditions).To(HaveLen(2))
Expect(linodeCluster.Status.Conditions).To(HaveLen(1))
Expect(linodeCluster.Status.Conditions[0].Type).To(Equal(clusterv1.ReadyCondition))

By("checking controlPlaneEndpoint/NB host and port")
Expand Down
3 changes: 0 additions & 3 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ func (r *LinodeMachineReconciler) reconcileDelete(
conditions.MarkFalse(machineScope.LinodeMachine, clusterv1.ReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "instance deleted")

r.Recorder.Event(machineScope.LinodeMachine, corev1.EventTypeNormal, clusterv1.DeletedReason, "instance has cleaned up")
if reconciler.ConditionTrue(machineScope.LinodeCluster, ConditionLoadBalancing) {
return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerRetryDelay}, nil
}

machineScope.LinodeMachine.Spec.ProviderID = nil
machineScope.LinodeMachine.Status.InstanceState = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ spec:
results: 1
- name: Delete Cluster resource
try:
- delete:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: LinodeCluster
name: ($cluster)
- delete:
ref:
apiVersion: cluster.x-k8s.io/v1beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ spec:
results: 1
- name: Delete Cluster resource
try:
- delete:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: LinodeCluster
name: ($cluster)
- delete:
ref:
apiVersion: cluster.x-k8s.io/v1beta1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ spec:
- active: true
- name: Delete the Cluster & LinodeVPC resource
try:
- delete:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: LinodeCluster
name: ($cluster)
- delete:
ref:
apiVersion: cluster.x-k8s.io/v1beta1
Expand Down

0 comments on commit 7ae3df4

Please sign in to comment.