-
Notifications
You must be signed in to change notification settings - Fork 87
120 lines (117 loc) · 6.96 KB
/
reusable_storage_create.yaml
File metadata and controls
120 lines (117 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
on:
workflow_call:
inputs:
cluster-name:
type: string
required: true
device-type:
description: 'Device Type'
required: false
default: 'n2-standard-64-1'
type: string
zone:
type: string
required: true
storage-type: # gcpfilestore or gcsfuse
required: false
type: string
storage-command: # attach or create
required: true
default: 'attach'
type: string
storage-name:
required: true
type: string
secrets:
GCP_SA_KEY:
required: true
BUCKET_NAME:
required: true
permissions:
contents: read
jobs:
storage-create:
name: "${{inputs.storage-type}}-${{inputs.storage-command}}"
runs-on: [ubuntu-22.04]
env:
STORAGE_WRITE_WORKLOAD: "${{inputs.storage-type}}-${{inputs.storage-command}}-write-workload"
STORAGE_READ_WORKLOAD: "${{inputs.storage-type}}-${{inputs.storage-command}}-read-workload"
STORAGE_DELETE_WORKLOAD: "${{inputs.storage-type}}-${{inputs.storage-command}}-delete-workload"
steps:
- name: Validate storage-type
run: |
if [[ "${{ inputs.storage-type }}" != "gcpfilestore" && "${{ inputs.storage-type }}" != "gcsfuse" ]]; then
echo "Error: storage-type must be 'gcpfilestore' or 'gcsfuse'"
exit 1
fi
- name: Validate storage-command
run: |
if [[ "${{ inputs.storage-command }}" != "attach" && "${{ inputs.storage-command }}" != "create" ]]; then
echo "Error: storage-command must be 'attach' or 'create'"
exit 1
fi
- uses: actions/download-artifact@v4
with:
name: custom-scripts
- name: Setup environment
uses: ./.github/actions/setup-test-env
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: Check xpk installation
run: xpk version
- name: Attach auto-mount GCS FUSE Storage instance
if: inputs.storage-command == 'attach' && inputs.storage-type == 'gcsfuse'
run: |
xpk storage attach ${{inputs.storage-name}} --cluster=${{inputs.cluster-name}} --zone=${{inputs.zone}} --type=${{inputs.storage-type}} \
--auto-mount=true --mount-point='/${{inputs.storage-type}}-test-mount-point' --readonly=false --size=1 --bucket=${{secrets.BUCKET_NAME}} --mount-options rename-dir-limit=10000 --prefetch-metadata
- name: Create auto-mount GCP Filestore Storage instance
if: inputs.storage-command == 'create' && inputs.storage-type == 'gcpfilestore'
run: |
xpk storage create ${{inputs.storage-name}} --cluster=${{inputs.cluster-name}} --zone=${{inputs.zone}} --type=${{inputs.storage-type}} \
--auto-mount=true --vol=vol1 --size=1024 --tier=BASIC_HDD --mount-point='/${{inputs.storage-type}}-test-mount-point' --readonly=false
- name: Attach an existing GCP Filestore Storage instance
if: inputs.storage-command == 'attach' && inputs.storage-type == 'gcpfilestore'
run: |
xpk storage attach ${{inputs.storage-name}} --cluster=${{inputs.cluster-name}} --zone=${{inputs.zone}} --type=${{inputs.storage-type}} \
--auto-mount=true --vol=vol1 --mount-point='/${{inputs.storage-type}}-test-mount-point' --readonly=false
- name: List and verify existing Storages
run: xpk storage list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} | tee output.txt | grep ${{inputs.storage-name}} || (echo 'No storage found' && exit 143)
- name: Verify Persistent Volume mount options
if: inputs.storage-command == 'attach' && inputs.storage-type == 'gcsfuse'
run: kubectl get pv ${{inputs.storage-name}}-pv -oyaml | grep rename-dir-limit=10000 || (echo 'Invalid storage mount options' && exit 143)
- name: Verify that metadata pre-population is enabled
if: inputs.storage-command == 'attach' && inputs.storage-type == 'gcsfuse'
run: |
kubectl get pv ${{inputs.storage-name}}-pv -oyaml | grep 'gcsfuseMetadataPrefetchOnMount: "true"' || (echo 'Metadata pre-population was not enabled' && exit 143)
- name: Run workload to write file on filestore
run: xpk workload create --workload $STORAGE_WRITE_WORKLOAD --num-slices=1 --docker-image='marketplace.gcr.io/google/ubuntu2004' --command "mkdir -p /${{inputs.storage-type}}-test-mount-point/$RANDOM_SEED/ && echo 'Test text message' > /${{inputs.storage-type}}-test-mount-point/$RANDOM_SEED/test.txt || (echo 'Writing to filestore failed' && exit 143)" --cluster ${{inputs.cluster-name}} --device-type=${{inputs.device-type}} --zone ${{inputs.zone}}
- name: Wait for writer workload completion and confirm it succeeded
run: xpk workload list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} --wait-for-job-completion $STORAGE_WRITE_WORKLOAD --timeout 300
- name: Delete the writer workload on the cluster
if: always()
run: xpk workload delete --workload $STORAGE_WRITE_WORKLOAD --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}}
- name: Run workload to read file on filestore
run : xpk workload create --workload $STORAGE_READ_WORKLOAD --command "grep 'Test text message' /${{inputs.storage-type}}-test-mount-point/$RANDOM_SEED/test.txt || (echo 'Reading from filestore failed' && exit 143)" --cluster ${{inputs.cluster-name}} --device-type=${{inputs.device-type}} --zone ${{inputs.zone}}
- name: Wait for reader workload completion and confirm it succeeded
run: xpk workload list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} --wait-for-job-completion $STORAGE_READ_WORKLOAD --timeout 300
- name: Delete the reader workload on the cluster
run: xpk workload delete --workload $STORAGE_READ_WORKLOAD --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}}
- name: Run workload to delete file on filestore
run : xpk workload create --workload $STORAGE_DELETE_WORKLOAD --command "rm -rf /${{inputs.storage-type}}-test-mount-point/$RANDOM_SEED/test.txt || exit 143" --num-slices=1 --cluster ${{inputs.cluster-name}} --device-type=${{inputs.device-type}} --zone ${{inputs.zone}}
- name: Wait for delete workload completion and confirm it succeeded
run: xpk workload list --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}} --wait-for-job-completion $STORAGE_DELETE_WORKLOAD --timeout 300
- name: Delete the delete workload on the cluster
run: xpk workload delete --workload $STORAGE_DELETE_WORKLOAD --cluster ${{inputs.cluster-name}} --zone=${{inputs.zone}}