Skip to content

Commit

Permalink
enhance the build script for jcnr-secrets.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrho committed Sep 10, 2023
1 parent 303967f commit cfa1e05
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ This script will apply the JCNR secrets and add the `key1=jcnr` label to your EK

**NOTE:** Without the proper base64-encoded license file and JCNR root password in the `secrets.yaml` file, the cRPD Pod will remain in `CrashLoopBackOff` state.

### Optional: Using `setup.sh` under `secrets` directroy for Automated Setup
For an effortless setup of JCNR secrets, including the license and root password, as well as adding the necessary label to the EKS worker node, you can make use of a provided setup script.


#### B. Using the Assistant Tool to Configure `jcnr-secrets.yaml`

Expand Down Expand Up @@ -252,6 +249,36 @@ For an effortless setup of JCNR secrets, including the license and root password

**NOTE:** Ensure your license file is obtained from your account team and integrated correctly. Otherwise, the cRPD Pod might face issues.



### Optional: Streamlined Configuration using `setup.sh`

For those looking to simplify and automate the processes described in Sections 5 and 6, the provided `setup.sh` script under the `secrets` directory offers an all-in-one solution. This script serves two main purposes:

1. **JCNR Secrets Configuration:** It automates the creation of the `jcnr-secrets.yaml` file, ensuring the JCNR secrets (license and root password) are appropriately set.
2. **Labeling the EKS Worker Node:** It ensures that the necessary label (used for targeting by the DPDK environment setup) is added to the EKS worker node.

To utilize this streamlined approach, follow the steps below:

```
cd ~/demo/secrets
```

2. Execute the `setup.sh` script:

```
./setup.sh
```

Upon execution, the script will:

- Create and apply the `jcnr-secrets.yaml` file with the JCNR secrets.
- Add the `key1=jcnr` label to your EKS worker nodes, making them identifiable for the JCNR deployment.

**NOTE:** While the `setup.sh` script offers convenience, it's essential to understand the underlying manual steps (as detailed in Sections 5 & 6) to troubleshoot potential issues or customize configurations further.
### 7. AWS Marketplace Subscription for JCNR
Before you can proceed with Helm setup and pull JCNR helm charts, you need to visit the AWS Marketplace and subscribe to the JCNR container product.
Expand Down
2 changes: 1 addition & 1 deletion secrets/jcnr-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ metadata:
data:
root-password: amNucjEyMw==
crpd-license: |
LS0tCmFwaVZlcnNpb246IHYxCmtpbmQ6IE5hbWVzcGFjZQptZXRhZGF0YToKICBuYW1lOiBqY25yCi0tLQphcGlWZXJzaW9uOiB2MQpraW5kOiBTZWNyZXQKbWV0YWRhdGE6CiAgbmFtZTogamNuci1zZWNyZXRzCiAgbmFtZXNwYWNlOiBqY25yCmRhdGE6CiAgcm9vdC1wYXNzd29yZDogYW1OdWNqRXlNdz09CiAgY3JwZC1saWNlbnNlOiB8CiAgICBTbFZPVDFNNE9USXhPVEV5TVRJZ1lXVmhjV2xsSUdGc1lXdGhjQ0JvY3paak1tRWdaWEZoWVdGa0lEVmhaSE54YnlCNmJUZHhkVzhnTTJoeGNtMTVJR2huTnpSbWN5QnNlbU5pY21FZ2QzWmhaMlpqSUhwNGRuRTNZU0J1ZDNka2VUSWdOak5vWVdwcklIVXlObXhzY0NCdFltczBkM1lnYzJsa1ltUjYK
SlVOT1M4OTIxOTEyMTIgYWVhcWllIGFsYWthcCBoczZjMmEgZXFhYWFkIDVhZHNxbyB6bTdxdW8gM2hxcm15IGhnNzRmcyBsemNicmEgd3ZhZ2ZjIHp4dnE3YSBud3dkeTIgNjNoYWprIHUyNmxscCBtYms0d3Ygc2lkYmR6
68 changes: 64 additions & 4 deletions secrets/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
# create a secret for jcnr license and root password
kubectl apply -f ./jcnr-secrets.yaml
#!/bin/bash

# add label key1=jcnr to eks worker nodes
kubectl label nodes $(kubectl get nodes -o json | jq -r .items[0].metadata.name) key1=jcnr --overwrite
# Function to silently get contents from file or write user input to an output file
get_input_or_prompt_to_file() {
local prompt=$1
local file=$2
local outfile=$3
local default_message=$4

if [[ -f $file ]]; then
echo "Reading $default_message from $file"
cp "$file" "$outfile"
else
read -sp "$prompt: " content
echo "$content" > "$outfile"
fi
}

# Function to get multi-line input until a delimiter (END) is detected, and write it to an output file
get_multiline_input_or_prompt_to_file() {
local prompt=$1
local file=$2
local outfile=$3
local default_message=$4

if [[ -f $file ]]; then
echo "Reading $default_message from $file"
cp "$file" "$outfile"
else
echo "$prompt (Type 'END' on a new line to finish):"
local multi_line=""
while IFS= read -r line; do
[[ "$line" == "END" ]] && break
multi_line="${multi_line}${line}"$'\n'
done
echo "$multi_line" > "$outfile"
fi
}

# Store root password and license key in temporary files
get_input_or_prompt_to_file "Enter root password" "jcnr-root-password.txt" "tmp-root-password.txt" "root password"
get_multiline_input_or_prompt_to_file "Enter license key" "jcnr-license.txt" "tmp-license.txt" "license key"

# Build jcnr-secrets.yaml file
echo "Creating jcnr-secrets.yaml file"
./build-secrets.sh tmp-root-password.txt tmp-license.txt

# Cleanup temporary files
rm tmp-root-password.txt tmp-license.txt

# Apply JCNR secrets and namespace
echo "Applying JCNR secrets and namespace"
kubectl apply -f jcnr-secrets.yaml

# Prompt user for key-value pair for the label or use default
read -p "Enter label in format key=value (default is key1=jcnr): " LABEL
[[ -z "$LABEL" ]] && LABEL="key1=jcnr"

# Split the key and value
KEY="${LABEL%=*}"
VALUE="${LABEL#*=}"

# Add label to eks worker nodes
echo "Adding label to eks worker nodes"
kubectl label nodes $(kubectl get nodes -o json | jq -r .items[0].metadata.name) "$KEY=$VALUE" --overwrite

0 comments on commit cfa1e05

Please sign in to comment.