Skip to content

Commit d27b377

Browse files
committed
Add --namespace flag support to workloads
Allows specifying a target Kubernetes namespace for workload commands (create, list, delete, wait). This avoids hardcoding the 'default' namespace and enables running workloads in custom namespaces. Also updates setup_k8s_service_accounts to create service accounts and role bindings in the specified namespace.
1 parent 337e676 commit d27b377

16 files changed

Lines changed: 85 additions & 65 deletions

recipes/Cluster_delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gcloud container clusters list --project=golden-project --filter=name=golden-clu
1717
gcloud container clusters get-credentials golden-cluster --location=us-central1 --dns-endpoint --project=golden-project && kubectl config view && kubectl config set-context --current --namespace=default
1818
[XPK] Get the name of the workloads in the cluster.
1919
[XPK] Task: `List Jobs with filter-by-status=EVERYTHING` is implemented by the following command not running since it is a dry run.
20-
kubectl get workloads --ignore-not-found -o=json
20+
kubectl get workloads --ignore-not-found -o=json
2121
[XPK] Task: `Cluster Delete` is implemented by the following command not running since it is a dry run.
2222
gcloud beta container clusters delete golden-cluster --project=golden-project --location=us-central1 --quiet
2323
[XPK] Task: `Get All Subnets` is implemented by the following command not running since it is a dry run.

recipes/Workload_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xpk workload create --project=golden-project --zone=us-central1-a --cluster=gold
99
$ xpk workload create --project=golden-project --zone=us-central1-a --cluster=golden-cluster --workload=golden-workload --command "bash hello" --tpu-type=v5p-8 --num-slices=1 --script-dir=/tmp
1010
[XPK] Starting xpk v0.0.0
1111
[XPK] Task: `Check if Workload Already Exists` is implemented by the following command not running since it is a dry run.
12-
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
12+
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
1313
[XPK] Task: `GKE Cluster Get ConfigMap` is implemented by the following command not running since it is a dry run.
1414
kubectl get configmap golden-cluster-resources-configmap -o=custom-columns="ConfigData:data" --no-headers=true
1515
[XPK] Skipping workload scheduling validation in dry run.
@@ -139,7 +139,7 @@ spec:
139139
140140
141141
[XPK] Task: `Creating Workload` is implemented by the following command not running since it is a dry run.
142-
kubectl apply -f 39eda1549f4c0d68a4f11e6cbd89ba655d49d2faeef6898a140f476e6e70ae0e
142+
kubectl apply -f 39eda1549f4c0d68a4f11e6cbd89ba655d49d2faeef6898a140f476e6e70ae0e
143143
[XPK] Task: `GKE Dashboard List` is implemented by the following command not running since it is a dry run.
144144
gcloud monitoring dashboards list --project=golden-project --filter="displayName:'GKE - TPU Monitoring Dashboard'" --format="value(name)" --verbosity=error
145145
[XPK] Check statistics and outlier mode of GKE metrics here: https://console.cloud.google.com/monitoring/dashboards/builder/0?project=golden-project&f.rlabel.cluster_name.ClusterName=golden-cluster. To view the metric data for your workload, select golden-workload from the JobName filter on the dashboard.

recipes/Workload_create_pathways.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xpk workload create-pathways --project=golden-project --zone=us-central1-a --clu
99
$ xpk workload create-pathways --project=golden-project --zone=us-central1-a --cluster=golden-cluster --workload=golden-workload --command "bash hello" --tpu-type=v5p-8 --num-slices=1 --script-dir=/tmp
1010
[XPK] Starting xpk v0.0.0
1111
[XPK] Task: `Check if Workload Already Exists` is implemented by the following command not running since it is a dry run.
12-
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
12+
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
1313
[XPK] Task: `GKE Cluster Get ConfigMap` is implemented by the following command not running since it is a dry run.
1414
kubectl get configmap golden-cluster-resources-configmap -o=custom-columns="ConfigData:data" --no-headers=true
1515
[XPK] Skipping workload scheduling validation in dry run.
@@ -268,7 +268,7 @@ spec:
268268
suspend: false
269269
270270
[XPK] Task: `Creating Workload` is implemented by the following command not running since it is a dry run.
271-
kubectl apply -f 0678dfe212682ff519efebdd5b50719a953fd288b50b0dd5e42775d0bb87d332
271+
kubectl apply -f 0678dfe212682ff519efebdd5b50719a953fd288b50b0dd5e42775d0bb87d332
272272
[XPK] Task: `GKE Dashboard List` is implemented by the following command not running since it is a dry run.
273273
gcloud monitoring dashboards list --project=golden-project --filter="displayName:'GKE - TPU Monitoring Dashboard'" --format="value(name)" --verbosity=error
274274
[XPK] Check statistics and outlier mode of GKE metrics here: https://console.cloud.google.com/monitoring/dashboards/builder/0?project=golden-project&f.rlabel.cluster_name.ClusterName=golden-cluster. To view the metric data for your workload, select golden-workload from the JobName filter on the dashboard.

recipes/Workload_create_pathways_super-slicing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DRY_RUN_RESOURCES_CONFIG_MAP="map[tpu7x-128:80]" xpk workload create-pathways --
99
$ DRY_RUN_RESOURCES_CONFIG_MAP="map[tpu7x-128:80]" xpk workload create-pathways --project=golden-project --zone=us-central1-a --cluster=golden-cluster --workload=golden-workload --command "bash hello" --tpu-type=tpu7x-4x4x20 --script-dir=/tmp
1010
[XPK] Starting xpk v0.0.0
1111
[XPK] Task: `Check if Workload Already Exists` is implemented by the following command not running since it is a dry run.
12-
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
12+
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
1313
[XPK] Task: `GKE Cluster Get ConfigMap` is implemented by the following command not running since it is a dry run.
1414
kubectl get configmap golden-cluster-resources-configmap -o=custom-columns="ConfigData:data" --no-headers=true
1515
[XPK] Task: `Get defined topologies` is implemented by the following command not running since it is a dry run.
@@ -270,7 +270,7 @@ spec:
270270
suspend: false
271271
272272
[XPK] Task: `Creating Workload` is implemented by the following command not running since it is a dry run.
273-
kubectl apply -f e7574bba6a3ad51a173d673c90ad230a9ba39c7f46cd000e09a952479d19460b
273+
kubectl apply -f e7574bba6a3ad51a173d673c90ad230a9ba39c7f46cd000e09a952479d19460b
274274
[XPK] Task: `GKE Dashboard List` is implemented by the following command not running since it is a dry run.
275275
gcloud monitoring dashboards list --project=golden-project --filter="displayName:'GKE - TPU Monitoring Dashboard'" --format="value(name)" --verbosity=error
276276
[XPK] Check statistics and outlier mode of GKE metrics here: https://console.cloud.google.com/monitoring/dashboards/builder/0?project=golden-project&f.rlabel.cluster_name.ClusterName=golden-cluster. To view the metric data for your workload, select golden-workload from the JobName filter on the dashboard.

recipes/Workload_create_sub-slicing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SUB_SLICING_ENABLED=true DRY_RUN_RESOURCES_CONFIG_MAP="map[v6e-16:8]" xpk worklo
99
$ SUB_SLICING_ENABLED=true DRY_RUN_RESOURCES_CONFIG_MAP="map[v6e-16:8]" xpk workload create --project=golden-project --zone=us-central1-a --cluster=golden-cluster --workload=golden-workload --command "bash hello" --tpu-type=v6e-2x4 --script-dir=/tmp
1010
[XPK] Starting xpk v0.0.0
1111
[XPK] Task: `Check if Workload Already Exists` is implemented by the following command not running since it is a dry run.
12-
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
12+
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
1313
[XPK] Task: `GKE Cluster Get ConfigMap` is implemented by the following command not running since it is a dry run.
1414
kubectl get configmap golden-cluster-resources-configmap -o=custom-columns="ConfigData:data" --no-headers=true
1515
[XPK] Task: `Get defined topologies` is implemented by the following command not running since it is a dry run.
@@ -144,7 +144,7 @@ spec:
144144
145145
146146
[XPK] Task: `Creating Workload` is implemented by the following command not running since it is a dry run.
147-
kubectl apply -f 2018fe16498f36301979a10667302a0aff6beb09956705b64ff396373af777ba
147+
kubectl apply -f 2018fe16498f36301979a10667302a0aff6beb09956705b64ff396373af777ba
148148
[XPK] Task: `GKE Dashboard List` is implemented by the following command not running since it is a dry run.
149149
gcloud monitoring dashboards list --project=golden-project --filter="displayName:'GKE - TPU Monitoring Dashboard'" --format="value(name)" --verbosity=error
150150
[XPK] Check statistics and outlier mode of GKE metrics here: https://console.cloud.google.com/monitoring/dashboards/builder/0?project=golden-project&f.rlabel.cluster_name.ClusterName=golden-cluster. To view the metric data for your workload, select golden-workload from the JobName filter on the dashboard.

recipes/Workload_create_super-slicing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DRY_RUN_RESOURCES_CONFIG_MAP="map[tpu7x-128:80]" xpk workload create --project=g
99
$ DRY_RUN_RESOURCES_CONFIG_MAP="map[tpu7x-128:80]" xpk workload create --project=golden-project --zone=us-central1-a --cluster=golden-cluster --workload=golden-workload --command "bash hello" --tpu-type=tpu7x-4x4x20 --script-dir=/tmp
1010
[XPK] Starting xpk v0.0.0
1111
[XPK] Task: `Check if Workload Already Exists` is implemented by the following command not running since it is a dry run.
12-
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
12+
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
1313
[XPK] Task: `GKE Cluster Get ConfigMap` is implemented by the following command not running since it is a dry run.
1414
kubectl get configmap golden-cluster-resources-configmap -o=custom-columns="ConfigData:data" --no-headers=true
1515
[XPK] Task: `Get defined topologies` is implemented by the following command not running since it is a dry run.
@@ -143,7 +143,7 @@ spec:
143143
144144
145145
[XPK] Task: `Creating Workload` is implemented by the following command not running since it is a dry run.
146-
kubectl apply -f 2c5ab381c0d643f8512a07d296d411413080ec652c15e8c676fd58435de5a327
146+
kubectl apply -f 2c5ab381c0d643f8512a07d296d411413080ec652c15e8c676fd58435de5a327
147147
[XPK] Task: `GKE Dashboard List` is implemented by the following command not running since it is a dry run.
148148
gcloud monitoring dashboards list --project=golden-project --filter="displayName:'GKE - TPU Monitoring Dashboard'" --format="value(name)" --verbosity=error
149149
[XPK] Check statistics and outlier mode of GKE metrics here: https://console.cloud.google.com/monitoring/dashboards/builder/0?project=golden-project&f.rlabel.cluster_name.ClusterName=golden-cluster. To view the metric data for your workload, select golden-workload from the JobName filter on the dashboard.

recipes/Workload_create_with_output-manifest-file.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xpk workload create --project=golden-project --zone=us-central1-a --cluster=gold
99
$ xpk workload create --project=golden-project --zone=us-central1-a --cluster=golden-cluster --workload=golden-workload --command "bash hello" --tpu-type=v5p-8 --num-slices=1 --script-dir=/tmp --output-manifest-file=/var/tmp/manifest.yaml
1010
[XPK] Starting xpk v0.0.0
1111
[XPK] Task: `Check if Workload Already Exists` is implemented by the following command not running since it is a dry run.
12-
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
12+
kubectl get workloads -o=custom-columns='Jobset:.metadata.ownerReferences[0].name'
1313
[XPK] Task: `GKE Cluster Get ConfigMap` is implemented by the following command not running since it is a dry run.
1414
kubectl get configmap golden-cluster-resources-configmap -o=custom-columns="ConfigData:data" --no-headers=true
1515
[XPK] Skipping workload scheduling validation in dry run.
@@ -140,7 +140,7 @@ spec:
140140
141141
142142
[XPK] Task: `Creating Workload` is implemented by the following command not running since it is a dry run.
143-
kubectl apply -f 39eda1549f4c0d68a4f11e6cbd89ba655d49d2faeef6898a140f476e6e70ae0e
143+
kubectl apply -f 39eda1549f4c0d68a4f11e6cbd89ba655d49d2faeef6898a140f476e6e70ae0e
144144
[XPK] Task: `GKE Dashboard List` is implemented by the following command not running since it is a dry run.
145145
gcloud monitoring dashboards list --project=golden-project --filter="displayName:'GKE - TPU Monitoring Dashboard'" --format="value(name)" --verbosity=error
146146
[XPK] Check statistics and outlier mode of GKE metrics here: https://console.cloud.google.com/monitoring/dashboards/builder/0?project=golden-project&f.rlabel.cluster_name.ClusterName=golden-cluster. To view the metric data for your workload, select golden-workload from the JobName filter on the dashboard.

recipes/Workload_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gcloud container clusters get-credentials golden-cluster --location=us-central1
1818
kubectl get pods
1919
[XPK] Finished get-credentials and kubectl setup.
2020
[XPK] Task: `List Jobs with filter-by-status=EVERYTHING` is implemented by the following command not running since it is a dry run.
21-
kubectl get workloads --ignore-not-found -o=json
21+
kubectl get workloads --ignore-not-found -o=json
2222
[XPK] Workload List Output:
2323
Jobset Name Created Time Priority TPU/GPU VMs Needed TPU/GPU VMs Running/Ran TPU/GPU VMs Done Status Status Message Status Time
2424
[XPK] See your workloads in Cloud Console: https://console.cloud.google.com/kubernetes/aiml/deployments/jobs?project=golden-project

recipes/comprehensive-demo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ gcloud container clusters get-credentials foo --location=us-central1 --dns-endpo
5454
kubectl get pods
5555
[XPK] Finished get-credentials and kubectl setup.
5656
[XPK] Task: `List Jobs with filter-by-status=EVERYTHING` is implemented by the following command not running since it is a dry run.
57-
kubectl get workloads --ignore-not-found -o=json
57+
kubectl get workloads --ignore-not-found -o=json
5858
[XPK] Workload List Output:
5959
Jobset Name Created Time Priority TPU/GPU VMs Needed TPU/GPU VMs Running/Ran TPU/GPU VMs Done Status Status Message Status Time
6060
[XPK] See your workloads in Cloud Console: https://console.cloud.google.com/kubernetes/aiml/deployments/jobs?project=bar

src/xpk/commands/cluster_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def construct_args(**kwargs: Any) -> Namespace:
8989
project='project',
9090
zone='us-central1-a',
9191
reservation='',
92+
namespace='',
9293
on_demand=False,
9394
tpu_type=None,
9495
device_type=None,

0 commit comments

Comments
 (0)