|
| 1 | +# Full `oc adm release new` Command Structure |
| 2 | + |
| 3 | +Based on the code in `pkg/steps/release/create_release.go`, here's how the complete `oc adm release new` command is constructed. |
| 4 | + |
| 5 | +## Command Builder Function |
| 6 | + |
| 7 | +The command is built by `buildOcAdmReleaseNewCommand()` at **line 314-335** in `pkg/steps/release/create_release.go`. |
| 8 | + |
| 9 | +## Base Command Structure |
| 10 | + |
| 11 | +```bash |
| 12 | +oc adm release new \ |
| 13 | + --max-per-registry=32 \ |
| 14 | + -n <namespace> \ |
| 15 | + --from-image-stream <streamName> \ |
| 16 | + --to-image-base <cvo> \ |
| 17 | + --to-image <destination> \ |
| 18 | + --name <version> |
| 19 | +``` |
| 20 | + |
| 21 | +## Parameter Sources |
| 22 | + |
| 23 | +### 1. `--max-per-registry=32` |
| 24 | +- **Fixed value**: Always `32` |
| 25 | +- **Location**: Line 316 |
| 26 | + |
| 27 | +### 2. `-n <namespace>` |
| 28 | +- **Source**: `s.jobSpec.Namespace()` (the CI job namespace) |
| 29 | +- **Example**: `ci-op-abc123` or `ci-op-xyz789` |
| 30 | +- **Location**: Line 317 |
| 31 | + |
| 32 | +### 3. `--from-image-stream <streamName>` |
| 33 | +- **Source**: `api.ReleaseStreamFor(s.name)` (line 145) |
| 34 | +- **Logic**: |
| 35 | + - If `s.name == "latest"` → `"stable"` |
| 36 | + - Otherwise → `"stable-{s.name}"` (e.g., `"stable-initial"`, `"stable-4.21-quay"`) |
| 37 | +- **Location**: Line 318 |
| 38 | +- **Example values**: |
| 39 | + - For release name `"latest"`: `stable` |
| 40 | + - For release name `"initial"`: `stable-initial` |
| 41 | + - For release name `"4.21-quay"`: `stable-4.21-quay` |
| 42 | + |
| 43 | +### 4. `--to-image-base <cvo>` |
| 44 | +- **Source**: Cluster Version Operator pull spec resolved from the ImageStream |
| 45 | +- **Resolution**: `util.ResolvePullSpec(stable, "cluster-version-operator", true)` (line 152) |
| 46 | +- **Example**: `registry.build02.ci.openshift.org/ci-op-abc/stable:cluster-version-operator` |
| 47 | +- **Location**: Line 319 |
| 48 | + |
| 49 | +### 5. `--to-image <destination>` |
| 50 | +- **Source**: `fmt.Sprintf("%s:%s", releaseImageStreamRepo, s.name)` (line 171) |
| 51 | +- **Format**: `<releaseImageStreamRepo>:<releaseName>` |
| 52 | +- **Example**: `registry.build02.ci.openshift.org/ci-op-abc/release:latest` |
| 53 | +- **Location**: Line 320 |
| 54 | + |
| 55 | +### 6. `--name <version>` |
| 56 | +- **Source**: Generated version string (line 169) |
| 57 | +- **Format**: `{prefix}-{timestamp}-test-{namespace}-{releaseName}` |
| 58 | +- **Prefix logic**: |
| 59 | + - Default: `"0.0.1-0"` |
| 60 | + - If ImageStream has `ReleaseConfigAnnotation`: Uses resolved config name |
| 61 | +- **Timestamp**: `time.Now().UTC().Truncate(time.Second).Format("2006-01-02-150405")` |
| 62 | +- **Example**: `0.0.1-0-2024-01-15-143022-ci-op-abc-latest` |
| 63 | +- **Location**: Line 321 |
| 64 | + |
| 65 | +## Conditional Flags |
| 66 | + |
| 67 | +### `--keep-manifest-list` (for OpenShift 4.11+) |
| 68 | +- **Condition**: `hasMinimumVersion(config, 4, 11)` returns true |
| 69 | +- **Logic**: Parses `config.Name` as `major.minor` (e.g., "4.21" → major=4, minor=21) |
| 70 | +- **Added if**: `major > 4 || (major == 4 && minor >= 11)` |
| 71 | +- **Location**: Lines 331-333 |
| 72 | + |
| 73 | +### `--reference-mode=source` (for OpenShift 4.13+ with SourceTagReferencePolicy) |
| 74 | +- **Condition**: |
| 75 | + - `config.ReferencePolicy != nil` |
| 76 | + - `hasMinimumVersion(config, 4, 13)` returns true |
| 77 | + - `*config.ReferencePolicy == imagev1.SourceTagReferencePolicy` |
| 78 | +- **Location**: Lines 324-327 |
| 79 | + |
| 80 | +## Complete Example Commands |
| 81 | + |
| 82 | +### Example 1: OpenShift 4.21 (latest release, with keep-manifest-list) |
| 83 | + |
| 84 | +```bash |
| 85 | +oc adm release new \ |
| 86 | + --max-per-registry=32 \ |
| 87 | + -n ci-op-abc123 \ |
| 88 | + --from-image-stream stable \ |
| 89 | + --to-image-base registry.build02.ci.openshift.org/ci-op-abc123/stable:cluster-version-operator \ |
| 90 | + --to-image registry.build02.ci.openshift.org/ci-op-abc123/release:latest \ |
| 91 | + --name 0.0.1-0-2024-01-15-143022-ci-op-abc123-latest \ |
| 92 | + --keep-manifest-list |
| 93 | +``` |
| 94 | + |
| 95 | +### Example 2: OpenShift 4.21-quay (custom release name) |
| 96 | + |
| 97 | +```bash |
| 98 | +oc adm release new \ |
| 99 | + --max-per-registry=32 \ |
| 100 | + -n ci-op-abc123 \ |
| 101 | + --from-image-stream stable-4.21-quay \ |
| 102 | + --to-image-base registry.build02.ci.openshift.org/ci-op-abc123/stable-4.21-quay:cluster-version-operator \ |
| 103 | + --to-image registry.build02.ci.openshift.org/ci-op-abc123/release:4.21-quay \ |
| 104 | + --name 0.0.1-0-2024-01-15-143022-ci-op-abc123-4.21-quay \ |
| 105 | + --keep-manifest-list |
| 106 | +``` |
| 107 | + |
| 108 | +### Example 3: OpenShift 4.15 with SourceTagReferencePolicy |
| 109 | + |
| 110 | +```bash |
| 111 | +oc adm release new \ |
| 112 | + --max-per-registry=32 \ |
| 113 | + -n ci-op-abc123 \ |
| 114 | + --from-image-stream stable \ |
| 115 | + --to-image-base registry.build02.ci.openshift.org/ci-op-abc123/stable:cluster-version-operator \ |
| 116 | + --to-image registry.build02.ci.openshift.org/ci-op-abc123/release:latest \ |
| 117 | + --name 0.0.1-0-2024-01-15-143022-ci-op-abc123-latest \ |
| 118 | + --reference-mode=source \ |
| 119 | + --keep-manifest-list |
| 120 | +``` |
| 121 | + |
| 122 | +### Example 4: OpenShift 4.10 (no keep-manifest-list) |
| 123 | + |
| 124 | +```bash |
| 125 | +oc adm release new \ |
| 126 | + --max-per-registry=32 \ |
| 127 | + -n ci-op-abc123 \ |
| 128 | + --from-image-stream stable \ |
| 129 | + --to-image-base registry.build02.ci.openshift.org/ci-op-abc123/stable:cluster-version-operator \ |
| 130 | + --to-image registry.build02.ci.openshift.org/ci-op-abc123/release:latest \ |
| 131 | + --name 0.0.1-0-2024-01-15-143022-ci-op-abc123-latest |
| 132 | +``` |
| 133 | + |
| 134 | +## Command Execution Context |
| 135 | + |
| 136 | +The command is executed inside a Pod with: |
| 137 | + |
| 138 | +1. **Setup** (lines 189-199): |
| 139 | + - Sets up authentication via `oc registry login` |
| 140 | + - Uses Docker config from `/pull/.dockerconfigjson` if available |
| 141 | + |
| 142 | +2. **Retry Logic** (lines 201-214): |
| 143 | + - Retries up to 5 times with 60-second delays |
| 144 | + - Captures exit codes properly |
| 145 | + |
| 146 | +3. **Post-Execution** (lines 218-232): |
| 147 | + - Extracts release payload: `oc adm release extract --from=<destination> --to=${ARTIFACT_DIR}/release-payload-<name>` |
| 148 | + - Also retries up to 5 times |
| 149 | + |
| 150 | +## Code References |
| 151 | + |
| 152 | +- **Command builder**: `pkg/steps/release/create_release.go:314-335` |
| 153 | +- **Command execution**: `pkg/steps/release/create_release.go:188-236` |
| 154 | +- **Stream name resolution**: `pkg/api/graph.go:312-318` |
| 155 | +- **Version detection**: `pkg/steps/release/create_release.go:301-312` |
| 156 | +- **Test examples**: `pkg/steps/release/create_release_test.go:13-103` |
| 157 | + |
| 158 | +## How to Reference a Specific ImageStream (e.g., `app.ci/4.21-quay`) |
| 159 | + |
| 160 | +To reference a specific ImageStream in a different namespace (like `app.ci/4.21-quay` instead of `ocp/4.21`), you need to use the **`integration`** release type instead of `candidate`. |
| 161 | + |
| 162 | +### YAML Configuration |
| 163 | + |
| 164 | +Change your release configuration from: |
| 165 | + |
| 166 | +```yaml |
| 167 | +releases: |
| 168 | + latest: |
| 169 | + candidate: |
| 170 | + product: ocp |
| 171 | + stream: ci |
| 172 | + version: "4.21" |
| 173 | +``` |
| 174 | +
|
| 175 | +To: |
| 176 | +
|
| 177 | +```yaml |
| 178 | +releases: |
| 179 | + latest: |
| 180 | + integration: |
| 181 | + namespace: app.ci |
| 182 | + name: 4.21-quay |
| 183 | +``` |
| 184 | +
|
| 185 | +Or if you want to keep both: |
| 186 | +
|
| 187 | +```yaml |
| 188 | +releases: |
| 189 | + latest: |
| 190 | + candidate: |
| 191 | + product: ocp |
| 192 | + stream: ci |
| 193 | + version: "4.21" |
| 194 | + 4.21-quay: |
| 195 | + integration: |
| 196 | + namespace: app.ci |
| 197 | + name: 4.21-quay |
| 198 | +``` |
| 199 | +
|
| 200 | +### How It Works |
| 201 | +
|
| 202 | +1. **Snapshot Step** (`pkg/steps/release/snapshot.go:52-124`): |
| 203 | + - Reads the source ImageStream from `app.ci/4.21-quay` |
| 204 | + - Creates a snapshot ImageStream in the test namespace |
| 205 | + - The snapshot name is `ReleaseStreamFor(releaseName)`: |
| 206 | + - If release name is `"latest"` → snapshot is `stable` |
| 207 | + - If release name is `"4.21-quay"` → snapshot is `stable-4.21-quay` |
| 208 | + |
| 209 | +2. **Assemble Step** (`pkg/steps/release/create_release.go:145`): |
| 210 | + - Uses `ReleaseStreamFor(s.name)` to find the snapshot ImageStream in the test namespace |
| 211 | + - This becomes the `--from-image-stream` parameter in the `oc adm release new` command |
| 212 | + |
| 213 | +### Complete Example |
| 214 | + |
| 215 | +For a release named `4.21-quay` referencing `app.ci/4.21-quay`: |
| 216 | + |
| 217 | +**YAML:** |
| 218 | +```yaml |
| 219 | +releases: |
| 220 | + 4.21-quay: |
| 221 | + integration: |
| 222 | + namespace: app.ci |
| 223 | + name: 4.21-quay |
| 224 | +``` |
| 225 | + |
| 226 | +**Resulting Command:** |
| 227 | +```bash |
| 228 | +oc adm release new \ |
| 229 | + --max-per-registry=32 \ |
| 230 | + -n ci-op-abc123 \ |
| 231 | + --from-image-stream stable-4.21-quay \ |
| 232 | + --to-image-base registry.build02.ci.openshift.org/ci-op-abc123/stable-4.21-quay:cluster-version-operator \ |
| 233 | + --to-image registry.build02.ci.openshift.org/ci-op-abc123/release:4.21-quay \ |
| 234 | + --name 0.0.1-0-2024-01-15-143022-ci-op-abc123-4.21-quay \ |
| 235 | + --keep-manifest-list |
| 236 | +``` |
| 237 | + |
| 238 | +**Key Points:** |
| 239 | +- The `integration.namespace` and `integration.name` specify the **source** ImageStream (`app.ci/4.21-quay`) |
| 240 | +- The release name in the `releases` map determines the **snapshot** ImageStream name in the test namespace |
| 241 | +- The snapshot ImageStream name follows the pattern: `stable-{releaseName}` (or just `stable` if release name is `latest`) |
| 242 | +- Code references: |
| 243 | + - Integration handling: `pkg/defaults/defaults.go:223-233` |
| 244 | + - Snapshot creation: `pkg/steps/release/snapshot.go:56-124` |
| 245 | + - Integration type definition: `pkg/api/types.go:331-342` |
| 246 | + |
0 commit comments