Skip to content

Commit f6d79e2

Browse files
committed
fix: we don't need to set eks specific labels
1 parent 4f4db0c commit f6d79e2

File tree

3 files changed

+10
-304
lines changed

3 files changed

+10
-304
lines changed

bootstrap/eks/controllers/nodeadmconfig_controller.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import (
2121
"sigs.k8s.io/controller-runtime/pkg/handler"
2222
"sigs.k8s.io/controller-runtime/pkg/source"
2323

24-
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2524
eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2"
2625
"sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/internal/userdata"
2726
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
28-
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
2927
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
3028
"sigs.k8s.io/cluster-api-provider-aws/v2/util/paused"
3129
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -213,7 +211,6 @@ func (r *NodeadmConfigReconciler) joinWorker(ctx context.Context, cluster *clust
213211
Files: files,
214212
ServiceCIDR: serviceCIDR,
215213
APIServerEndpoint: controlPlane.Spec.ControlPlaneEndpoint.Host,
216-
NodeGroupName: config.Name,
217214
}
218215
if config.Spec.Kubelet != nil {
219216
nodeInput.KubeletFlags = config.Spec.Kubelet.Flags
@@ -247,44 +244,6 @@ func (r *NodeadmConfigReconciler) joinWorker(ctx context.Context, cluster *clust
247244
}
248245
nodeInput.CACert = ca
249246

250-
// Get AMI ID and capacity type from owner resource
251-
switch configOwner.GetKind() {
252-
case "AWSManagedMachinePool":
253-
amp := &expinfrav1.AWSManagedMachinePool{}
254-
if err := r.Get(ctx, client.ObjectKey{Namespace: config.Namespace, Name: configOwner.GetName()}, amp); err == nil {
255-
log.Info("Found AWSManagedMachinePool", "name", amp.Name, "launchTemplate", amp.Spec.AWSLaunchTemplate != nil)
256-
if amp.Spec.AWSLaunchTemplate != nil && amp.Spec.AWSLaunchTemplate.AMI.ID != nil {
257-
nodeInput.AMIImageID = *amp.Spec.AWSLaunchTemplate.AMI.ID
258-
log.Info("Set AMI ID from AWSManagedMachinePool launch template", "amiID", nodeInput.AMIImageID)
259-
} else {
260-
log.Info("No AMI ID found in AWSManagedMachinePool launch template")
261-
}
262-
if amp.Spec.CapacityType != nil {
263-
nodeInput.CapacityType = amp.Spec.CapacityType
264-
log.Info("Set capacity type from AWSManagedMachinePool", "capacityType", *amp.Spec.CapacityType)
265-
} else {
266-
log.Info("No capacity type found in AWSManagedMachinePool")
267-
}
268-
} else {
269-
log.Info("Failed to get AWSManagedMachinePool", "error", err)
270-
}
271-
case "AWSMachineTemplate":
272-
awsmt := &infrav1.AWSMachineTemplate{}
273-
var awsMTGetErr error
274-
if awsMTGetErr = r.Get(ctx, client.ObjectKey{Namespace: config.Namespace, Name: configOwner.GetName()}, awsmt); awsMTGetErr == nil {
275-
log.Info("Found AWSMachineTemplate", "name", awsmt.Name)
276-
if awsmt.Spec.Template.Spec.AMI.ID != nil {
277-
nodeInput.AMIImageID = *awsmt.Spec.Template.Spec.AMI.ID
278-
log.Info("Set AMI ID from AWSMachineTemplate", "amiID", nodeInput.AMIImageID)
279-
} else {
280-
log.Info("No AMI ID found in AWSMachineTemplate")
281-
}
282-
}
283-
log.Info("Failed to get AWSMachineTemplate", "error", awsMTGetErr)
284-
default:
285-
log.Info("Config owner kind not recognized for AMI extraction", "kind", configOwner.GetKind())
286-
}
287-
288247
log.Info("Generating nodeadm userdata",
289248
"cluster", controlPlane.Spec.EKSClusterName,
290249
"endpoint", nodeInput.APIServerEndpoint)

bootstrap/eks/internal/userdata/nodeadm.go

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ package userdata
1919
import (
2020
"bytes"
2121
"fmt"
22-
"strings"
2322
"text/template"
2423

2524
"k8s.io/apimachinery/pkg/runtime"
2625
"k8s.io/klog/v2"
2726

2827
eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2"
29-
"sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
3028
)
3129

3230
const (
@@ -95,14 +93,16 @@ spec:
9593
{{$k}}: {{$v}}
9694
{{- end }}
9795
{{- end }}
96+
{{- if .KubeletConfig }}
9897
kubelet:
99-
{{- if .KubeletConfig }}
10098
config:
10199
{{ Indent 6 (toYaml .KubeletConfig) }}
102100
{{- end }}
101+
{{- if .KubeletFlags }}
103102
flags:
104-
{{- range $flag := .KubeletFlags }}
105-
- "{{$flag}}"
103+
{{- range $flag := .KubeletFlags }}
104+
- "{{$flag}}"
105+
{{- end }}
106106
{{- end }}
107107
{{- if or .ContainerdConfig .ContainerdBaseRuntimeSpec }}
108108
containerd:
@@ -133,10 +133,6 @@ spec:
133133
{{- end }}
134134
135135
--{{.Boundary}}`
136-
137-
nodeLabelImage = "eks.amazonaws.com/nodegroup-image"
138-
nodeLabelNodeGroup = "eks.amazonaws.com/nodegroup"
139-
nodeLabelCapacityType = "eks.amazonaws.com/capacityType"
140136
)
141137

142138
// NodeadmInput contains all the information required to generate user data for a node.
@@ -160,68 +156,8 @@ type NodeadmInput struct {
160156
APIServerEndpoint string
161157
Boundary string
162158
CACert string
163-
CapacityType *v1beta2.ManagedMachinePoolCapacityType
164159
ServiceCIDR string // Service CIDR range for the cluster
165160
ClusterDNS string
166-
NodeGroupName string
167-
NodeLabels string // Not exposed in CRD, computed from user input
168-
}
169-
170-
func (input *NodeadmInput) setKubeletFlags() error {
171-
var nodeLabels string
172-
newFlags := []string{}
173-
for _, flag := range input.KubeletFlags {
174-
if strings.HasPrefix(flag, "--node-labels=") {
175-
nodeLabels = strings.TrimPrefix(flag, "--node-labels=")
176-
} else {
177-
newFlags = append(newFlags, flag)
178-
}
179-
}
180-
labelsMap := make(map[string]string)
181-
if nodeLabels != "" {
182-
labels := strings.Split(nodeLabels, ",")
183-
for _, label := range labels {
184-
labelSplit := strings.Split(label, "=")
185-
if len(labelSplit) != 2 {
186-
return fmt.Errorf("invalid label: %s", label)
187-
}
188-
labelKey := labelSplit[0]
189-
labelValue := labelSplit[1]
190-
labelsMap[labelKey] = labelValue
191-
}
192-
}
193-
if _, ok := labelsMap[nodeLabelImage]; !ok && input.AMIImageID != "" {
194-
labelsMap[nodeLabelImage] = input.AMIImageID
195-
}
196-
if _, ok := labelsMap[nodeLabelNodeGroup]; !ok && input.NodeGroupName != "" {
197-
labelsMap[nodeLabelNodeGroup] = input.NodeGroupName
198-
}
199-
if _, ok := labelsMap[nodeLabelCapacityType]; !ok {
200-
labelsMap[nodeLabelCapacityType] = input.getCapacityTypeString()
201-
}
202-
stringBuilder := strings.Builder{}
203-
for key, value := range labelsMap {
204-
stringBuilder.WriteString(fmt.Sprintf("%s=%s,", key, value))
205-
}
206-
newLabels := stringBuilder.String()[:len(stringBuilder.String())-1] // remove the last comma
207-
newFlags = append(newFlags, fmt.Sprintf("--node-labels=%s", newLabels))
208-
input.KubeletFlags = newFlags
209-
return nil
210-
}
211-
212-
// getCapacityTypeString returns the string representation of the capacity type.
213-
func (input *NodeadmInput) getCapacityTypeString() string {
214-
if input.CapacityType == nil {
215-
return "ON_DEMAND"
216-
}
217-
switch *input.CapacityType {
218-
case v1beta2.ManagedMachinePoolCapacityTypeSpot:
219-
return "SPOT"
220-
case v1beta2.ManagedMachinePoolCapacityTypeOnDemand:
221-
return "ON_DEMAND"
222-
default:
223-
return strings.ToUpper(string(*input.CapacityType))
224-
}
225161
}
226162

227163
// validateNodeInput validates the input for nodeadm user data generation.
@@ -235,18 +171,11 @@ func validateNodeadmInput(input *NodeadmInput) error {
235171
if input.ClusterName == "" {
236172
return fmt.Errorf("cluster name is required for nodeadm")
237173
}
238-
if input.NodeGroupName == "" {
239-
return fmt.Errorf("node group name is required for nodeadm")
240-
}
241174
if input.Boundary == "" {
242175
input.Boundary = boundary
243176
}
244-
err := input.setKubeletFlags()
245-
if err != nil {
246-
return err
247-
}
248177

249-
klog.V(2).Infof("Nodeadm Userdata Generation - node-labels: %s", input.NodeLabels)
178+
klog.V(2).Infof("Nodeadm Userdata Generation %v", input)
250179

251180
return nil
252181
}

0 commit comments

Comments
 (0)