#!/bin/bash # Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 #################################################### # Constants #################################################### readonly DP_DAEMONSET_NAME=aws-nitro-enclaves-k8s-daemonset readonly DP_PLUGIN_LABEL=aws-nitro-enclaves-k8s-dp #################################################### # Misc Specification #################################################### readonly misc_specification=$(cat<&1 > /dev/null } unlabel_node() { local node_name=$1 local label=$2 kubectl label node $node_name $label- } label_node() { local node_name=$1 local label=$2 local value=$3 kubectl label node $node_name $2=$3 } #################################################### # Main #################################################### main() { device_plugin_running -eq 0 && { say_warn "Device plugin is already enabled and running." return $SUCCESS } reset_ifs printf '%s\n' $misc_specification > $FILE_K8S_DEVICE_PLUGIN_MANIFEST restore_ifs local node_name=$(get_node_name) [ -z "${node_name}" ] && { say_err "Cannot get K8s node name. Device plugin installation has failed!" say_err "Make sure cluster the cluster installation has completed successfully." return $FAILURE } say "Attempt to unlabel node $node_name..." unlabel_node $node_name $DP_PLUGIN_LABEL say "Enabling Nitro Enclaves K8s device plugin..." kubectl apply -f $FILE_K8S_DEVICE_PLUGIN_MANIFEST || { say_err "Error applying manifest. ($FILE_K8S_DEVICE_PLUGIN_MANIFEST)" return $FAILURE } say "Labelling node $node_name..." label_node $node_name $DP_PLUGIN_LABEL enabled -eq 0 || { say_err "Error while labelling ${node_name}." return $FAILURE } }