Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: member cluster labeling script #807

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions hack/Azure/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,25 @@ more information.

You can add labels to a `MemberCluster` object in the same as with any other Kubernetes object.
These labels can then be used for targeting specific clusters in resource placement. To add a label,
run the command below:
run the commands below:

```sh
# Replace the values of MEMBER_CLUSTER, LABEL_KEY, and LABEL_VALUE with those of your own.
export MEMBER_CLUSTER=YOUR-MEMBER-CLUSTER
export LABEL_KEY=YOUR-LABEL-KEY
export LABEL_VALUE=YOUR-LABEL-VALUE
# Replace the values of <MEMBER_CLUSTER>, <LABEL_KEY>, and <LABEL_VALUE> with those of your own.
export MEMBER_CLUSTER=<YOUR-MEMBER-CLUSTER<
export LABEL_KEY=YOUR-<LABEL-KEY>
export LABEL_VALUE=<YOUR-LABEL-VALUE>
kubectl label membercluster $MEMBER_CLUSTER $LABEL_KEY=$LABEL_VALUE
```

Or, you can add the same label to multiple clusters at once by running the following script:
```
# Replace the value <number-of-member-cluster> to the desired number of member clusters you want to label.
chmod +x hack/Azure/setup/labelMC.sh
./hack/Azure/setup/labelMC.sh $LABEL_KEY=$LABEL_VALUE <number-of-member-clusters>
```
>**NOTE:** The script will label the number of member clusters at random.

To view the labels your current member clusters have been assigned, run the following command:
```
kubectl get membercluster --show-labels
```
18 changes: 18 additions & 0 deletions hack/Azure/setup/labelMC.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# CAN ONLY BE RUN AFTER CREATING NEEDED AKS CLUSTERS AND HUB CLUSTER. This script add labels to specified number of
# member clusters at random.

label=$1
count=$2

# Get the list of member clusters
clusters=($(kubectl get memberclusters -A -o jsonpath='{.items[*].metadata.name}'))

# Shuffle the indices
shuffled_indices=($(shuf -i 0-$((${#clusters[@]} - 1))))

# Label the specified number of clusters
for index in "${shuffled_indices[@]:0:$count}"; do
cluster=${clusters[$index]}
kubectl label membercluster "$cluster" "$label" --overwrite
echo "Labeled $cluster with label: $label"
done
Loading