From c99689ec3331672f8fe73253bf49351cf8fa5bcc Mon Sep 17 00:00:00 2001 From: Alfredo Molero Date: Tue, 14 Jun 2022 16:46:05 -0400 Subject: [PATCH 1/2] chore(k8s): support for new suffix pods naming --- .../newrelic/infrastructure/kubernetes.yml | 62 +++++++++++++------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/recipes/newrelic/infrastructure/kubernetes.yml b/recipes/newrelic/infrastructure/kubernetes.yml index 29a3e73e1..aec319c42 100644 --- a/recipes/newrelic/infrastructure/kubernetes.yml +++ b/recipes/newrelic/infrastructure/kubernetes.yml @@ -434,25 +434,49 @@ install: $SUDO $KUBECTL apply -f newrelic-k8s.yml fi - # Wait on nrk8s-kubelet pod to be running - POD_NAME="nrk8s-kubelet" - - echo "Running ${POD_NAME} status check attempt..." - MAX_RETRIES=150 - TRIES=0 - while [ $TRIES -lt $MAX_RETRIES ]; do - ((TRIES++)) - IS_INFRA_POD_STARTED=$($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep ${POD_NAME} | grep -i "running" | wc -l | sed 's/ //g') - if [[ $IS_INFRA_POD_STARTED -gt 0 ]]; then - echo "${POD_NAME} pod started" - break - fi - if [ "$TRIES" -eq "$MAX_RETRIES" ]; then - echo "${POD_NAME} pod is not starting" >&2 - exit 33 - fi - sleep 2 - done + # Check for '-scraper' suffixed pod name present, otherwise default to former pod naming + POD_NAME=$(test $($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep 'nrk8s-kubelet-node-scraper' | wc -l | sed 's/ //g') -gt 0 && echo 'nrk8s-kubelet-node-scraper' || echo 'nrk8s-kubelet') + + # Wait 2 mins max for at least 2 '-scraper' suffixed pods to be in a running state + if [[ "$POD_NAME" == "nrk8s-kubelet-node-scraper" ]]; then + echo "Running ${POD_NAME} status check attempt..." + MAX_RETRIES=60 + TRIES=0 + while [ $TRIES -lt $MAX_RETRIES ]; do + ((TRIES++)) + INFRA_PODS_STARTED=$($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep ${POD_NAME} | grep -i "running" | wc -l | sed 's/ //g') + if [[ $INFRA_PODS_STARTED -gt 1 ]]; then + echo "${POD_NAME} pods started" + break + fi + if [ "$TRIES" -eq "$MAX_RETRIES" ]; then + echo "${POD_NAME} pods not starting" >&2 + exit 33 + fi + sleep 2 + done + # Wait on former 'nrk8s-kubelet' pod naming to be running + elif [[ "$POD_NAME" == "nrk8s-kubelet" ]]; then + echo "Running ${POD_NAME} status check attempt..." + MAX_RETRIES=150 + TRIES=0 + while [ $TRIES -lt $MAX_RETRIES ]; do + ((TRIES++)) + IS_INFRA_POD_STARTED=$($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep ${POD_NAME} | grep -i "running" | wc -l | sed 's/ //g') + if [[ $IS_INFRA_POD_STARTED -gt 0 ]]; then + echo "${POD_NAME} pod started" + break + fi + if [ "$TRIES" -eq "$MAX_RETRIES" ]; then + echo "${POD_NAME} pod is not starting" >&2 + exit 33 + fi + sleep 2 + done + else + echo "Unable to check status for ${POD_NAME}" >&2 + exit 33 + fi # Show post install message echo "" From 6bdda87c78f9dab0f9ba01bc18dd54881b2b7c3f Mon Sep 17 00:00:00 2001 From: Alfredo Molero Date: Wed, 29 Jun 2022 14:27:58 -0400 Subject: [PATCH 2/2] chore(k8s): single pod name check --- .../newrelic/infrastructure/kubernetes.yml | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/recipes/newrelic/infrastructure/kubernetes.yml b/recipes/newrelic/infrastructure/kubernetes.yml index aec319c42..7276dba7e 100644 --- a/recipes/newrelic/infrastructure/kubernetes.yml +++ b/recipes/newrelic/infrastructure/kubernetes.yml @@ -434,49 +434,25 @@ install: $SUDO $KUBECTL apply -f newrelic-k8s.yml fi - # Check for '-scraper' suffixed pod name present, otherwise default to former pod naming + # Check for 'nrk8s-kubelet-node-scraper' pod presence first, otherwise default to former pod name 'nrk8s-kubelet' POD_NAME=$(test $($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep 'nrk8s-kubelet-node-scraper' | wc -l | sed 's/ //g') -gt 0 && echo 'nrk8s-kubelet-node-scraper' || echo 'nrk8s-kubelet') - # Wait 2 mins max for at least 2 '-scraper' suffixed pods to be in a running state - if [[ "$POD_NAME" == "nrk8s-kubelet-node-scraper" ]]; then - echo "Running ${POD_NAME} status check attempt..." - MAX_RETRIES=60 - TRIES=0 - while [ $TRIES -lt $MAX_RETRIES ]; do - ((TRIES++)) - INFRA_PODS_STARTED=$($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep ${POD_NAME} | grep -i "running" | wc -l | sed 's/ //g') - if [[ $INFRA_PODS_STARTED -gt 1 ]]; then - echo "${POD_NAME} pods started" - break - fi - if [ "$TRIES" -eq "$MAX_RETRIES" ]; then - echo "${POD_NAME} pods not starting" >&2 - exit 33 - fi - sleep 2 - done - # Wait on former 'nrk8s-kubelet' pod naming to be running - elif [[ "$POD_NAME" == "nrk8s-kubelet" ]]; then - echo "Running ${POD_NAME} status check attempt..." - MAX_RETRIES=150 - TRIES=0 - while [ $TRIES -lt $MAX_RETRIES ]; do - ((TRIES++)) - IS_INFRA_POD_STARTED=$($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep ${POD_NAME} | grep -i "running" | wc -l | sed 's/ //g') - if [[ $IS_INFRA_POD_STARTED -gt 0 ]]; then - echo "${POD_NAME} pod started" - break - fi - if [ "$TRIES" -eq "$MAX_RETRIES" ]; then - echo "${POD_NAME} pod is not starting" >&2 - exit 33 - fi - sleep 2 - done - else - echo "Unable to check status for ${POD_NAME}" >&2 - exit 33 - fi + echo "Running ${POD_NAME} status check attempt..." + MAX_RETRIES=150 + TRIES=0 + while [ $TRIES -lt $MAX_RETRIES ]; do + ((TRIES++)) + IS_INFRA_POD_STARTED=$($SUDO $KUBECTL get pods -o wide -n $NR_CLI_NAMESPACE | grep ${POD_NAME} | grep -i "running" | wc -l | sed 's/ //g') + if [[ $IS_INFRA_POD_STARTED -gt 0 ]]; then + echo "${POD_NAME} pod started" + break + fi + if [ "$TRIES" -eq "$MAX_RETRIES" ]; then + echo "${POD_NAME} pod is not starting" >&2 + exit 33 + fi + sleep 2 + done # Show post install message echo ""