[[- define "camelCase" -]]
[[- $input := . -]]
[[- $parts := split "_" $input -]]
[[- $camel := "" -]]
[[- range $index, $part := $parts -]]
  [[- if eq $index 0 -]]
    [[- $camel = lower $part -]]
  [[- else -]]
    [[- $camel = printf "%s%s" $camel (title (lower $part)) -]]
  [[- end -]]
[[- end -]]
[[- $camel -]]
[[- end -]]

[[- if .Generate ]]
global:
  registry: [[ .Global.Registry ]]
  repository: [[ .Global.Repository ]]
  [[- if .Global.NodeSelector ]]
  nodeSelector:
    [[- range $key, $value := .Global.NodeSelector ]]
    [[ $key ]]: [[ $value ]]
    [[- end ]]
  [[- else ]]
  nodeSelector: {}
  [[- end ]]

[[- range $component := .Components ]]
[[ $component.Name ]]:
  replicas: [[ $component.Replicas ]]
  image:
    registry: [[ $component.Image.Registry ]]
    repository: [[ $component.Image.Repository ]]
    name: [[ $component.Image.Name ]]
    tag: [[ $component.Image.Tag ]]
    imagePullPolicy: [[ $component.Image.ImagePullPolicy ]]
[[- if $component.Ports]]
  ports:
[[- range $port := $component.Ports ]]
    - name: [[ $port.Name ]]
      containerPort: [[ $port.ContainerPort ]]
      protocol: [[ $port.Protocol ]]
[[- end ]]
[[- end]]
  resources:
    requests:
      cpu: "[[ $component.Resources.Requests.CPU ]]"
      memory: "[[ $component.Resources.Requests.Memory ]]"
    limits:
      cpu: "[[ $component.Resources.Limits.CPU ]]"
      memory: "[[ $component.Resources.Limits.Memory ]]"
  probes:
    liveness:
      type: [[ $component.Probes.Liveness.Type ]]
      config:
        path: [[ $component.Probes.Liveness.Config.Path ]]
        port: [[ $component.Probes.Liveness.Config.Port ]]
    readiness:
      type: [[ $component.Probes.Readiness.Type ]]
      config:
        path: [[ $component.Probes.Readiness.Config.Path ]]
        port: [[ $component.Probes.Readiness.Config.Port ]]
  services:
  [[- range $service := $component.Services ]]
    - name: [[ $service.Name ]]
      type: [[ $service.Type ]]
      port: [[ $service.Port ]]
      targetPort: [[ $service.TargetPort ]]
  [[- end ]]
  ingresses:
  [[- range $ingress := $component.Ingresses ]]
    - name: [[ $ingress.Name ]]
      host: [[ $ingress.Host ]]
      class: [[ $ingress.Class ]]
      rules:
      [[- range $rule := $ingress.Rules ]]
        - path: [[ $rule.Path ]]
          pathType: [[ $rule.PathType ]]
          backend:
            service:
              name: [[ $rule.Backend.Service.Name ]]
              port:
                number: [[ $rule.Backend.Service.Port.Number ]]
      [[- end ]]
      tls:
        exists: [[ $ingress.TLS.Exists ]]
        [[- if $ingress.TLS.IssuerRef ]]
        issuerRef:
          name: [[ $ingress.TLS.IssuerRef.Name ]]
          kind: [[ $ingress.TLS.IssuerRef.Kind ]]
        [[- end ]]
        name: [[ $ingress.TLS.Name ]]
  [[- end ]]
  configs:
  [[- range $config := $component.Configs ]]
    [[- if eq $config.Type "environment-secret" ]]
      [[- range $data := $config.Data ]]
    [[ $data.Name | camelCase ]]: [[ $data.Value | quote ]]
      [[- end ]]
    [[- end ]]
  [[- end ]]
[[- end ]]
[[- end ]]