Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kubernetes): Add gke autopilot check to script #1004

Merged
merged 10 commits into from
Dec 21, 2023
49 changes: 47 additions & 2 deletions recipes/newrelic/infrastructure/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@ install:
# DEBUG_MESSAGE is used to collect all necessary debug info we need.
DEBUG_MESSAGE=""

# Determine if user is installing in gke autopilot
while :; do
echo -e -n "${GREEN}Are you installing in a GKE Autopilot cluster? Y/N? ${NC} "
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
read ans
echo ""
GKE_AUTOPILOT_ANSWER=$(echo "${ans^^}" | cut -c1-1)
if [[ "$GKE_AUTOPILOT_ANSWER" == "N" ]]; then
echo "Continuing with installing the integration."
echo "{\"Metadata\":{\"gkeAutopilotAnswer\":\"No\",\"DebugMessage\":\"$DEBUG_MESSAGE\"}}" | tee -a {{.NR_CLI_OUTPUT}} > /dev/null
break
fi
if [[ "$GKE_AUTOPILOT_ANSWER" == "Y" ]]; then
echo "{\"Metadata\":{\"gkeAutopilotAnswer\":\"Yes\",\"DebugMessage\":\"$DEBUG_MESSAGE\"}}" | tee -a {{.NR_CLI_OUTPUT}} > /dev/null
echo "GKE Autopilot does not allowed privileged access. Turning off privileged mode." >&2
echo -e "\033[0;31mTurning off Pixie for this installation which requires privileged access.\033[0m" >&2
echo -e "\033[0;31mTurning off Logging for this installation which currently is not supported in GKE Autopilot.\033[0m" >&2
NR_CLI_PRIVILEGED=false
PIXIE_SUPPORTED=false
NR_CLI_LOGGING=false
break
fi
echo -e "Please type Y or N only."
done

# Determine the cluster name if not provided
CLUSTER=$($SUDO $KUBECTL config current-context 2>/dev/null || echo "unknown")

Expand Down Expand Up @@ -528,6 +552,14 @@ install:
fi
ARGS="${ARGS} --set ksm.enabled=${NR_CLI_KSM}"

# if installing in GKE Autopilot, we need to turn off controlPlane and pixie and set kubelet scheme and port
if [[ "$GKE_AUTOPILOT_ANSWER" == "Y" ]]; then
ARGS="${ARGS} --set newrelic-infrastructure.controlPlane.enabled=false"
ARGS="${ARGS} --set newrelic-infrastructure.kubelet.config.scheme=http"
ARGS="${ARGS} --set newrelic-infrastructure.kubelet.config.port=10255"
ARGS="${ARGS} --set newrelic-pixie.enabled=false"
fi

# leaving this commented out for the future
# if [[ $SERVER_MAJOR_VERSION -eq 1 && $SERVER_MINOR_VERSION -lt 25 ]]; then
# ARGS="${ARGS} --set kube-state-metrics.image.tag=v2.6.0"
Expand Down Expand Up @@ -588,10 +620,16 @@ install:
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

# With 2>&1 >/dev/null, ERROR only keeps the error message if $? is non-zero and is empty if $? is zero
echo "Installing newrelic-bundle......."
ERROR=$($SUDO helm upgrade $ARGS 2>&1 >/dev/null)
if [[ "${ERROR}" != "" ]]; then
echo "helm (version $HELM_VERSION) repo upgrade installation failed due to: $ERROR"
exit 131
if [[ "${GKE_AUTOPILOT_ANSWER}" == "Y" ]] && ! (echo "${ERROR}" | grep -q "Error"); then
echo "Warnings from GKE Autopilot: $ERROR"
break
else
echo "helm (version $HELM_VERSION) repo upgrade installation failed due to: $ERROR"
exit 131
fi
fi
else
echo ""
Expand Down Expand Up @@ -619,6 +657,13 @@ install:
BODY="${BODY},\"global.lowDataMode\":\"${NR_CLI_LOW_DATA_MODE}\""
BODY="${BODY},\"ksm.enabled\":\"${NR_CLI_KSM}\""

# if installing in GKE Autopilot, turn off controlPlane and set kubelet scheme and port
if [[ "$GKE_AUTOPILOT_ANSWER" == "Y" ]]; then
BODY="${BODY},\"newrelic-infrastructure.controlPlane.enabled\":\"false\""
BODY="${BODY},\"newrelic-infrastructure.kubelet.config.scheme\":\"http\""
BODY="${BODY},\"newrelic-infrastructure.kubelet.config.port\":\"10255\""
fi

# leaving this commented out for the future
# if [[ $SERVER_MAJOR_VERSION -eq 1 && $SERVER_MINOR_VERSION -lt 25 ]]; then
# BODY="${BODY},\"kube-state-metrics.image.tag\":\"v2.6.0\""
Expand Down
Loading