Skip to content

Commit

Permalink
Removing manual step 9 to add hub kube config secret (#800)
Browse files Browse the repository at this point in the history
Signed-off-by: Amrutha <[email protected]>
  • Loading branch information
amrcoder authored Jan 14, 2025
1 parent 5df279f commit 54a9764
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions solutions/joining-hub-and-spoke-with-aws-auth-manually/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,4 @@ While the implementation of this feature is in progress, in the hub and spoke si
aws eks create-access-entry --cluster-name $HUB_CLUSTER_NAME --region=$HUB_REGION --principal-arn arn:aws:iam::"$HUB_ACCOUNT_ID":role/$HUB_ROLE_NAME --username $SPOKE_CLUSTER_NAME --kubernetes-groups open-cluster-management:$SPOKE_CLUSTER_NAME
aws eks list-access-entries --cluster $HUB_CLUSTER_NAME --region=$HUB_REGION | grep -i $HUB_ROLE_NAME
```

9. Generate the secret called `hub-kubeconfig-secret` in `open-cluster-management-agent` namespace using above kubeconfig:
```shell
aws eks update-kubeconfig --name $HUB_CLUSTER_NAME --kubeconfig /awscli/kubeconfig.kubeconfig --role-arn arn:aws:iam::"$HUB_ACCOUNT_ID":role/$HUB_ROLE_NAME --dry-run > hub-kubeconfig

# Updating the clusterName to "hub" to make it same as bootstrap-kubeconfig
# to pass a validation in ocm. Install yq, if missing.
# Note - The yq command works only on a Linux machine. Please use a text editor to manually replace the values otherwise.
NEW_CLUSTER_NAME="hub"
yq eval "
(.clusters[].name = \"${NEW_CLUSTER_NAME}\") |
(.contexts[].context.cluster = \"${NEW_CLUSTER_NAME}\") |
del(.users[].user.exec.env)
" -i "hub-kubeconfig"

HUB_KUBECONFIG=$(cat hub-kubeconfig)

AGENT_NAME_ENCODED=$(kubectl get klusterlet klusterlet -o jsonpath='{.metadata.uid}' | tr -d '\n' | base64 | tr -d '\n')
SPOKE_CLUSTER_NAME_ENCODED=$(echo -n "$SPOKE_CLUSTER_NAME" | base64 | tr -d '\n')
HUB_KUBECONFIG_ENCODED=$(echo -n "$HUB_KUBECONFIG" | base64 | tr -d '\n')
HUB_KUBECONFIG_ENCODED_ESCAPED=$(printf '%s' "$HUB_KUBECONFIG_ENCODED" | sed 's/[&/\|]/\\&/g')

sed -e "s|\${AGENT_NAME_ENCODED}|$AGENT_NAME_ENCODED|g" \
-e "s|\${SPOKE_CLUSTER_NAME_ENCODED}|$SPOKE_CLUSTER_NAME_ENCODED|g" \
-e "s|\${HUB_KUBECONFIG_ENCODED}|$HUB_KUBECONFIG_ENCODED_ESCAPED|g" \
templates/Template-hub-kubeconfig-secret.yaml > hubKubeconfigSecret.yaml

kubectl apply -f hubKubeconfigSecret.yaml
```

10. Create a sample manifestwork in hub. Confirm that resources are pushed to spoke.
9. Create a sample manifestwork in hub. Confirm that resources are pushed to spoke.

0 comments on commit 54a9764

Please sign in to comment.