# Flux Operator resources — ResourceSetInputProviders feed into ResourceSets
# ResourceSetInputProvider/github-branches ─┬─► ResourceSet/per-branch-envs
# ResourceSetInputProvider/cluster-inventory ┴─► ResourceSet/cluster-configs (multi-input)
apiVersion: fluxcd.controlplane.io/v1
kind: ResourceSetInputProvider
metadata:
  name: github-branches
  namespace: flux-resources
  annotations:
    fluxcd.controlplane.io/reconcileEvery: "30s"
  labels: {app.kubernetes.io/managed-by: flux9s-dev}
spec:
  type: GitHubBranch
  url: https://github.com/fluxcd/flux2
  secretRef:
    name: github-token
---
apiVersion: fluxcd.controlplane.io/v1
kind: ResourceSetInputProvider
metadata:
  name: cluster-inventory
  namespace: flux-resources
  annotations:
    fluxcd.controlplane.io/reconcileEvery: "1m"
  labels: {app.kubernetes.io/managed-by: flux9s-dev}
spec:
  type: GitLabBranch
  url: https://gitlab.com/fluxcd/flux2
  secretRef:
    name: gitlab-token
---
apiVersion: fluxcd.controlplane.io/v1
kind: ResourceSet
metadata:
  name: per-branch-envs
  namespace: flux-resources
  labels: {app.kubernetes.io/managed-by: flux9s-dev}
spec:
  inputsFrom:
    - kind: ResourceSetInputProvider
      name: github-branches
  resources:
    - apiVersion: v1
      kind: ConfigMap
      metadata:
        name: branch-${{ inputs.branch }}
        namespace: flux-resources
      data:
        branch: ${{ inputs.branch }}
---
apiVersion: fluxcd.controlplane.io/v1
kind: ResourceSet
metadata:
  name: cluster-configs
  namespace: flux-resources
  labels: {app.kubernetes.io/managed-by: flux9s-dev}
spec:
  inputsFrom:
    - kind: ResourceSetInputProvider
      name: github-branches
    - kind: ResourceSetInputProvider
      name: cluster-inventory
  resources:
    - apiVersion: v1
      kind: ConfigMap
      metadata:
        name: cluster-${{ inputs.region }}
        namespace: flux-resources
      data:
        region: ${{ inputs.region }}
