Skip to content

Commit

Permalink
wip additions
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Nov 25, 2024
1 parent 79c860d commit a443689
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/java-eks-otlp-ocb-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ jobs:
max_retry: 3
sleep_time: 60

- name: Download enablement script
uses: ./.github/workflows/actions/execute_and_retry
with:
pre-command: "mkdir enablement-script && cd enablement-script"
command: "wget https://raw.githubusercontent.com/jj22ee/application-signals-demo/refs/heads/ocb/scripts/eks/appsignals/enable-app-signals-ocb.sh"
cleanup: "rm -f enable-app-signals-ocb.sh"
post-command: "chmod +x enable-app-signals-ocb.sh"

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down Expand Up @@ -192,7 +184,7 @@ jobs:
- name: Install OTel Operator using enablement script
uses: ./.github/workflows/actions/execute_and_retry
with:
command: "${{ env.TEST_RESOURCES_FOLDER }}/enablement-script/enable-app-signals-ocb.sh \
command: "${{ env.TEST_RESOURCES_FOLDER }}/terraform/java/eks-otlp-ocb/util/enable-app-signals-ocb.sh \
${{ env.CLUSTER_NAME }} \
${{ env.E2E_TEST_AWS_REGION }} \
${{ env.SAMPLE_APP_NAMESPACE }}"
Expand Down
68 changes: 68 additions & 0 deletions terraform/java/eks-otlp-ocb/util/enable-app-signals-ocb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

cd "$(dirname "$0")"

CLUSTER_NAME=$1
REGION=$2
NAMESPACE=${3:-default}
echo "Enabling Application Signals for EKS Cluster ${CLUSTER_NAME} in ${REGION} for namespace ${NAMESPACE}"

# Check if the current context points to the new cluster in the correct region
kub_config=$(kubectl config current-context)
if [[ $kub_config != *"$CLUSTER_NAME"* ]] || [[ $kub_config != *"$REGION"* ]]; then
echo "Your current cluster context is not set to $CLUSTER_NAME $REGION. Please switch to the correct context first before running this script"
exit 1
fi

check_if_step_failed_and_exit() {
if [ $? -ne 0 ]; then
echo $1
exit 1
fi
}

check_if_loop_failed_and_exit() {
if [ $1 -ne 0 ]; then
echo $2
exit 1
fi
}

# Check if the namespace exists
kubectl get namespace $NAMESPACE > /dev/null 2>&1

# $? is a special variable that stores the exit status of the last command
if [ $? -ne 0 ]; then
# If namespace does not exist, create it
echo "Namespace '$NAMESPACE' does not exist. Creating it..."
kubectl create namespace $NAMESPACE
else
# If namespace exists, print a message
echo "Namespace '$NAMESPACE' already exists."
fi

# Create service linked role in the account
aws iam create-service-linked-role --aws-service-name application-signals.cloudwatch.amazonaws.com

# Enable OIDC to allow IAM role authN/Z with service account
eksctl utils associate-iam-oidc-provider --cluster ${CLUSTER_NAME} --region ${REGION} --approve
check_if_step_failed_and_exit "There was an error enabling the OIDC, exiting"

# Create Service Account with the proper IAM permissions
echo "Creating ServiceAccount"
eksctl create iamserviceaccount \
--name appsignals-collector \
--namespace ${NAMESPACE} \
--cluster ${CLUSTER_NAME} \
--region ${REGION} \
--attach-policy-arn arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess \
--attach-policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy \
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy \
--approve \
--override-existing-serviceaccounts
check_if_step_failed_and_exit "There was an error creating the ServiceAccount, exiting"


# Install OpenTelemetry Operator
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.0/cert-manager.yaml
kubectl apply -f https://github.com/open-telemetry/opentelemetry-operator/releases/latest/download/opentelemetry-operator.yaml

0 comments on commit a443689

Please sign in to comment.