Skip to content

Commit

Permalink
NR-361437-fix-jd-parse-error (#1586)
Browse files Browse the repository at this point in the history
<!--
Thank you for contributing to New Relic's Helm charts. Before you submit
this PR we'd like to
make sure you are aware of our technical requirements:

*
https://github.com/newrelic-experimental/helm-charts/blob/master/CONTRIBUTING.md#technical-requirements

For a quick overview across what we will look at reviewing your PR,
please read
our review guidelines:

*
https://github.com/newrelic-experimental/helm-charts/blob/master/REVIEW_GUIDELINES.md

Following our best practices right from the start will accelerate the
review process and
help get your PR merged quicker.

When updates to your PR are requested, please add new commits and do not
squash the
history. This will make it easier to identify new changes. The PR will
be squashed
anyways when it is merged. Thanks.

For fast feedback, please @-mention maintainers that are listed in the
Chart.yaml file.

Please make sure you test your changes before you push them. Once
pushed, a Github Action
will run across your changes and do some initial checks and linting.
These checks run
very quickly. Please check the results. We would like these checks to
pass before we
even continue reviewing your changes.
-->
#### Is this a new chart

#### What this PR does / why we need it:

#### Which issue this PR fixes
*(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)`
format, will close that issue when PR gets merged)*
  - fixes #

#### Special notes for your reviewer:

#### Checklist
[Place an '[x]' (no spaces) in all applicable fields. Please remove
unrelated fields.]
- [ ] Chart Version bumped
- [ ] Variables are documented in the README.md
- [ ] Title of the PR starts with chart name (e.g. `[mychartname]`)
  • Loading branch information
vjripoll authored Feb 5, 2025
1 parent 042bf16 commit f6ff9c4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion charts/agent-control/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: agent-control
description: Bootstraps New Relic' Agent Control

type: application
version: 0.0.42-beta
version: 0.0.43-beta

dependencies:
- name: flux2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,39 @@ spec:
echo Key generated, creating the identity...
if [ "${NEW_RELIC_AUTH_CLIENT_ID:-}" != "" ] && [ "${NEW_RELIC_AUTH_CLIENT_SECRET:-}" != "" ]; then
echo Starting with L1/L2 System Identity...
echo Starting with L1 System Identity...
############################################################
# Get the L1 Access Token
############################################################
RESPONSE_FILE=$TEMPORAL_FOLDER/response_token.json
for RETRY in 1 2 3; do
HTTP_CODE=$(echo '{"client_id": "'$NEW_RELIC_AUTH_CLIENT_ID'", "client_secret": "'$NEW_RELIC_AUTH_CLIENT_SECRET'", "grant_type": "client_credentials"}' | tr -d $'\n' | curl \
-s -w "%{http_code}" \
-s -S -w "%{http_code}" \
-H "Content-Type: application/json" \
-o "$RESPONSE_FILE" \
--data-binary @- \
"{{ include "newrelic-agent-control.config.endpoints.tokenRenewal" . }}"
)
--max-time 60 \
"{{ include "newrelic-agent-control.config.endpoints.tokenRenewal" . }}")
if [ $HTTP_CODE -eq 200 ]; then
break
fi
ERROR_MESSAGE=$(jq '.error_description // "invalid_request"' < "$TEMPORAL_FOLDER/response_token.json" | tr -d '"')
echo "Error getting system identity auth token. The API endpoint returned $HTTP_CODE: $ERROR_MESSAGE. Retrying ($RETRY/3)..."
sleep 2
if [ -z "$HTTP_CODE" ] || [ "$HTTP_CODE" -eq 0 ]; then
echo "Network error occurred or no HTTP response was received. Retrying ($RETRY/3)..."
sleep 2
continue
else
if jq empty "$TEMPORAL_FOLDER/response_token.json" > /dev/null 2>&1; then
ERROR_MESSAGE=$(jq '.error_description // "invalid_request"' < "$TEMPORAL_FOLDER/response_token.json" | tr -d '"')
echo "Error getting system identity auth token. The API endpoint returned $HTTP_CODE: $ERROR_MESSAGE. Retrying ($RETRY/3)..."
sleep 2
else
echo -n "Error getting system identity auth token. The API endpoint returned $HTTP_CODE: " && cat "$TEMPORAL_FOLDER/response_token.json" | tr -d '\n' && echo " Retrying ($RETRY/3)..."
sleep 2
continue
fi
fi
done
if [ $HTTP_CODE -ne 200 ]; then
Expand All @@ -142,6 +153,7 @@ spec:
ACCESS_TOKEN=$(jq '.access_token' < "$RESPONSE_FILE" | tr -d '"' )
echo Starting with L2 System Identity...
############################################################
# Create System Identity (L1/L2 System Identities)
############################################################
Expand All @@ -161,30 +173,47 @@ spec:
}
}"
}' | tr -d $'\n' | curl \
-s -w "%{http_code}" \
-s -S -w "%{http_code}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-o "$TEMPORAL_FOLDER/response.json" \
--data-binary @- \
--max-time 60 \
"{{ include "newrelic-agent-control.config.endpoints.systemIdentityCreation" . }}"
)
if [ $HTTP_CODE -eq 200 ]; then
break
fi
echo "Error creating L2 system identity. The API endpoint returned $HTTP_CODE. Retrying ($RETRY/3)..."
sleep 2
if [ -z "$HTTP_CODE" ] || [ "$HTTP_CODE" -eq 0 ]; then
echo "Network error occurred or no HTTP response was received during L2 identity creation. Retrying ($RETRY/3)..."
sleep 2
continue
else
if jq empty "$TEMPORAL_FOLDER/response_token.json" > /dev/null 2>&1; then
ERROR_MESSAGE=$(jq '.errors[0].message // "invalid_request"' < "$TEMPORAL_FOLDER/response_token.json" | tr -d '"')
echo "Error creating L2 system identity. The API endpoint returned $HTTP_CODE. Retrying ($RETRY/3)..."
sleep 2
else
echo -n "Error creating L2 system identity. The API endpoint returned $HTTP_CODE: " && cat "$TEMPORAL_FOLDER/response_token.json" | tr -d '\n' && echo " Retrying ($RETRY/3)..."
sleep 2
continue
fi
fi
done
if [ $HTTP_CODE -ne 200 ]; then
echo "Error: The API endpoint returned HTTP code $HTTP_CODE."
exit 99
fi
ERROR_MESSAGE=$(jq '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json" | tr -d '"')
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Failed to create a New Relic System Identity for Fleet Control communication authentication. Please verify that your User Key is valid and that your Account Organization has the necessary permissions to create a System Identity: $ERROR_MESSAGE"
exit 100
if jq empty "$TEMPORAL_FOLDER/response_token.json" > /dev/null 2>&1; then
ERROR_MESSAGE=$(jq '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json" | tr -d '"')
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Failed to create a New Relic System Identity L2 for Fleet Control communication authentication. Please verify that your User Key is valid and that your Account Organization has the necessary permissions to create a System Identity: $ERROR_MESSAGE"
exit 100
fi
fi
CLIENT_ID=$(jq '.data.create.clientId' < "$TEMPORAL_FOLDER/response.json" | tr -d '"' )
Expand All @@ -207,28 +236,46 @@ spec:
}"
}' | tr -d $'\n' | \
curl \
-w "%{http_code}" \
-s -S -w "%{http_code}" \
-H "Content-Type: application/json" \
-H "API-Key: $USER_KEY" \
-o "$TEMPORAL_FOLDER/response.json" \
--data @- \
--max-time 60 \
"{{ include "newrelic-agent-control.config.endpoints.systemIdentityRegistration" . }}"
)
if [ $HTTP_CODE -eq 200 ]; then
break
fi
echo "Error creating the new system identity. The API endpoint returned $HTTP_CODE. Retrying ($RETRY/3)..."
sleep 2
if [ -z "$HTTP_CODE" ] || [ "$HTTP_CODE" -eq 0 ]; then
echo "Network error occurred or no HTTP response was received during legacy identity creation. Retrying ($RETRY/3)..."
sleep 2
continue
else
if jq empty "$TEMPORAL_FOLDER/response_token.json" > /dev/null 2>&1; then
ERROR_MESSAGE=$(jq '.errors[0].message // "invalid_request"' < "$TEMPORAL_FOLDER/response_token.json" | tr -d '"')
echo "Error creating the new legacy system identity. The API endpoint returned $HTTP_CODE. Retrying ($RETRY/3)..."
sleep 2
else
echo -n "Error creating the new legacy system identity. The API endpoint returned $HTTP_CODE: " && cat "$TEMPORAL_FOLDER/response_token.json" | tr -d '\n' && echo " Retrying ($RETRY/3)..."
sleep 2
continue
fi
fi
done
if [ $HTTP_CODE -ne 200 ]; then echo HTTP_CODE=$HTTP_CODE ;exit 1; fi
ERROR_MESSAGE=$(jq -r '.errors[0].message // "NOERROR"' "$TEMPORAL_FOLDER/response.json")
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Failed to create a New Relic System Identity for Fleet Control communication authentication. Please verify that your User Key is valid and that your Account Organization has the necessary permissions to create a System Identity: $ERROR_MESSAGE"
exit 1
if jq empty "$TEMPORAL_FOLDER/response_token.json" > /dev/null 2>&1; then
ERROR_MESSAGE=$(jq '.errors[0].message // "NOERROR"' < "$TEMPORAL_FOLDER/response.json" | tr -d '"')
if [ "$ERROR_MESSAGE" != "NOERROR" ]; then
echo "Failed to create a New Relic Legacy System Identity for Fleet Control communication authentication. Please verify that your User Key is valid and that your Account Organization has the necessary permissions to create a System Identity: $ERROR_MESSAGE"
exit 100
fi
fi
CLIENT_ID=$(jq -r '.data.systemIdentityCreate.clientId' "$TEMPORAL_FOLDER/response.json")
CLIENT_ID=$(jq -r '.data.systemIdentityCreate.clientId' "$TEMPORAL_FOLDER/response.json")
fi
echo Creating the secret '{{ include "newrelic-agent-control.auth.secret.name" . }}'...
kubectl create secret generic --dry-run=client -o json \
Expand Down

0 comments on commit f6ff9c4

Please sign in to comment.