From f28522f99126b98991124dcafc0d2c03d7a22e5a Mon Sep 17 00:00:00 2001 From: Vacant2333 Date: Tue, 10 Dec 2024 14:35:27 +0800 Subject: [PATCH] fix: re-reconcile the nodeclass status (#7305) Signed-off-by: Vacant2333 --- pkg/controllers/nodeclass/status/ami.go | 4 +++- pkg/controllers/nodeclass/status/securitygroup.go | 4 +++- pkg/controllers/nodeclass/status/subnet.go | 4 +++- pkg/providers/amifamily/ami.go | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/controllers/nodeclass/status/ami.go b/pkg/controllers/nodeclass/status/ami.go index 52debaba9b75..a6f9974880be 100644 --- a/pkg/controllers/nodeclass/status/ami.go +++ b/pkg/controllers/nodeclass/status/ami.go @@ -42,7 +42,9 @@ func (a *AMI) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (reconc if len(amis) == 0 { nodeClass.Status.AMIs = nil nodeClass.StatusConditions().SetFalse(v1.ConditionTypeAMIsReady, "AMINotFound", "AMISelector did not match any AMIs") - return reconcile.Result{}, nil + // If users have omitted the necessary tags from their AMIs and later add them, we need to reprocess the information. + // Returning 'ok' in this case means that the nodeclass will remain in an unready state until the component is restarted. + return reconcile.Result{RequeueAfter: time.Minute}, nil } nodeClass.Status.AMIs = lo.Map(amis, func(ami amifamily.AMI, _ int) v1.AMI { reqs := lo.Map(ami.Requirements.NodeSelectorRequirements(), func(item karpv1.NodeSelectorRequirementWithMinValues, _ int) corev1.NodeSelectorRequirement { diff --git a/pkg/controllers/nodeclass/status/securitygroup.go b/pkg/controllers/nodeclass/status/securitygroup.go index b3a8756da895..5e0a21af0b29 100644 --- a/pkg/controllers/nodeclass/status/securitygroup.go +++ b/pkg/controllers/nodeclass/status/securitygroup.go @@ -40,7 +40,9 @@ func (sg *SecurityGroup) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeCla if len(securityGroups) == 0 && len(nodeClass.Spec.SecurityGroupSelectorTerms) > 0 { nodeClass.Status.SecurityGroups = nil nodeClass.StatusConditions().SetFalse(v1.ConditionTypeSecurityGroupsReady, "SecurityGroupsNotFound", "SecurityGroupSelector did not match any SecurityGroups") - return reconcile.Result{}, nil + // If users have omitted the necessary tags from their SecurityGroups and later add them, we need to reprocess the information. + // Returning 'ok' in this case means that the nodeclass will remain in an unready state until the component is restarted. + return reconcile.Result{RequeueAfter: time.Minute}, nil } sort.Slice(securityGroups, func(i, j int) bool { return *securityGroups[i].GroupId < *securityGroups[j].GroupId diff --git a/pkg/controllers/nodeclass/status/subnet.go b/pkg/controllers/nodeclass/status/subnet.go index 0e775022575e..7c64ba1be264 100644 --- a/pkg/controllers/nodeclass/status/subnet.go +++ b/pkg/controllers/nodeclass/status/subnet.go @@ -40,7 +40,9 @@ func (s *Subnet) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (rec if len(subnets) == 0 { nodeClass.Status.Subnets = nil nodeClass.StatusConditions().SetFalse(v1.ConditionTypeSubnetsReady, "SubnetsNotFound", "SubnetSelector did not match any Subnets") - return reconcile.Result{}, nil + // If users have omitted the necessary tags from their Subnets and later add them, we need to reprocess the information. + // Returning 'ok' in this case means that the nodeclass will remain in an unready state until the component is restarted. + return reconcile.Result{RequeueAfter: time.Minute}, nil } sort.Slice(subnets, func(i, j int) bool { if int(*subnets[i].AvailableIpAddressCount) != int(*subnets[j].AvailableIpAddressCount) { diff --git a/pkg/providers/amifamily/ami.go b/pkg/providers/amifamily/ami.go index 1e06bd85547f..ee6fdfc7257d 100644 --- a/pkg/providers/amifamily/ami.go +++ b/pkg/providers/amifamily/ami.go @@ -65,7 +65,7 @@ func NewDefaultProvider(clk clock.Clock, versionProvider version.Provider, ssmPr } } -// Get Returning a list of AMIs with its associated requirements +// List Returning a list of AMIs with its associated requirements func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass) (AMIs, error) { p.Lock() defer p.Unlock()