name: Create PersistentVolumeClaim in Kubernetes
inputs:
- {name: Name,         type: String}
- {name: Storage size, type: String, default: 1Gi}
- {name: Namespace,    type: String, default: default}
outputs:
- {name: Name,         type: String}
metadata:
  annotations:
    author: Alexey Volkov <alexey.volkov@ark-kun.com>
    canonical_location: 'https://raw.githubusercontent.com/Ark-kun/pipeline_components/master/components/kubernetes/Create_PersistentVolumeClaim/component.yaml'
implementation:
  container:
    image: bitnami/kubectl:1.17.17
    command:
    - bash
    - -exc
    - |
      name=$0
      storage_size=$1
      namespace=$2
      output_name_path=$3
      mkdir -p "$(dirname "$output_name_path")"
      object_path=$(mktemp)

      cat <<EOF >"$object_path"
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: $name
      spec:
        #storageClassName: standard
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: $storage_size
      EOF
      object_name=$(kubectl apply -f "$object_path" --namespace $namespace --output=name)
      object_name=${object_name##persistentvolumeclaim/}
      echo "$object_name" >"$output_name_path"

    - {inputValue: Name}
    - {inputValue: Storage size}
    - {inputValue: Namespace}
    - {outputPath: Name}
