Skip to content
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

fix(eks): Update NodeGroup taints #1976

Merged
Merged
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
51 changes: 50 additions & 1 deletion pkg/clients/eks/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,55 @@ func GenerateUpdateNodeGroupConfigInput(name string, p *manualv1alpha1.NodeGroup
MaxUnavailablePercentage: p.UpdateConfig.MaxUnavailablePercentage,
}
}
// TODO(muvaf): Add support for updating taints.

if p.Taints != nil {
u.Taints = generateUpdateTaintsPayload(p.Taints, ng.Taints)
}
return u
}

func generateUpdateTaintsPayload(spec []manualv1alpha1.Taint, current []ekstypes.Taint) *ekstypes.UpdateTaintsPayload {
res := &ekstypes.UpdateTaintsPayload{}

curMap := map[string]manualv1alpha1.Taint{}
for _, t := range current {
if t.Key == nil {
continue
}
curMap[*t.Key] = manualv1alpha1.Taint{
Effect: string(t.Effect),
Key: t.Key,
Value: t.Value,
}
}

specMap := map[string]any{}
for _, st := range spec {
if st.Key == nil {
continue
}
specMap[*st.Key] = nil

ct, exists := curMap[*st.Key]
if !exists || !cmp.Equal(st, ct) {
res.AddOrUpdateTaints = append(res.AddOrUpdateTaints, ekstypes.Taint{
Effect: ekstypes.TaintEffect(st.Effect),
Key: st.Key,
Value: st.Value,
})
}
}
for _, ct := range current {
if ct.Key == nil {
continue
}
if _, exists := specMap[*ct.Key]; !exists {
res.RemoveTaints = append(res.RemoveTaints, ct)
}
}
return res
}

// GenerateNodeGroupObservation is used to produce manualv1alpha1.NodeGroupObservation
// from eks.Nodegroup.
func GenerateNodeGroupObservation(ng *ekstypes.Nodegroup) manualv1alpha1.NodeGroupObservation { //nolint:gocyclo
Expand Down Expand Up @@ -351,6 +396,10 @@ func IsNodeGroupUpToDate(p *manualv1alpha1.NodeGroupParameters, ng *ekstypes.Nod
}
return true
}
taints := generateUpdateTaintsPayload(p.Taints, ng.Taints)
if len(taints.AddOrUpdateTaints) > 0 || len(taints.RemoveTaints) > 0 {
return false
}
return false
}

Expand Down
72 changes: 72 additions & 0 deletions pkg/clients/eks/nodegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

"github.com/crossplane-contrib/provider-aws/apis/eks/manualv1alpha1"
"github.com/crossplane-contrib/provider-aws/pkg/utils/pointer"
Expand Down Expand Up @@ -643,6 +644,77 @@ func TestGenerateUpdateNodeGroupInput(t *testing.T) {
},
},
},
"DiffTaints": {
args: args{
name: ngName,
p: &manualv1alpha1.NodeGroupParameters{
ClusterName: clusterName,
Taints: []manualv1alpha1.Taint{
{
Effect: "effect",
Key: ptr.To("toAdd"),
Value: ptr.To("value"),
},
{
Effect: "effect",
Key: ptr.To("toChange"),
Value: ptr.To("newValue"),
},
{
Effect: "effect",
Key: ptr.To("toKeep"),
Value: ptr.To("value"),
},
},
},
n: &ekstypes.Nodegroup{
NodegroupName: &ngName,
ClusterName: &clusterName,
Taints: []ekstypes.Taint{
{
Effect: "effect",
Key: ptr.To("toKeep"),
Value: ptr.To("value"),
},
{
Effect: "effect",
Key: ptr.To("toRemove"),
Value: ptr.To("value"),
},
{
Effect: "effect",
Key: ptr.To("toChange"),
Value: ptr.To("oldValue"),
},
},
},
},
want: &eks.UpdateNodegroupConfigInput{
NodegroupName: &ngName,
ClusterName: &clusterName,
Taints: &ekstypes.UpdateTaintsPayload{
AddOrUpdateTaints: []ekstypes.Taint{
{
Effect: "effect",
Key: ptr.To("toAdd"),
Value: ptr.To("value"),
},
{
Effect: "effect",
Key: ptr.To("toChange"),
Value: ptr.To("newValue"),
},
},
RemoveTaints: []ekstypes.Taint{
{
Effect: "effect",
Key: ptr.To("toRemove"),
Value: ptr.To("value"),
},
},
},
},
},
}

for name, tc := range cases {
Expand Down
Loading