# 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:
  - cleanup-disk.yaml
  - configmap.yaml
  - ../../base

images:
- name: fio
  newName: us-docker.pkg.dev/fsi-research-1/research-images/fio
  newTag: latest

configMapGenerator:
- literals:
  - JOB_NAME=fio-test-parallelstore-sidecar-3k
  - PROJECT_ID=fsi-research-1
  - LOCATION=us-central1-b
  - INSTANCE_NAME=parallelstore-us-central1-b
  - STORAGE_SIZE=27000Gi
  - ACCESS_POINTS=10.93.0.3, 10.93.0.4, 10.93.0.2
  - NETWORK=research-vpc
  - MOUNT_LOCALITY=node
  - TEST_DIR=test_files
  - MOUNT_PATH=/data
  name: parallelstore-vars

replacements:
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.JOB_NAME
  targets:
  - select:
      kind: Job
    fieldPaths:
    - metadata.name
- 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.TEST_DIR
  targets:
  - select:
      kind: Job
    fieldPaths:
    - spec.template.spec.containers.[name=cleanup].env.[name=OUTPUT_DIR].value
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.MOUNT_PATH
  targets:
  - select:
      kind: Job
    fieldPaths:
    - spec.template.spec.containers.[name=cleanup].volumeMounts.[name=parallelstore-volume].mountPath
- 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
- 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.LOCATION
  targets:
  - select:
      kind: PersistentVolume
    fieldPaths:
    - metadata.name
    options:
      delimiter: '-'
      index: 2
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.LOCATION
  targets:
  - select:
      kind: PersistentVolumeClaim
    fieldPaths:
    - metadata.name
    options:
      delimiter: '-'
      index: 2
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.LOCATION
  targets:
  - select:
      kind: PersistentVolumeClaim
    fieldPaths:
    - spec.storageClassName
    options:
      delimiter: '-'
      index: 2
  - select:
      kind: PersistentVolume
    fieldPaths:
    - spec.storageClassName
    options:
      delimiter: '-'
      index: 2
- source:
    kind: ConfigMap
    name: parallelstore-vars
    fieldPath: data.LOCATION
  targets:
  - select:
      kind: Job
    fieldPaths:
    - spec.template.spec.volumes.[name=parallelstore-volume].persistentVolumeClaim.claimName
    options:
      delimiter: '-'
      index: 2
