apiVersion: turtles-capi.cattle.io/v1alpha1
kind: CAPIProvider
metadata:
  name: fleet
  namespace: '{{ .Values.rancherTurtles.namespace }}'
  annotations:
    "helm.sh/hook": "post-install, post-upgrade"
    "helm.sh/hook-weight": "2"
    "helm.sh/resource-policy": keep
spec:
  enableAutomaticUpdate: true
  type: addon
  additionalManifests:
    name: fleet-addon-config
    namespace: '{{ .Values.rancherTurtles.namespace }}'
{{- if or (index .Values "cluster-api-operator" "cluster-api" "fleet" "addon" "fetchConfig" "url") (index .Values "cluster-api-operator" "cluster-api" "fleet" "addon" "fetchConfig" "selector") }}
  fetchConfig:
    {{- if index .Values "cluster-api-operator" "cluster-api" "fleet" "addon" "fetchConfig" "url" }}
    url: {{ index .Values "cluster-api-operator" "cluster-api" "fleet" "addon" "fetchConfig" "url" }}
    {{- end }}
    {{- if index .Values "cluster-api-operator" "cluster-api" "fleet" "addon" "fetchConfig" "selector" }}
    selector: {{ index .Values "cluster-api-operator" "cluster-api" "fleet" "addon" "fetchConfig" "selector" }}
    {{- end }}
{{- end }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: fleet-addon-config
  namespace: '{{ .Values.rancherTurtles.namespace }}'
  annotations:
    "helm.sh/hook": "post-install, post-upgrade"
    "helm.sh/hook-weight": "2"
    "helm.sh/resource-policy": keep
data:
  manifests: |-
    apiVersion: addons.cluster.x-k8s.io/v1alpha1
    kind: FleetAddonConfig
    metadata:
      name: fleet-addon-config
    spec:
      config:
        featureGates:
          configMap:
            ref:
              kind: ConfigMap
              apiVersion: v1
              name: rancher-config
              namespace: cattle-system
          experimentalOciStorage: true
          experimentalHelmOps: true
      clusterClass:
        patchResource: true
        setOwnerReferences: true
      cluster:
        agentNamespace: cattle-fleet-system
        applyClassGroup: true
        patchResource: true
        setOwnerReferences: true
        hostNetwork: true
        selector:
          matchLabels:
            cluster-api.cattle.io/rancher-auto-import: "true"
          matchExpressions:
            - key: cluster-api.cattle.io/disable-fleet-auto-import
              operator: DoesNotExist
        namespaceSelector:
          matchLabels:
            cluster-api.cattle.io/rancher-auto-import: "true"
          matchExpressions:
            - key: cluster-api.cattle.io/disable-fleet-auto-import
              operator: DoesNotExist
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: cappf-controller-psa
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: fleet-controller-psa
    subjects:
    - kind: ServiceAccount
      name: caapf-controller-manager
      namespace: {{ .Values.rancherTurtles.namespace }}
