<!--
SPDX-FileCopyrightText: Red Hat

SPDX-License-Identifier: Apache-2.0
-->

# Preparing GitOps repository

**Prerequisites:** The O-Cloud Manager operator should be deployed on the hub cluster.
See [Environment Setup](./environment-setup.md).

## Repository layout

This guide describes the Git repository content required by the O‑Cloud Manager to deploy and configure a cluster. We recommend organizing the repo as follows. For concrete examples, see the sample content under [git-setup](../samples/git-setup/).

Recommended layout:

```text
git-root/
  clustertemplates/
    hardwareprofiles/                   # HardwareProfile CRs for hardware provisioning
    inventory/                          # BareMetalHost inventory for sites
    version_4.Y.Z/                      # Version matches the OCP version to be installed
      sno-ran-du/                       # Single-Node OpenShift (SNO)
        clusterinstance-defaults-*.yaml
        policytemplates-defaults-*.yaml
        pull-secret.yaml
        extra-manifest/
        ns.yaml
        sno-ran-du-v4-Y-Z-*.yaml
      3node-ran-du/                     # 3-node compact cluster (all masters)
        clusterinstance-defaults-*.yaml
        policytemplates-defaults-*.yaml
        pull-secret.yaml
        ns.yaml
        3node-ran-du-v4-Y-Z-*.yaml
      std-ran-du/                       # Standard cluster (3 masters + N workers)
        clusterinstance-defaults-*.yaml
        policytemplates-defaults-*.yaml
        pull-secret.yaml
        ns.yaml
        std-ran-du-v4-Y-Z-*.yaml
    version_4.Y.Z+1/                    # Optional upgrade content
  policytemplates/
    version_4.Y.Z/                      # Version matches the OCP version to be installed
      sno-ran-du/
        ns.yaml
        msc-binding.yaml
        sno-ran-du-pg-v4-Y-Z-*.yaml
      3node-ran-du/
        ns.yaml
        msc-binding.yaml
        3node-ran-du-pg-v4-Y-Z-*.yaml
      std-ran-du/
        ns.yaml
        msc-binding.yaml
        std-ran-du-pg-v4-Y-Z-*.yaml
      source-crs/                       # ZTP source CRs; keep in sync with OCP version
    version_4.Y.Z+1/                    # Optional upgrade content
```

Notes

* Keep content versioned by OCP release using the `version_4.Y.Z/` folders so templates and policies align with the target OCP.
* The content of the `extra-manifest` directory should be copied over from the [telco-reference extra-manifest](https://github.com/openshift-kni/telco-reference/tree/main/telco-ran/configuration/source-crs/extra-manifest) repo
or extracted from the [ztp-site-generate](https://catalog.redhat.com/software/containers/openshift4/ztp-site-generate-rhel8/6154c29fd2c7f84a4d2edca1) container.
  * ArgoCD will assemble all the extra-manifests into a ConfigMap.
* The content of the `source-crs` directory should be copied over from the [telco-reference source-crs](https://github.com/openshift-kni/telco-reference/tree/main/telco-ran/configuration/source-crs) repo
or extracted from the [ztp-site-generate](https://catalog.redhat.com/software/containers/openshift4/ztp-site-generate-rhel8/6154c29fd2c7f84a4d2edca1) container.
  * The ACM PGs will reference the source CRs to generate the ACM Policies that will be applied on the spoke cluster(s).
* Make sure to bring over the `extra-manifest` and `source-crs` corresponding to the OCP release provided in the ClusterTemplate CR.
* ACM policies must be created under the namespace `ztp-<cluster-template-namespace>`.
  The O-Cloud Manager uses this naming convention to locate the policies associated with
  a ClusterTemplate's namespace. See the [example](../samples/git-setup/policytemplates/version_4.Y.Z/sno-ran-du/ns.yaml).
* In the ACM PGs, set `policyAnnotations` to include the annotation `clustertemplates.clcm.openshift.io/templates` with a comma-separated
  list of ClusterTemplates that PG is associated with. Use the ClusterTemplate metadata.name for each entry. This annotation is propagated to
  each generated root Policy. It enables the O‑Cloud Manager to identify which root policies are associated with the
  ClusterTemplate used by a ProvisioningRequest, determine the expected child policies, and accurately detect when configuration
  is complete - ensuring correct provisioning status reporting during Day-2 policy configuration changes. See the [example](../samples/git-setup/policytemplates/version_4.Y.Z/sno-ran-du/sno-ran-du-pg-v4-Y-Z-v1.yaml).

## SNO Full DU (Distributed Unit) profile

For configuring an SNO with a full DU profile according to the [RAN RDS](https://docs.redhat.com/en/documentation/openshift_container_platform/4.21/html/scalability_and_performance/telco-ran-du-ref-design-specs#telco-ran-du-reference-configuration-crs),
the following main samples can be used as a starting example:

* [ClusterInstance defaults ConfigMap](../samples/git-setup/clustertemplates/version_4.Y.Z/sno-ran-full-du/clusterinstance-defaults-full-du-v1.yaml)
* [PolicyTemplate defaults ConfigMap](../samples/git-setup/clustertemplates/version_4.Y.Z/sno-ran-full-du/policytemplates-defaults-full-du-v1.yaml)
* [ClusterTemplate](../samples/git-setup/clustertemplates/version_4.Y.Z/sno-ran-full-du/sno-ran-full-du-v4-Y-Z-1.yaml)
* [Full DU profile ACM Policy Generator](../samples/git-setup/policytemplates/version_4.Y.Z/sno-ran-full-du/sno-ran-full-du-pg-v4-Y-Z-v1.yaml)

## Preparation of ArgoCD applications

Preparing the ArgoCD applications for provisioning clusters through the O-Cloud Manager is similar to the [ZTP approach](https://github.com/openshift-kni/telco-reference/tree/main/telco-ran/configuration/argocd#preparation-of-hub-cluster-for-ztp), with the following **distinctions**:

* The source path for the ArgoCD Application [clusters](https://github.com/openshift-kni/telco-reference/blob/main/telco-ran/configuration/argocd/deployment/clusters-app.yaml) should point to the [clustertemplates](../samples/git-setup/clustertemplates) directory.
Additionally, configure `spec.ignoreDifferences` for the `BareMetalHost` kind to ignore the following fields:

```yaml
spec:
  ignoreDifferences:
  - group: metal3.io
    jsonPointers:
    - /spec/preprovisioningNetworkDataName
    - /spec/online
    kind: BareMetalHost
```

* The source path for the ArgoCD Application [policies](https://github.com/openshift-kni/telco-reference/blob/main/telco-ran/configuration/argocd/deployment/policies-app.yaml) should point to the [policytemplates](../samples/git-setup/policytemplates) directory.

* The following **additional CRDs** should be added to the [AppProject](https://github.com/openshift-kni/telco-reference/blob/main/telco-ran/configuration/argocd/deployment/app-project.yaml), under `spec.clusterResourceWhitelist`:

```yaml
  - group: clcm.openshift.io
    kind: ClusterTemplate
  - group: clcm.openshift.io
    kind: HardwareProfile
```
