Skip to content
Closed
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
26 changes: 26 additions & 0 deletions pkg/cloud/services/eks/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package eks
import (
"context"
"fmt"
"slices"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
Expand All @@ -37,6 +39,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/wait"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/record"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/util/annotations"
)

Expand Down Expand Up @@ -592,6 +595,29 @@ func (s *NodegroupService) setStatus(ng *eks.Nodegroup) error {
managedPool.Status.Ready = false
case eks.NodegroupStatusUpdating:
managedPool.Status.Ready = true
case eks.NodegroupStatusDegraded:
issueErrMsgSet := make([]string, 0)
var errMsgStr string

for _, iss := range ng.Health.Issues {
errMsg := iss.GoString()
if slices.Contains(issueErrMsgSet, errMsg) {
continue
}
issueErrMsgSet = append(issueErrMsgSet, errMsg)
errMsgStr = fmt.Sprintf("%s %s", errMsgStr, errMsg)
}
reason := capierrors.InvalidConfigurationMachineError
// TODO: implement checks for other MachineStatusErrors and set reason accordingly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to add this TODO as part of this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ankitasw I was going to leave this TODO as this PR is implementing returning of the error set.

if strings.Contains(errMsgStr, "VcpuLimitExceeded") {
reason = capierrors.InsufficientResourcesMachineError
}

managedPool.Status.Ready = false
managedPool.Status.FailureReason = &reason
managedPool.Status.FailureMessage = &errMsgStr
return errors.Errorf("NodeGroup status is %s due to %v caused by error %s. This error may persist and recreating the Node Group may be required to return to %s status",
eks.NodegroupStatusDegraded, *s.scope.ManagedMachinePool.Status.FailureReason, *s.scope.ManagedMachinePool.Status.FailureMessage, eks.NodegroupStatusActive)
default:
return errors.Errorf("unexpected EKS nodegroup status %s", *ng.Status)
}
Expand Down
65 changes: 65 additions & 0 deletions pkg/cloud/services/eks/nodegroup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2020 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package eks

import (
"testing"

"github.com/aws/aws-sdk-go/service/eks"
. "github.com/onsi/gomega"

"sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
capierrors "sigs.k8s.io/cluster-api/errors"
)

func TestSetStatus(t *testing.T) {
g := NewWithT(t)
degraded := eks.NodegroupStatusDegraded
code := eks.NodegroupIssueCodeAsgInstanceLaunchFailures
message := "VcpuLimitExceeded"
resourceID := "my-worker-nodes"

s := &NodegroupService{
scope: &scope.ManagedMachinePoolScope{
ManagedMachinePool: &v1beta2.AWSManagedMachinePool{
Status: v1beta2.AWSManagedMachinePoolStatus{
Ready: false,
},
},
},
}

issue := &eks.Issue{
Code: &code,
Message: &message,
ResourceIds: []*string{&resourceID},
}
ng := &eks.Nodegroup{
Status: &degraded,
Health: &eks.NodegroupHealth{
Issues: []*eks.Issue{issue},
},
}

err := s.setStatus(ng)
g.Expect(err).ToNot(BeNil())
// ensure machine pool status values are set as expected
g.Expect(*s.scope.ManagedMachinePool.Status.FailureMessage).To(ContainSubstring(issue.GoString()))
g.Expect(s.scope.ManagedMachinePool.Status.Ready).To(BeFalse())
g.Expect(*s.scope.ManagedMachinePool.Status.FailureReason).To(Equal(capierrors.InsufficientResourcesMachineError))
}
Loading