Skip to content

Commit 7680909

Browse files
committed
fix: run placement group discovery
1 parent 6db7a44 commit 7680909

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

pkg/handlers/aws/mutation/placementgroupnfd/embedded/placementgroup_discovery.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -euo pipefail
44
# This script is used to discover the placement group for the node.
55
# The script will be placed in /etc/kubernetes/node-feature-discovery/source.d/
66
# The script will be executed by the node feature discovery's local feature hook.
7-
8-
7+
PLACEMENT_GROUP_FEATURE_DIR="/etc/kubernetes/node-feature-discovery/features.d"
8+
PLACEMENT_GROUP_FEATURE_FILE="${PLACEMENT_GROUP_FEATURE_DIR}/placementgroup"
99
# Fetch IMDSv2 token
1010
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" \
1111
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
@@ -21,14 +21,17 @@ PG_RESPONSE=$(curl -s -w "%{http_code}" -H "X-aws-ec2-metadata-token: $TOKEN" \
2121
PARTITION_HTTP_CODE="${PARTITION_RESPONSE: -3}" # last 3 characters are the HTTP status code
2222
PARTITION_CONTENT="${PARTITION_RESPONSE%???}" # remove the last 3 characters to get the content
2323

24+
mkdir -p "${PLACEMENT_GROUP_FEATURE_DIR}"
25+
touch "${PLACEMENT_GROUP_FEATURE_FILE}"
26+
2427
# Only print features if HTTP 200 response
2528
if [ "$PARTITION_HTTP_CODE" = "200" ] && [ -n "$PARTITION_CONTENT" ]; then
26-
echo "feature.node.kubernetes.io/partition=${PARTITION_CONTENT}"
29+
echo "feature.node.kubernetes.io/partition=${PARTITION_CONTENT}" >> "${PLACEMENT_GROUP_FEATURE_FILE}"
2730
fi
2831

2932
PG_HTTP_CODE="${PG_RESPONSE: -3}" # last 3 characters are the HTTP status code
3033
PG_CONTENT="${PG_RESPONSE%???}" # remove the last 3 characters to get the content
3134

3235
if [ "$PG_HTTP_CODE" = "200" ] && [ -n "$PG_CONTENT" ]; then
33-
echo "feature.node.kubernetes.io/aws-placement-group=${PG_CONTENT}"
36+
echo "feature.node.kubernetes.io/aws-placement-group=${PG_CONTENT}" >> "${PLACEMENT_GROUP_FEATURE_FILE}"
3437
fi

pkg/handlers/aws/mutation/placementgroupnfd/inject_controlplane.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,18 @@ func (h *controlPlanePatchHandler) Mutate(
7979
"patchedObjectKind", obj.GetObjectKind().GroupVersionKind().String(),
8080
"patchedObjectName", client.ObjectKeyFromObject(obj),
8181
).Info("setting placement group for local node feature discovery in AWS controlplane KubeadmControlPlaneTemplate")
82-
obj.Spec.Template.Spec.KubeadmConfigSpec.Files = append(obj.Spec.Template.Spec.KubeadmConfigSpec.Files, cabpkv1.File{
83-
Path: PlacementGroupDiscoveryScriptFileOnRemote,
84-
Content: string(PlacementgroupDiscoveryScript),
85-
Permissions: "0700",
86-
})
82+
obj.Spec.Template.Spec.KubeadmConfigSpec.Files = append(
83+
obj.Spec.Template.Spec.KubeadmConfigSpec.Files,
84+
cabpkv1.File{
85+
Path: PlacementGroupDiscoveryScriptFileOnRemote,
86+
Content: string(PlacementgroupDiscoveryScript),
87+
Permissions: "0700",
88+
},
89+
)
90+
obj.Spec.Template.Spec.KubeadmConfigSpec.PreKubeadmCommands = append(
91+
obj.Spec.Template.Spec.KubeadmConfigSpec.PreKubeadmCommands,
92+
PlacementGroupDiscoveryScriptFileOnRemote,
93+
)
8794
return nil
8895
},
8996
)

pkg/handlers/aws/mutation/placementgroupnfd/inject_worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func (h *workerPatchHandler) Mutate(
8282
Content: string(PlacementgroupDiscoveryScript),
8383
Permissions: "0700",
8484
})
85+
obj.Spec.Template.Spec.PreKubeadmCommands = append(
86+
obj.Spec.Template.Spec.PreKubeadmCommands,
87+
PlacementGroupDiscoveryScriptFileOnRemote,
88+
)
8589
return nil
8690
},
8791
)

pkg/handlers/eks/mutation/placementgroupnfd/inject_worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func (h *workerPatchHandler) Mutate(
8383
Content: string(awsplacementgroupnfd.PlacementgroupDiscoveryScript),
8484
Permissions: "0700",
8585
})
86+
obj.Spec.Template.Spec.PreNodeadmCommands = append(
87+
obj.Spec.Template.Spec.PreNodeadmCommands,
88+
awsplacementgroupnfd.PlacementGroupDiscoveryScriptFileOnRemote,
89+
)
8690
return nil
8791
},
8892
)

0 commit comments

Comments
 (0)