# Copyright 2024 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.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- parallelstore-pv.yaml
- parallelstore-pvc.yaml
- parallelstore-testing.yaml
- fio-config.yaml

images:
- name: fio
  newName: us-docker.pkg.dev/PROJECT_ID/research-images/fio # Replace with your desired registry
  newTag: latest



configMapGenerator:
- literals:
  - STORAGECLASS=STORAGECLASS
  - PROJECT_ID=PROJECT_ID
  - LOCATION=LOCATION
  - INSTANCE_NAME=INSTANCE_NAME
  - STORAGE_SIZE=STORAGE_SIZE
  - ACCESS_POINTS=ACCESS_POINTS
  - NETWORK=research-vpc
  - MOUNT_LOCALITY=node
  - COMPLETIONS=1000
  - PARALLELISM=1000
  name: parallelstore-vars

replacements:
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.STORAGE_SIZE
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.capacity.storage
  - select:
      kind: PersistentVolumeClaim
    fieldPaths:
    - spec.resources.requests.storage

- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.ACCESS_POINTS
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.csi.volumeAttributes.accessPoints

- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.NETWORK
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.csi.volumeAttributes.network

- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.MOUNT_LOCALITY
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.csi.volumeAttributes.mountLocality

# Volume handle specific replacement
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.PROJECT_ID
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.csi.volumeHandle
    options:
      delimiter: '/'
      index: 0
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.LOCATION
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.csi.volumeHandle
    options:
      delimiter: '/'
      index: 1
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.INSTANCE_NAME
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.csi.volumeHandle
    options:
      delimiter: '/'
      index: 2


- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.STORAGECLASS
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.storageClassName
    options:
      delimiter: '-'
      index: 0
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.STORAGECLASS
  targets:
  - select:
      kind: PersistentVolumeClaim
    fieldPaths:
    - spec.storageClassName
    options:
      delimiter: '-'
      index: 0

- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.INSTANCE_NAME
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - metadata.name
    options:
      delimiter: '-'
      index: 0
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.INSTANCE_NAME
  targets:
  - select:
      kind: PersistentVolumeClaim
    fieldPaths:
    - metadata.name
    options:
      delimiter: '-'
      index: 0

- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.INSTANCE_NAME
  targets:
  - select:
      kind: Job
    fieldPaths:
    - spec.template.spec.volumes.[name=parallelstore-volume].persistentVolumeClaim.claimName
    options:
      delimiter: '-'
      index: 0
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.COMPLETIONS
  targets:
  - select:
      kind: Job
    fieldPaths:
    - spec.completions
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.PARALLELISM
  targets:
  - select:
      kind: Job
    fieldPaths:
    - spec.parallelism
