Skip to content

Commit 31dd601

Browse files
authored
Add flag to pass the private image repository secret name (#523)
* fix issue #491 Signed-off-by: Piotr Pawłowski <[email protected]> --------- Signed-off-by: Piotr Pawłowski <[email protected]>
1 parent 414a6e1 commit 31dd601

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.github/workflows/reusable_workload_tests.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030

3131
env:
3232
WORKLOAD_NAME: xpktest-build-${{ github.run_attempt }}
33+
PRIVATE_IMAGE_WORKLOAD_NAME: xpktest-build-priv-${{ github.run_attempt }}
3334
PATHWAYS_WORKLOAD_NAME: xpkpw-build-${{ github.run_attempt }}
3435

3536
jobs:
@@ -83,8 +84,24 @@ jobs:
8384
run: python3 xpk.py workload list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} --wait-for-job-completion $PATHWAYS_WORKLOAD_NAME --timeout 300
8485
- name: List out the workloads on the cluster
8586
run: python3 xpk.py workload list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}}
87+
- name: Create a kubectl secret to use with private images
88+
run: |
89+
kubectl create secret docker-registry gcr-key \
90+
--docker-server=${{secrets.DOCKER_REPO_SERVER}}ubuntu2004 \
91+
--docker-username=_json_key \
92+
--docker-password='${{secrets.GCP_SA_KEY}}' \
93+
--docker-email='${{secrets.GCP_SA_EMAIL}}'
94+
- name: Run workload with private image
95+
run: python xpk.py workload create --cluster ${{inputs.cluster-name}} --workload $PRIVATE_IMAGE_WORKLOAD_NAME --command "echo foo" --tpu-type=${{inputs.tpu-type}} --num-slices=1 --zone=${{inputs.zone}} --docker-image=${{secrets.DOCKER_REPO_SERVER}}ubuntu2004 --docker-image-pull-secret=gcr-key
96+
- name: Wait for private image workload completion and confirm it succeeded
97+
run: python3 xpk.py workload list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} --wait-for-job-completion $PRIVATE_IMAGE_WORKLOAD_NAME --timeout 300
98+
- name: Delete kubectl secret
99+
if: always()
100+
run: kubectl delete secret gcr-key
86101
- name: Run xpk info
87102
run: python3 xpk.py info --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} | tee output.txt | grep -P "^(?=.*QUEUE)(?=.*PENDING_WORKLOADS)(?=.*ADMITTED_WORKLOADS)(?=.*1x${{inputs.tpu-type}}:google.com/tpu)(?=.*cpu-user:cpu)(?=.*cpu-user:memory)" || (echo 'Invalid command output' && cat output.txt && exit 1)
103+
- name: Delete the private image workload on the cluster
104+
run: python3 xpk.py workload delete --workload $PRIVATE_IMAGE_WORKLOAD_NAME --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}}
88105
- name: Delete the workload on the cluster
89106
run: python3 xpk.py workload delete --workload $WORKLOAD_NAME --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}}
90107
- name: Delete the Pathways workload on the cluster

src/xpk/commands/workload.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
{storage_annotations}
126126
spec:
127127
schedulerName: {args.scheduler}
128+
imagePullSecrets:
129+
- name: {args.docker_image_pull_secret}
128130
restartPolicy: Never
129131
{affinity}
130132
nodeSelector:
@@ -177,6 +179,8 @@
177179
{gpu_scheduler}
178180
priorityClassName: {args.priority}
179181
restartPolicy: Never
182+
imagePullSecrets:
183+
- name: {args.docker_image_pull_secret}
180184
hostNetwork: true
181185
dnsPolicy: ClusterFirstWithHostNet
182186
terminationGracePeriodSeconds: {args.termination_grace_period_seconds}
@@ -220,6 +224,8 @@
220224
spec:
221225
priorityClassName: {args.priority}
222226
restartPolicy: Never
227+
imagePullSecrets:
228+
- name: {args.docker_image_pull_secret}
223229
dnsPolicy: ClusterFirstWithHostNet
224230
terminationGracePeriodSeconds: {args.termination_grace_period_seconds}
225231
serviceAccountName: {service_account}

src/xpk/parser/workload.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,14 @@ def add_shared_workload_docker_image_arguments(args_parsers):
728728
' directly by the xpk workload.'
729729
),
730730
)
731+
custom_parser.add_argument(
732+
'--docker-image-pull-secret',
733+
type=str,
734+
help=(
735+
'Name of the secret that will be used to pull image from'
736+
' private repository'
737+
),
738+
)
731739

732740

733741
def add_shared_workload_create_tensorboard_arguments(args_parsers):

0 commit comments

Comments
 (0)