Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3613 from openshift-cherrypick-robot/cherry-pick-…
…3610-to-release-4.12

[release-4.12] OCPBUGS-10372: Remove hard requirement for the afterburn from early-running aws-related services
  • Loading branch information
openshift-merge-robot committed Mar 16, 2023
2 parents 731341b + 7c35afd commit e7a5af3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
18 changes: 15 additions & 3 deletions templates/common/aws/files/usr-local-bin-aws-kubelet-nodename.yaml
Expand Up @@ -11,12 +11,24 @@ contents:
echo "Not replacing existing ${NODECONF}"
exit 0
fi
# afterburn service is expected to be used for metadata retrival, see respective systemd unit.
# However, on older OCP boot images does not contain afterburn service, check if afterburn variables are there
# otherwise try to communicate IMDS here.
# metadata related afterburn doc: https://coreos.github.io/afterburn/usage/attributes/
HOSTNAME=${AFTERBURN_AWS_HOSTNAME:-}
if [[ -z "${HOSTNAME}" ]]; then
HOSTNAME=$(curl -fSs http://169.254.169.254/2022-09-24/meta-data/local-hostname)
if [[ -z "${HOSTNAME}" ]]; then
echo "Can not obtain hostname from the metadata service."
exit 1
fi
fi
# For compatibility with the AWS in-tree provider
# Set node name to be instance name instead of the default FQDN hostname
# afterburn service is using for metadata retrival, see respective systemd unit
# metadata related afterburn doc: https://coreos.github.io/afterburn/usage/attributes/
cat > "${NODECONF}" <<EOF
[Service]
Environment="KUBELET_NODE_NAME=${AFTERBURN_AWS_HOSTNAME}"
Environment="KUBELET_NODE_NAME=${HOSTNAME}"
EOF
Expand Up @@ -12,15 +12,29 @@ contents:
exit 0
fi
# afterburn service is expected to be used for metadata retrival, see respective systemd unit.
# However, on older OCP boot images does not contain afterburn service, check if afterburn variables are there
# otherwise try to communicate IMDS here.
# metadata related afterburn doc: https://coreos.github.io/afterburn/usage/attributes/
INSTANCE_ID=${AFTERBURN_AWS_INSTANCE_ID:-}
AVAILABILITY_ZONE=${AFTERBURN_AWS_AVAILABILITY_ZONE:-}
if [[ -z "${INSTANCE_ID}" ]] || [[ -z "${AVAILABILITY_ZONE}" ]]; then
INSTANCE_ID=$(curl -fSs http://169.254.169.254/2022-09-24/meta-data/instance-id)
AVAILABILITY_ZONE=$(curl -fSs http://169.254.169.254/2022-09-24/meta-data/placement/availability-zone)
if [[ -z "${INSTANCE_ID}" ]] || [[ -z "${AVAILABILITY_ZONE}" ]]; then
echo "Can not obtain instance-id and availability zone info from the metadata service."
exit 1
fi
fi
# Due to a potential mismatch between Hostname and PrivateDNSName with clusters that use custom DHCP Option Sets
# which can cause issues in cloud controller manager node syncing
# (see: https://github.com/kubernetes/cloud-provider-aws/issues/384),
# set KUBELET_PROVIDERID to be a fully qualified AWS instace provider id.
# This new variable is later used to populate the kubelet's `provider-id` flag, later set on the Node .spec
# and used by the cloud controller manager's node controller to retrieve the Node's backing instance.
# This is obtained by using afterburn service variables, in turn obtained from metadata retrival.
# See respective systemd unit metadata related afterburn doc: https://coreos.github.io/afterburn/usage/attributes/
cat > "${NODECONF}" <<EOF
[Service]
Environment="KUBELET_PROVIDERID=aws:///${AFTERBURN_AWS_AVAILABILITY_ZONE}/${AFTERBURN_AWS_INSTANCE_ID}"
Environment="KUBELET_PROVIDERID=aws:///${AVAILABILITY_ZONE}/${INSTANCE_ID}"
EOF
7 changes: 5 additions & 2 deletions templates/common/aws/units/aws-kubelet-nodename.service.yaml
Expand Up @@ -6,7 +6,9 @@ contents: |
# Run afterburn service for collect info from metadata server
# see: https://coreos.github.io/afterburn/usage/attributes/
Requires=afterburn.service
# Not required due to OCP 4.1 boot image does not contain afterburn service
# see: https://issues.redhat.com/browse/OCPBUGS-7559
Wants=afterburn.service
After=afterburn.service
# Wait for NetworkManager to report it's online
Expand All @@ -15,7 +17,8 @@ contents: |
Before=kubelet.service
[Service]
EnvironmentFile=/run/metadata/afterburn
# Mark afterburn environment file optional, due to it is possible that afterburn service was not executed
EnvironmentFile=-/run/metadata/afterburn
ExecStart=/usr/local/bin/aws-kubelet-nodename
Type=oneshot
Expand Down
Expand Up @@ -6,7 +6,9 @@ contents: |
# Run afterburn service for collect info from metadata server
# see: https://coreos.github.io/afterburn/usage/attributes/
Requires=afterburn.service
# Not required due to OCP 4.1 boot image does not contain afterburn service
# see: https://issues.redhat.com/browse/OCPBUGS-7559
Wants=afterburn.service
After=afterburn.service
# Wait for NetworkManager to report it's online
Expand All @@ -15,7 +17,8 @@ contents: |
Before=kubelet.service
[Service]
EnvironmentFile=/run/metadata/afterburn
# Mark afterburn environment file optional, due to it is possible that afterburn service was not executed
EnvironmentFile=-/run/metadata/afterburn
ExecStart=/usr/local/bin/aws-kubelet-providerid
Type=oneshot
Expand Down

0 comments on commit e7a5af3

Please sign in to comment.