Skip to content

Commit 5e93cde

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 5e93cde

16 files changed

Lines changed: 83 additions & 71 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 -n --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: 3 additions & 3 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 -n -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,13 +139,13 @@ 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.
146146
[XPK] Task: `Find cluster region or zone` is implemented by the following command not running since it is a dry run.
147147
gcloud container clusters list --project=golden-project --filter=name=golden-cluster --format="value(location)"
148148
[XPK] Follow your workload here: https://console.cloud.google.com/kubernetes/service/us-central1/golden-cluster/default/golden-workload/details?project=golden-project
149-
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.namespace_name%3D%22default%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
149+
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
150150
[XPK] Exiting XPK cleanly
151151
-->

recipes/Workload_create_pathways.md

Lines changed: 3 additions & 3 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 -n -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,10 +268,10 @@ 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.
275-
[XPK] Follow your Pathways workload and other resources here: https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.pod_name%3A%22golden-workload-%22%0Aseverity%3E%3DDEFAULT
275+
[XPK] Follow your Pathways workload and other resources here: https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.namespace_name%3D%22%22%0Aresource.labels.pod_name%3A%22golden-workload-%22%0Aseverity%3E%3DDEFAULT
276276
[XPK] Exiting XPK cleanly
277277
-->

recipes/Workload_create_pathways_super-slicing.md

Lines changed: 3 additions & 3 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 -n -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,11 +270,11 @@ 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.
277-
[XPK] Follow your Pathways workload and other resources here: https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.pod_name%3A%22golden-workload-%22%0Aseverity%3E%3DDEFAULT
277+
[XPK] Follow your Pathways workload and other resources here: https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.namespace_name%3D%22%22%0Aresource.labels.pod_name%3A%22golden-workload-%22%0Aseverity%3E%3DDEFAULT
278278
[XPK] Exiting XPK cleanly
279279
-->
280280

recipes/Workload_create_sub-slicing.md

Lines changed: 3 additions & 3 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 -n -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,13 +144,13 @@ 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.
151151
[XPK] Task: `Find cluster region or zone` is implemented by the following command not running since it is a dry run.
152152
gcloud container clusters list --project=golden-project --filter=name=golden-cluster --format="value(location)"
153153
[XPK] Follow your workload here: https://console.cloud.google.com/kubernetes/service/us-central1/golden-cluster/default/golden-workload/details?project=golden-project
154-
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.namespace_name%3D%22default%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
154+
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
155155
[XPK] Exiting XPK cleanly
156156
-->

recipes/Workload_create_super-slicing.md

Lines changed: 3 additions & 3 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 -n -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,13 +143,13 @@ 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.
150150
[XPK] Task: `Find cluster region or zone` is implemented by the following command not running since it is a dry run.
151151
gcloud container clusters list --project=golden-project --filter=name=golden-cluster --format="value(location)"
152152
[XPK] Follow your workload here: https://console.cloud.google.com/kubernetes/service/us-central1/golden-cluster/default/golden-workload/details?project=golden-project
153-
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.namespace_name%3D%22default%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
153+
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
154154
[XPK] Exiting XPK cleanly
155155
-->

recipes/Workload_create_with_output-manifest-file.md

Lines changed: 3 additions & 3 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 -n -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,13 +140,13 @@ 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.
147147
[XPK] Task: `Find cluster region or zone` is implemented by the following command not running since it is a dry run.
148148
gcloud container clusters list --project=golden-project --filter=name=golden-cluster --format="value(location)"
149149
[XPK] Follow your workload here: https://console.cloud.google.com/kubernetes/service/us-central1/golden-cluster/default/golden-workload/details?project=golden-project
150-
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.namespace_name%3D%22default%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
150+
[XPK] Follow your worker 0, slice 0 logs here: Adjust the pod name ([prefix]-slice-job-[slice_number]-[worker_number]) after clicking the url if you want other worker logs. https://console.cloud.google.com/logs/query;query=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22golden-project%22%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22golden-cluster%22%0Aresource.labels.pod_name%3A%22golden-workload-slice-job-0-0-%22%0Aseverity%3E%3DDEFAULT;storageScope=project;duration=P1D?project=golden-project
151151
[XPK] Exiting XPK cleanly
152152
-->

0 commit comments

Comments
 (0)