This commit is contained in:
병준 박 2025-04-10 09:22:57 +00:00
parent 7e5cab8a97
commit f78ccdff65

View File

@ -17,6 +17,13 @@ spec:
description: | description: |
The requested size of the PVC (e.g., "1Gi", "5Gi"). The requested size of the PVC (e.g., "1Gi", "5Gi").
- name: pvcStorageClass
type: string
default: ""
description: |
The name of the StorageClass to use. Leave empty to use the default storage class.
results: results:
- name: pvcName - name: pvcName
description: | description: |
@ -29,15 +36,13 @@ spec:
#!/bin/sh #!/bin/sh
set -e set -e
echo "pvcEnable: $(params.pvcEnable)"
if [ "$(params.pvcEnable)" = "true" ]; then if [ "$(params.pvcEnable)" = "true" ]; then
# Generate a random PVC name
RAND=$(head /dev/urandom | tr -dc a-z0-9 | head -c 6) RAND=$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)
PVC_NAME="before-pvc-${RAND}" PVC_NAME="before-pvc-${RAND}"
echo "Creating PVC: ${PVC_NAME}" echo "Creating PVC: ${PVC_NAME}"
# Apply PVC manifest # Start writing the PVC YAML
cat <<EOF | kubectl apply -f - cat <<EOF > /tmp/pvc.yaml
apiVersion: v1 apiVersion: v1
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
metadata: metadata:
@ -51,10 +56,18 @@ spec:
volumeMode: Filesystem volumeMode: Filesystem
EOF EOF
# Output the PVC name as a Task result # Append storageClassName if provided
if [ "$(params.storageClass)" != "" ]; then
echo " storageClassName: $(params.storageClass)" >> /tmp/pvc.yaml
fi
# Apply PVC
kubectl apply -f /tmp/pvc.yaml
# Write result
echo -n "${PVC_NAME}" > $(results.pvcName.path) echo -n "${PVC_NAME}" > $(results.pvcName.path)
echo "PVC creation complete: ${PVC_NAME}" echo "PVC created: ${PVC_NAME}"
else else
echo "PVC creation skipped (pvcEnable=false)" echo "PVC creation skipped (pvcEnable=false)"
echo -n "" > $(results.pvcName.path) echo -n "" > $(results.pvcName.path)
fi fi