Skip to content

fix: Fix EC2NodeClass readiness to not stuck in False #7970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/controllers/nodeclass/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (n Readiness) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (r
nodeClass.StatusConditions().SetFalse(status.ConditionReady, "NodeClassNotReady", "Failed to detect the cluster CIDR")
return reconcile.Result{}, fmt.Errorf("failed to detect the cluster CIDR, %w", err)
}
// Ensure the ready condition is set to true once the cluster CIDR is resolved,
// to not stuck in Failed state indefinitely.
nodeClass.StatusConditions().SetTrue(status.ConditionReady)
}
return reconcile.Result{}, nil
}
35 changes: 35 additions & 0 deletions pkg/controllers/nodeclass/readiness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ limitations under the License.
package nodeclass_test

import (
"fmt"

"github.com/awslabs/operatorpkg/status"
"github.com/samber/lo"
coreoptions "sigs.k8s.io/karpenter/pkg/operator/options"

"github.com/aws/aws-sdk-go-v2/service/eks"
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
"github.com/aws/karpenter-provider-aws/pkg/test"

Expand Down Expand Up @@ -76,4 +80,35 @@ var _ = Describe("NodeClass Status Condition Controller", func() {
Expect(nodeClass.StatusConditions().Get(status.ConditionReady).IsFalse()).To(BeTrue())
Expect(nodeClass.StatusConditions().Get(status.ConditionReady).Message).To(Equal("ValidationSucceeded=False, SecurityGroupsReady=False"))
})
It("should recover from temporary DescribeCluster failure", func() {
// First reconcile with API error
awsEnv.EKSAPI.DescribeClusterBehavior.Error.Set(fmt.Errorf("temporary AWS API error"))

nodeClass.Spec.AMIFamily = lo.ToPtr(v1.AMIFamilyAL2023)

ExpectApplied(ctx, env.Client, nodeClass)

ExpectObjectReconcileFailed(ctx, env.Client, controller, nodeClass)
nodeClass = ExpectExists(ctx, env.Client, nodeClass)

Expect(nodeClass.StatusConditions().Get(status.ConditionReady).IsFalse()).To(BeTrue())
Expect(nodeClass.StatusConditions().Get(status.ConditionReady).Message).To(ContainSubstring("Failed to detect the cluster CIDR"))

// Clear the error and reconcile again
awsEnv.EKSAPI.DescribeClusterBehavior.Error.Set(nil)
awsEnv.EKSAPI.DescribeClusterBehavior.Output.Set(&eks.DescribeClusterOutput{
Cluster: &ekstypes.Cluster{
Version: lo.ToPtr("1.29"),
KubernetesNetworkConfig: &ekstypes.KubernetesNetworkConfigResponse{
ServiceIpv4Cidr: lo.ToPtr("10.100.0.0/16"),
},
},
})

ExpectObjectReconciled(ctx, env.Client, controller, nodeClass)
nodeClass = ExpectExists(ctx, env.Client, nodeClass)

// Verify conditions are now ready
Expect(nodeClass.StatusConditions().Get(status.ConditionReady).IsTrue()).To(BeTrue())
})
})