Skip to content

Commit

Permalink
Merge pull request #1976 from MisterMX/fix/nodegroup-taints-update
Browse files Browse the repository at this point in the history
fix(eks): Update NodeGroup taints
  • Loading branch information
MisterMX authored Dec 18, 2023
2 parents 4ecbd4c + c3db3c3 commit 7134583
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
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

0 comments on commit 7134583

Please sign in to comment.