|
| 1 | + |
| 2 | +<b>Pattern 1: Add complete, runnable examples in docs and example manifests by including required dependent resources (for example, Secrets or CRDs) with safe placeholder values so users can apply them out-of-the-box.</b> |
| 3 | + |
| 4 | +Example code before: |
| 5 | +``` |
| 6 | +# examples/orchestrator.yaml |
| 7 | +apiVersion: rhdh.redhat.com/v1alpha4 |
| 8 | +kind: Backstage |
| 9 | +metadata: |
| 10 | + name: orchestrator |
| 11 | +spec: |
| 12 | + application: |
| 13 | + extraEnvs: |
| 14 | + secrets: |
| 15 | + - name: backend-auth-secret |
| 16 | +# Secret referenced above is missing |
| 17 | +``` |
| 18 | + |
| 19 | +Example code after: |
| 20 | +``` |
| 21 | +# examples/orchestrator.yaml |
| 22 | +--- |
| 23 | +apiVersion: v1 |
| 24 | +kind: Secret |
| 25 | +metadata: |
| 26 | + name: backend-auth-secret |
| 27 | +stringData: |
| 28 | + BACKEND_SECRET: "dummy-not-secret" |
| 29 | +--- |
| 30 | +apiVersion: rhdh.redhat.com/v1alpha4 |
| 31 | +kind: Backstage |
| 32 | +metadata: |
| 33 | + name: orchestrator |
| 34 | +spec: |
| 35 | + application: |
| 36 | + extraEnvs: |
| 37 | + secrets: |
| 38 | + - name: backend-auth-secret |
| 39 | +``` |
| 40 | + |
| 41 | +<details><summary>Examples for relevant past discussions:</summary> |
| 42 | + |
| 43 | +- https://github.com/redhat-developer/rhdh-operator/pull/1567#discussion_r2315417933 |
| 44 | +- https://github.com/redhat-developer/rhdh-operator/pull/1219#discussion_r2163204987 |
| 45 | +</details> |
| 46 | + |
| 47 | + |
| 48 | +___ |
| 49 | + |
| 50 | +<b>Pattern 2: When introducing optional features controlled by CR fields, implement idempotent create-or-update logic, register required schemes, add RBAC, and gate behavior on CRD presence; also document enabling/disabling and lifecycle management.</b> |
| 51 | + |
| 52 | +Example code before: |
| 53 | +``` |
| 54 | +// creates ServiceMonitor with server-side apply (SSA) |
| 55 | +err := c.Patch(ctx, sm, client.Apply, applyOpts) |
| 56 | +// no scheme registration or RBAC for ServiceMonitor |
| 57 | +``` |
| 58 | + |
| 59 | +Example code after: |
| 60 | +``` |
| 61 | +// register monitoring v1 scheme and add RBAC for servicemonitors |
| 62 | +controllerutil.CreateOrUpdate(ctx, c, sm, func() error { |
| 63 | + sm.Spec = desiredSpec |
| 64 | + return controllerutil.SetControllerReference(owner, sm, scheme) |
| 65 | +}) |
| 66 | +// check CRD exists if needed; reconcile create/update/delete on spec.monitoring.enabled |
| 67 | +``` |
| 68 | + |
| 69 | +<details><summary>Examples for relevant past discussions:</summary> |
| 70 | + |
| 71 | +- https://github.com/redhat-developer/rhdh-operator/pull/1374#discussion_r2248149438 |
| 72 | +- https://github.com/redhat-developer/rhdh-operator/pull/1374#discussion_r2253372015 |
| 73 | +- https://github.com/redhat-developer/rhdh-operator/pull/1499#discussion_r2284826017 |
| 74 | +</details> |
| 75 | + |
| 76 | + |
| 77 | +___ |
| 78 | + |
| 79 | +<b>Pattern 3: Preserve autoscaling compatibility by omitting or commenting out hard-coded replicas in Deployment/StatefulSet templates and add explicit comments explaining the omission.</b> |
| 80 | + |
| 81 | +Example code before: |
| 82 | +``` |
| 83 | +spec: |
| 84 | + replicas: 1 |
| 85 | + template: |
| 86 | + spec: {} |
| 87 | +``` |
| 88 | + |
| 89 | +Example code after: |
| 90 | +``` |
| 91 | +spec: |
| 92 | + # replicas: 1 # Intentionally omitted to allow HPA or custom scaling control. |
| 93 | + template: |
| 94 | + spec: {} |
| 95 | +``` |
| 96 | + |
| 97 | +<details><summary>Examples for relevant past discussions:</summary> |
| 98 | + |
| 99 | +- https://github.com/redhat-developer/rhdh-operator/pull/1284#discussion_r2156758328 |
| 100 | +- https://github.com/redhat-developer/rhdh-operator/pull/1284#discussion_r2157238898 |
| 101 | +</details> |
| 102 | + |
| 103 | + |
| 104 | +___ |
| 105 | + |
| 106 | +<b>Pattern 4: Keep documentation synchronized with implementation changes, specifying versions, defaults, namespaces, and merge semantics to avoid user confusion when behavior evolves.</b> |
| 107 | + |
| 108 | +Example code before: |
| 109 | +``` |
| 110 | +# docs/configuration.md |
| 111 | +From version 0.7.0, dynamic plugins are overridden by the CR. |
| 112 | +``` |
| 113 | + |
| 114 | +Example code after: |
| 115 | +``` |
| 116 | +# docs/configuration.md |
| 117 | +Before 0.8.0 the Operator replaced defaults; since 0.8.0 it merges defaults with the user ConfigMap (non-deep merge). |
| 118 | +Resources are created in the same namespace as the Backstage CR unless stated otherwise. |
| 119 | +``` |
| 120 | + |
| 121 | +<details><summary>Examples for relevant past discussions:</summary> |
| 122 | + |
| 123 | +- https://github.com/redhat-developer/rhdh-operator/pull/1486#discussion_r2288776329 |
| 124 | +- https://github.com/redhat-developer/rhdh-operator/pull/1551#discussion_r2301210631 |
| 125 | +- https://github.com/redhat-developer/rhdh-operator/pull/1551#discussion_r2301214220 |
| 126 | +- https://github.com/redhat-developer/rhdh-operator/pull/1323#discussion_r2179583371 |
| 127 | +</details> |
| 128 | + |
| 129 | + |
| 130 | +___ |
| 131 | + |
| 132 | +<b>Pattern 5: Harden shell scripts by enabling strict modes, quoting variables and arrays, validating required env vars, avoiding brittle traps, and removing unused variables to satisfy ShellCheck and prevent runtime errors.</b> |
| 133 | + |
| 134 | +Example code before: |
| 135 | +``` |
| 136 | +#!/bin/bash |
| 137 | +for db in ${!allDB[@]}; do |
| 138 | + echo Copying database: $db |
| 139 | +done |
| 140 | +trap "rm -f $tmpFile" EXIT |
| 141 | +``` |
| 142 | + |
| 143 | +Example code after: |
| 144 | +``` |
| 145 | +#!/bin/bash |
| 146 | +set -euo pipefail |
| 147 | +: "${TO_PSW:?TO_PSW environment variable not set}" |
| 148 | +for db in "${allDB[@]}"; do |
| 149 | + echo "Copying database: ${db}" |
| 150 | +done |
| 151 | +trap 'rm -f "$tmpFile" || true' EXIT |
| 152 | +``` |
| 153 | + |
| 154 | +<details><summary>Examples for relevant past discussions:</summary> |
| 155 | + |
| 156 | +- https://github.com/redhat-developer/rhdh-operator/pull/1305#discussion_r2175117965 |
| 157 | +- https://github.com/redhat-developer/rhdh-operator/pull/1305#discussion_r2175123942 |
| 158 | +- https://github.com/redhat-developer/rhdh-operator/pull/1305#discussion_r2175338254 |
| 159 | +- https://github.com/redhat-developer/rhdh-operator/pull/1305#discussion_r2188582064 |
| 160 | +- https://github.com/redhat-developer/rhdh-operator/pull/1305#discussion_r2188591953 |
| 161 | +</details> |
| 162 | + |
| 163 | + |
| 164 | +___ |
0 commit comments