Skip to content

Commit 144a500

Browse files
feat(kubernetes): Add gke autopilot check to script (#1004)
1 parent 64b0d8f commit 144a500

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

recipes/newrelic/infrastructure/kubernetes.yml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,40 @@ install:
190190
# DEBUG_MESSAGE is used to collect all necessary debug info we need.
191191
DEBUG_MESSAGE=""
192192
193+
# Determine if user is installing in gke autopilot
194+
195+
GKE_AUTOPILOT_ANSWER="N"
196+
while :; do
197+
echo -e -n "${GREEN}Are you installing in a GKE Autopilot cluster? Y/N? ${NC} "
198+
199+
if [[ "{{.NEW_RELIC_ASSUME_YES}}" == "true" ]]; then
200+
echo "Assume yes flag was provided - answering N for installing in GKE Autopilot."
201+
echo "Continuing with installing the integration."
202+
GKE_AUTOPILOT_ANSWER="N"
203+
break
204+
else
205+
read ans
206+
echo ""
207+
GKE_AUTOPILOT_ANSWER=$(echo "${ans^^}" | cut -c1-1)
208+
if [[ "$GKE_AUTOPILOT_ANSWER" == "N" ]]; then
209+
echo "Continuing with installing the integration."
210+
echo "{\"Metadata\":{\"gkeAutopilotAnswer\":\"No\",\"DebugMessage\":\"$DEBUG_MESSAGE\"}}" | tee -a {{.NR_CLI_OUTPUT}} > /dev/null
211+
break
212+
fi
213+
if [[ "$GKE_AUTOPILOT_ANSWER" == "Y" ]]; then
214+
echo "{\"Metadata\":{\"gkeAutopilotAnswer\":\"Yes\",\"DebugMessage\":\"$DEBUG_MESSAGE\"}}" | tee -a {{.NR_CLI_OUTPUT}} > /dev/null
215+
echo -e "\033[0;31mGKE Autopilot does not allow privileged access. Turning off privileged mode.\033[0m" >&2
216+
echo -e "\033[0;31mTurning off Pixie for this installation which requires privileged access.\033[0m" >&2
217+
echo -e "\033[0;31mTurning off Logging for this installation which currently is not supported in GKE Autopilot.\033[0m" >&2
218+
NR_CLI_PRIVILEGED=false
219+
PIXIE_SUPPORTED=false
220+
NR_CLI_LOGGING=false
221+
break
222+
fi
223+
fi
224+
echo -e "Please type Y or N only."
225+
done
226+
193227
# Determine the cluster name if not provided
194228
CLUSTER=$($SUDO $KUBECTL config current-context 2>/dev/null || echo "unknown")
195229
@@ -528,6 +562,14 @@ install:
528562
fi
529563
ARGS="${ARGS} --set ksm.enabled=${NR_CLI_KSM}"
530564
565+
# if installing in GKE Autopilot, we need to turn off controlPlane and pixie and set kubelet scheme and port
566+
if [[ "$GKE_AUTOPILOT_ANSWER" == "Y" ]]; then
567+
ARGS="${ARGS} --set newrelic-infrastructure.controlPlane.enabled=false"
568+
ARGS="${ARGS} --set newrelic-infrastructure.kubelet.config.scheme=http"
569+
ARGS="${ARGS} --set newrelic-infrastructure.kubelet.config.port=10255"
570+
ARGS="${ARGS} --set newrelic-pixie.enabled=false"
571+
fi
572+
531573
# leaving this commented out for the future
532574
# if [[ $SERVER_MAJOR_VERSION -eq 1 && $SERVER_MINOR_VERSION -lt 25 ]]; then
533575
# ARGS="${ARGS} --set kube-state-metrics.image.tag=v2.6.0"
@@ -588,10 +630,16 @@ install:
588630
echo "{\"Metadata\":{\"helmVersion\":\"$($SUDO helm version -c --short)\", \"helmCommandBeforeExecution\":\"$SUDO helm upgrade $CLEANED_ARGS\", \"K8sClientVersion\":\"$CLIENT_MAJOR_VERSION.$CLIENT_MINOR_VERSION\",\"K8sServerVersion\":\"$SERVER_MAJOR_VERSION.$SERVER_MINOR_VERSION\",\"DebugMessage\":\"$DEBUG_MESSAGE\"}}" | tee -a {{.NR_CLI_OUTPUT}} > /dev/null
589631
590632
# With 2>&1 >/dev/null, ERROR only keeps the error message if $? is non-zero and is empty if $? is zero
633+
echo "Installing newrelic-bundle......."
591634
ERROR=$($SUDO helm upgrade $ARGS 2>&1 >/dev/null)
592635
if [[ "${ERROR}" != "" ]]; then
593-
echo "helm (version $HELM_VERSION) repo upgrade installation failed due to: $ERROR"
594-
exit 131
636+
if [[ "${GKE_AUTOPILOT_ANSWER}" == "Y" ]] && ! (echo "${ERROR}" | grep -q "Error"); then
637+
echo "Warnings from GKE Autopilot: $ERROR"
638+
break
639+
else
640+
echo "helm (version $HELM_VERSION) repo upgrade installation failed due to: $ERROR"
641+
exit 131
642+
fi
595643
fi
596644
else
597645
echo ""
@@ -619,6 +667,13 @@ install:
619667
BODY="${BODY},\"global.lowDataMode\":\"${NR_CLI_LOW_DATA_MODE}\""
620668
BODY="${BODY},\"ksm.enabled\":\"${NR_CLI_KSM}\""
621669
670+
# if installing in GKE Autopilot, turn off controlPlane and set kubelet scheme and port
671+
if [[ "$GKE_AUTOPILOT_ANSWER" == "Y" ]]; then
672+
BODY="${BODY},\"newrelic-infrastructure.controlPlane.enabled\":\"false\""
673+
BODY="${BODY},\"newrelic-infrastructure.kubelet.config.scheme\":\"http\""
674+
BODY="${BODY},\"newrelic-infrastructure.kubelet.config.port\":\"10255\""
675+
fi
676+
622677
# leaving this commented out for the future
623678
# if [[ $SERVER_MAJOR_VERSION -eq 1 && $SERVER_MINOR_VERSION -lt 25 ]]; then
624679
# BODY="${BODY},\"kube-state-metrics.image.tag\":\"v2.6.0\""

0 commit comments

Comments
 (0)