|
| 1 | +# CoCo Pattern — AI Coding Assistant Guidance |
| 2 | + |
| 3 | +This is a [Validated Pattern](https://validatedpatterns.io/) for deploying confidential containers (CoCo) on OpenShift. |
| 4 | +This file provides rules and context for any AI coding assistant working in this repository. |
| 5 | + |
| 6 | +## Critical Rules |
| 7 | + |
| 8 | +- **DO NOT** edit anything under `/common/`. It is a read-only Git subtree from the upstream validated patterns framework. |
| 9 | +- **DO NOT** commit secrets, credentials, or private keys. `values-secret.yaml.template` is a template only. |
| 10 | +- **DO NOT** use Kustomize. This project uses Helm exclusively. |
| 11 | +- **DO NOT** create charts with `apiVersion: v1`. Use `apiVersion: v2` (Helm 3+). |
| 12 | +- **DO NOT** place cloud-provider-specific logic in chart templates. Use `/overrides/` via `sharedValueFiles` instead. |
| 13 | +- **DO NOT** hardcode secrets in templates. Use External Secrets Operator with vault paths (see `charts/hub/trustee/templates/dynamic-eso.yaml` for reference). |
| 14 | + |
| 15 | +## Feature Development Precedence Order |
| 16 | + |
| 17 | +Use the **first** approach that fits your requirement: |
| 18 | + |
| 19 | +1. **Helm charts** — Declarative Kubernetes resources in `/charts/`, deployed by ArgoCD. Preferred for installing operators, configuring CRDs, and creating Kubernetes resources. |
| 20 | +2. **ACM policies** — Red Hat Advanced Cluster Management policies for propagating configuration from hub to spoke clusters and enforcing multi-cluster governance. Reference: `charts/hub/sandbox-policies/templates/`. |
| 21 | +3. **Imperative framework (Ansible)** — Playbooks in `/ansible/`, executed as Kubernetes Jobs on a 10-minute schedule. **Must be idempotent.** Use for API calls, runtime data lookups, and multi-step orchestration that cannot be expressed declaratively. Register playbooks in `clusterGroup.imperative.jobs` as an ordered list. |
| 22 | +4. **Out-of-band scripts** — `/scripts/` or `/rhdp/`. Last resort for one-time setup or local development tooling. These are not managed by GitOps. |
| 23 | + |
| 24 | +## Project Structure |
| 25 | + |
| 26 | +```text |
| 27 | +├── ansible/ # Ansible playbooks (imperative jobs) |
| 28 | +├── charts/ |
| 29 | +│ ├── all/ |
| 30 | +│ │ └── letsencrypt/ # Shared across cluster groups |
| 31 | +│ ├── coco-supported/ |
| 32 | +│ │ ├── baremetal/ # Bare-metal TDX configuration |
| 33 | +│ │ ├── hello-openshift/ # Sample workloads |
| 34 | +│ │ ├── kbs-access/ # KBS access verification workload |
| 35 | +│ │ └── sandbox/ # Sandboxed containers runtime |
| 36 | +│ └── hub/ |
| 37 | +│ ├── lvm-storage/ # LVM storage for bare-metal |
| 38 | +│ ├── sandbox-policies/ # ACM policies (hub → spoke) |
| 39 | +│ └── trustee/ # Trustee / KBS |
| 40 | +├── common/ # READ-ONLY — upstream framework subtree |
| 41 | +├── overrides/ # Cloud-provider value overrides |
| 42 | +│ ├── values-AWS.yaml |
| 43 | +│ ├── values-Azure.yaml |
| 44 | +│ └── values-IBMCloud.yaml |
| 45 | +├── rhdp/ # Red Hat Demo Platform tooling |
| 46 | +├── scripts/ # Utility scripts |
| 47 | +├── values-global.yaml # Global configuration |
| 48 | +├── values-simple.yaml # Cluster group: simple |
| 49 | +├── values-baremetal.yaml # Cluster group: baremetal |
| 50 | +├── values-trusted-hub.yaml # Cluster group: trusted-hub |
| 51 | +├── values-untrusted-spoke.yaml # Cluster group: untrusted-spoke |
| 52 | +└── values-secret.yaml.template # Secrets template (never commit filled-in copy) |
| 53 | +``` |
| 54 | + |
| 55 | +## Companion Chart Repositories |
| 56 | + |
| 57 | +Several charts in this repository have companion repositories for independent versioning and reuse. Develop and test in this repository first (charts deploy via `path:`), then sync changes to the companion repository. |
| 58 | + |
| 59 | +| Local Path | Companion Repository | Purpose | |
| 60 | +|---|---|---| |
| 61 | +| `charts/hub/trustee/` | `trustee-chart` | Trustee / KBS on hub | |
| 62 | +| `charts/hub/sandbox-policies/` | `sandboxed-policies-chart` | ACM policies hub → spoke | |
| 63 | +| `charts/coco-supported/sandbox/` | `sandboxed-containers-chart` | Sandboxed runtime on spoke | |
| 64 | + |
| 65 | +Large features may require coordinated changes across multiple companion repos. References are org-agnostic — contributors should fork all relevant repos as needed. |
| 66 | + |
| 67 | +## Cluster Groups |
| 68 | + |
| 69 | +Set via `main.clusterGroupName` in `values-global.yaml`. |
| 70 | + |
| 71 | +| Cluster Group | Values File | Role | Description | |
| 72 | +|---|---|---|---| |
| 73 | +| `simple` | `values-simple.yaml` | Hub (single cluster) | All components on one cluster | |
| 74 | +| `baremetal` | `values-baremetal.yaml` | Hub (single cluster) | TDX + LVM storage on bare metal | |
| 75 | +| `trusted-hub` | `values-trusted-hub.yaml` | Multi-cluster hub | Trustee + ACM policies | |
| 76 | +| `untrusted-spoke` | `values-untrusted-spoke.yaml` | Multi-cluster spoke | Sandbox runtime + workloads | |
| 77 | + |
| 78 | +## Values File Hierarchy |
| 79 | + |
| 80 | +Merge order (last wins): |
| 81 | + |
| 82 | +1. Chart defaults (`charts/<group>/<chart>/values.yaml`) |
| 83 | +2. `values-global.yaml` |
| 84 | +3. `values-<clustergroup>.yaml` |
| 85 | +4. `/overrides/values-{{ clusterPlatform }}.yaml` (via `sharedValueFiles`) |
| 86 | +5. `values-secret.yaml` (runtime only, never committed) |
| 87 | + |
| 88 | +Key conventions: |
| 89 | + |
| 90 | +- Global settings go under the `global:` key in `values-global.yaml`. |
| 91 | +- Subscriptions go under `clusterGroup.subscriptions:` in the cluster group values file. |
| 92 | +- Applications go under `clusterGroup.applications:` in the cluster group values file. |
| 93 | +- Local charts use `path:` (e.g., `path: charts/hub/trustee`). Shared framework charts use `chart:` + `chartVersion:`. |
| 94 | +- Imperative jobs go under `clusterGroup.imperative.jobs:` as an **ordered list** (not a hash — hashes lose ordering in Helm). |
| 95 | + |
| 96 | +## Helm Chart Conventions |
| 97 | + |
| 98 | +- Use `apiVersion: v2`. Place charts in `charts/<cluster-group>/<chart-name>/`. |
| 99 | +- Use ArgoCD sync-wave annotations to control deployment ordering. |
| 100 | +- Use `ExternalSecret` resources to pull secrets from vault. Reference: `charts/hub/trustee/templates/dynamic-eso.yaml`. |
| 101 | +- Use `.Values.global.clusterPlatform` for platform-conditional logic only when overrides files are insufficient. |
| 102 | +- Reference patterns: |
| 103 | + - ESO integration: `charts/hub/trustee/templates/dynamic-eso.yaml` |
| 104 | + - Template helpers: `charts/coco-supported/hello-openshift/templates/_helpers.tpl` |
| 105 | + |
| 106 | +## Ansible Playbook Conventions |
| 107 | + |
| 108 | +- Place playbooks in `/ansible/`. They **must be idempotent**. |
| 109 | +- Use `connection: local`, `hosts: localhost`, `become: false`. |
| 110 | +- Use `kubernetes.core.k8s` and `kubernetes.core.k8s_info` modules for cluster interaction. |
| 111 | +- Register playbooks in the cluster group values file under `clusterGroup.imperative.jobs` with `name`, `playbook`, `verbosity`, and `timeout` fields. |
| 112 | + |
| 113 | +## Git Workflow |
| 114 | + |
| 115 | +- **Fork-first**: ArgoCD reconciles against your fork. Clone and push to your own fork. |
| 116 | +- **Conventional commits**: Enforced by commitlint (`@commitlint/config-conventional`). |
| 117 | +- **Branch-based deployment**: The branch of your local checkout determines the ArgoCD deployment target. |
| 118 | +- **Changes require commit + push** to take effect — ArgoCD watches the remote. |
| 119 | + |
| 120 | +## Commands Reference |
| 121 | + |
| 122 | +All commands run via `./pattern.sh make <target>`: |
| 123 | + |
| 124 | +| Command | Purpose | |
| 125 | +|---|---| |
| 126 | +| `install` | Install the pattern and load secrets | |
| 127 | +| `show` | Render the starting template without installing | |
| 128 | +| `preview-all` | Preview all applications across cluster groups | |
| 129 | +| `validate-schema` | Validate values files against JSON schema | |
| 130 | +| `validate-cluster` | Validate cluster prerequisites | |
| 131 | +| `super-linter` | Run super-linter locally | |
| 132 | +| `load-secrets` | Load secrets into the configured backend | |
| 133 | +| `uninstall` | Uninstall the pattern | |
| 134 | + |
| 135 | +See the readme for secrets backend configuration, RHDP environment variables, and additional maintenance commands. |
| 136 | + |
| 137 | +## Validation and CI |
| 138 | + |
| 139 | +CI runs the following checks on pull requests: |
| 140 | + |
| 141 | +- **JSON schema validation** — values files validated against `common/clustergroup` schema |
| 142 | +- **Super Linter** — multi-language linting |
| 143 | +- **Conventional PR title lint** — PR titles must follow conventional commit format |
| 144 | + |
| 145 | +Run locally before pushing: |
| 146 | + |
| 147 | +```bash |
| 148 | +./pattern.sh make preview-all |
| 149 | +./pattern.sh make validate-schema |
| 150 | +``` |
0 commit comments