Skip to content

Commit

Permalink
return set of issues when ng is in degraded state
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanSpectro committed Feb 22, 2024
1 parent 8b4231d commit df11df2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
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 @@ -588,6 +591,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
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
48 changes: 48 additions & 0 deletions pkg/cloud/services/eks/nodegroup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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"

Check failure on line 18 in pkg/cloud/services/eks/nodegroup_test.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var resourceId should be resourceID (revive)

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(Equal(false))

Check failure on line 46 in pkg/cloud/services/eks/nodegroup_test.go

View workflow job for this annotation

GitHub Actions / lint

ginkgo-linter: wrong boolean assertion; consider using `g.Expect(s.scope.ManagedMachinePool.Status.Ready).To(BeFalse())` instead (ginkgolinter)
g.Expect(*s.scope.ManagedMachinePool.Status.FailureReason).To(Equal(capierrors.InsufficientResourcesMachineError))
}

0 comments on commit df11df2

Please sign in to comment.