Skip to content

Commit 9fff25a

Browse files
authored
Merge pull request #1466 from 14rcole/stoneintg-1464-implementation
feat(stoneintg-1464) create snapshots from componentgroups
2 parents b066b40 + 2eabb6b commit 9fff25a

30 files changed

Lines changed: 3036 additions & 264 deletions

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ run: manifests generate fmt vet ## Run a controller from your host.
131131
go run ./cmd/main.go
132132

133133
.PHONY: img-build
134-
img-build: test ## Build container image with the manager.
134+
#img-build: test ## Build container image with the manager.
135+
img-build:
135136
$(CONT_ENGINE) build -t ${IMG} .
136137

137138
.PHONY: img-push

api/v1beta2/componentgroup_types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ type ComponentState struct {
135135
// +optional
136136
Version string `json:"version"`
137137

138+
// Git URL for the component. Needed by Release service. Can be used along
139+
// with LastPromotedCommit to access the code that has been promoted
140+
// +optional
141+
URL string `json:"url"`
142+
138143
// Location of the last image for this Component to be promoted. If no
139144
// image has been promoted then the field will be blank
140145
// +optional
@@ -154,7 +159,8 @@ type ComponentState struct {
154159
// ComponentGroupStatus defines the observed state of ComponentGroup
155160
type ComponentGroupStatus struct {
156161
// Conditions is an array of the ComponentGroup's status conditions
157-
Conditions []metav1.Condition `json:"conditions"`
162+
// +optional
163+
Conditions []metav1.Condition `json:"conditions,omitempty"`
158164

159165
// The list of recently promoted Components which the integration service
160166
// uses to create Snapshots

config/crd/bases/appstudio.redhat.com_componentgroups.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ spec:
248248
name:
249249
description: Name of the Component
250250
type: string
251+
url:
252+
description: |-
253+
Git URL for the component. Needed by Release service. Can be used along
254+
with LastPromotedCommit to access the code that has been promoted
255+
type: string
251256
version:
252257
description: |-
253258
Version of the Component. Only required if multiple version of the same
@@ -257,8 +262,6 @@ spec:
257262
- name
258263
type: object
259264
type: array
260-
required:
261-
- conditions
262265
type: object
263266
type: object
264267
served: true

gitops/snapshot.go

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const (
7676
// SnapshotTestScenarioLabel contains the name of the Snapshot test scenario.
7777
SnapshotTestScenarioLabel = "test.appstudio.openshift.io/scenario"
7878

79-
// SnapshotTestScenarioLabel contains json data with test results of the particular snapshot
79+
// SnapshotTestsStatusAnnotation contains json data with test results of the particular snapshot
8080
SnapshotTestsStatusAnnotation = "test.appstudio.openshift.io/status"
8181

8282
// (Deprecated) SnapshotPRLastUpdate contains timestamp of last time PR was updated
@@ -133,6 +133,9 @@ const (
133133
// ApplicationNameLabel contains the name of the application
134134
ApplicationNameLabel = AppstudioLabelPrefix + "/application"
135135

136+
// ComponentGroupNameLabel contains the name of the ComponentGroup
137+
ComponentGroupNameLabel = AppstudioLabelPrefix + "/component-group"
138+
136139
// SnapshotComponentType is the type of Snapshot which was created for a single component build.
137140
SnapshotComponentType = "component"
138141

@@ -227,10 +230,10 @@ const (
227230
// GitRefBranchPrefix is the git prefix denoting a reference is a branch
228231
GitRefBranchPrefix = "refs/heads/"
229232

230-
//AppStudioTestSucceededCondition is the condition for marking if the AppStudio Tests succeeded for the Snapshot.
233+
// AppStudioTestSucceededCondition is the condition for marking if the AppStudio Tests succeeded for the Snapshot.
231234
AppStudioTestSucceededCondition = "AppStudioTestSucceeded"
232235

233-
//LegacyTestSucceededCondition is the condition for marking if the AppStudio Tests succeeded for the Snapshot.
236+
// LegacyTestSucceededCondition is the condition for marking if the AppStudio Tests succeeded for the Snapshot.
234237
LegacyTestSucceededCondition = "HACBSStudioTestSucceeded"
235238

236239
// AppStudioIntegrationStatusCondition is the condition for marking the AppStudio integration status of the Snapshot.
@@ -244,7 +247,6 @@ const (
244247

245248
// SnapshotAddedToGlobalCandidateListCondition is the condition for marking if Snapshot's component was added to
246249
// the global candidate list.
247-
// Checking statusCondition has been replaced by checking annotation test.appstudio.openshift.io/added-to-global-candidate-list now but this statusCondition is still kept
248250
SnapshotAddedToGlobalCandidateListCondition = "AddedToGlobalCandidateList"
249251

250252
// AppStudioTestSucceededConditionSatisfied is the reason that's set when the AppStudio tests succeed.
@@ -262,46 +264,46 @@ const (
262264
// AppStudioIntegrationStatusErrorOccured is the reason that's set when the AppStudio integration gets into an error state.
263265
AppStudioIntegrationStatusErrorOccured = "ErrorOccured"
264266

265-
//AppStudioIntegrationStatusInProgress is the reason that's set when the AppStudio tests gets into an in progress state.
267+
// AppStudioIntegrationStatusInProgress is the reason that's set when the AppStudio tests gets into an in progress state.
266268
AppStudioIntegrationStatusInProgress = "InProgress"
267269

268-
//AppStudioIntegrationStatusFinished is the reason that's set when the AppStudio tests finish.
270+
// AppStudioIntegrationStatusFinished is the reason that's set when the AppStudio tests finish.
269271
AppStudioIntegrationStatusFinished = "Finished"
270272

271-
//AppStudioIntegrationStatusCancelled is the reason that's set when the AppStudio tests pipelinerun gets cancelled.
273+
// AppStudioIntegrationStatusCancelled is the reason that's set when the AppStudio tests pipelinerun gets cancelled.
272274
AppStudioIntegrationStatusCancelled = "CancelledRunFinally"
273275

274-
// This annotation helps track PipelineRuns that were stopped before completion, enabling better auditability and observability.
276+
// PRGroupCancelledAnnotation helps track PipelineRuns that were stopped before completion.
275277
PRGroupCancelledAnnotation = PipelinesAsCodePrefix + "/cancelled"
276278

277-
// the statuses needed to report to GiHub when creating check run or commit status, see doc
278-
// https://docs.github.com/en/rest/guides/using-the-rest-api-to-interact-with-checks?apiVersion=2022-11-28
279-
// https://docs.github.com/en/free-pro-team@latest/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
280-
//IntegrationTestStatusPendingGithub is the status reported to github when integration test is in a queue
279+
// IntegrationTestStatusPendingGithub is the status reported to github when integration test is in a queue
281280
IntegrationTestStatusPendingGithub = "pending"
282281

283-
//IntegrationTestStatusSuccessGithub is the status reported to github when integration test succeed
282+
// IntegrationTestStatusSuccessGithub is the status reported to github when integration test succeed
284283
IntegrationTestStatusSuccessGithub = "success"
285284

286-
//IntegrationTestStatusFailureGithub is the status reported to github when integration test fail
285+
// IntegrationTestStatusFailureGithub is the status reported to github when integration test fail
287286
IntegrationTestStatusFailureGithub = "failure"
288287

289-
//IntegrationTestStatusErrorGithub is the status reported to github when integration test experience error
288+
// IntegrationTestStatusErrorGithub is the status reported to github when integration test experience error
290289
IntegrationTestStatusErrorGithub = "error"
291290

292-
//IntegrationTestStatusInProgressGithub is the status reported to github when integration test is in progress
291+
// IntegrationTestStatusInProgressGithub is the status reported to github when integration test is in progress
293292
IntegrationTestStatusInProgressGithub = "in_progress"
294293

295-
//IntegrationTestStatusCancelledGithub is the status reported to github when integration test is cancelled
294+
// IntegrationTestStatusCancelledGithub is the status reported to github when integration test is cancelled
296295
IntegrationTestStatusCancelledGithub = "cancelled"
297296

298-
//IntegrationTestStatusNeutralGithub is the status reported to github when integration test is neutral
297+
// IntegrationTestStatusNeutralGithub is the status reported to github when integration test is neutral
299298
IntegrationTestStatusNeutralGithub = "neutral"
300299

300+
// ComponentNameForGroupSnapshot is the component name used for group snapshots
301301
ComponentNameForGroupSnapshot = "pr group"
302302

303+
// FailedToCreateGroupSnapshotMsg is the message when group snapshot creation fails
303304
FailedToCreateGroupSnapshotMsg = "Failed to create group snapshot for pr group"
304305

306+
// GroupSnapshotCreationFailureReported is the message when group snapshot creation failure is reported to git provider
305307
GroupSnapshotCreationFailureReported = "group snapshot creation failure is reported to git provider"
306308

307309
// Annotation that tells the integration service to skip checks for whether a build or snapshot is superseded
@@ -310,18 +312,11 @@ const (
310312
// PRStatusMerged indicates that the PR has been merged
311313
PRStatusMerged = "merged"
312314

315+
// Success is the success status value
313316
Success = "Success"
314-
// AddedToGlobalCandidateListAnnotation is the annotation for marking if Snapshot/build PLR's component was added to
315-
// the global candidate list.
316-
AddedToGlobalCandidateListAnnotation = "test.appstudio.openshift.io/added-to-global-candidate-list"
317317

318-
// maxPrefixLength is the maximum length of the prefix for the snapshot name
319-
// When a suffix is used for collision handling, reduce by 3 to accommodate the 2-char suffix and extra dash
320-
// Format: {prefix}-{YYYYMMDD}-{HHMMSS}-{mmm}[-{suffix}]
321-
// Without suffix: 43 + 1 + 8 + 1 + 6 + 1 + 3 = 63 chars
322-
// With suffix: 40 + 1 + 8 + 1 + 6 + 1 + 3 + 1 + 2 = 63 chars
323-
maxPrefixLength = 43
324-
maxPrefixLengthWithSuffix = 40 // 43 - 3 (2 for suffix + 1 for extra dash)
318+
// AddedToGlobalCandidateListAnnotation is the annotation for marking if Snapshot/build PLR's component was added to the global candidate list.
319+
AddedToGlobalCandidateListAnnotation = "test.appstudio.openshift.io/added-to-global-candidate-list"
325320

326321
// GitCommentPolicyAnnotation is the annotation to control git comment policy for the component
327322
GitCommentPolicyAnnotation = "test.appstudio.openshift.io/comment_strategy"
@@ -334,6 +329,16 @@ var (
334329
SnapshotComponentLabel = tektonconsts.ComponentNameLabel
335330
)
336331

332+
const (
333+
// maxPrefixLength is the maximum length of the prefix for the snapshot name
334+
// When a suffix is used for collision handling, reduce by 3 to accommodate the 2-char suffix and extra dash
335+
// Format: {prefix}-{YYYYMMDD}-{HHMMSS}-{mmm}[-{suffix}]
336+
// Without suffix: 43 + 1 + 8 + 1 + 6 + 1 + 3 = 63 chars
337+
// With suffix: 40 + 1 + 8 + 1 + 6 + 1 + 3 + 1 + 2 = 63 chars
338+
maxPrefixLength = 43
339+
maxPrefixLengthWithSuffix = 40 // 43 - 3 (2 for suffix + 1 for extra dash)
340+
)
341+
337342
// ComponentSnapshotInfo contains data about the component snapshots' info in group snapshot
338343
type ComponentSnapshotInfo struct {
339344
// Namespace
@@ -827,7 +832,7 @@ func IsSnapshotCreatedByPACMergeQueueEvent(snapshot *applicationapiv1alpha1.Snap
827832
}
828833

829834
// IsSnapshotCreatedByPACPushEvent checks if a snapshot has label PipelineAsCodeEventTypeLabel and with push value
830-
// it the label doesn't exist for some manual snapshot
835+
// if the label doesn't exist for some manual snapshot
831836
func IsSnapshotCreatedByPACPushEvent(snapshot *applicationapiv1alpha1.Snapshot) bool {
832837
return !IsSnapshotCreatedByPACMergeQueueEvent(snapshot) && !IsGroupSnapshot(snapshot) &&
833838
(metadata.HasLabelWithValue(snapshot, PipelineAsCodeEventTypeLabel, PipelineAsCodePushType) ||
@@ -1135,7 +1140,9 @@ func ResetSnapshotStatusConditions(ctx context.Context, adapterClient client.Cli
11351140

11361141
// CopySnapshotLabelsAndAnnotations coppies labels and annotations from build pipelineRun or tested snapshot
11371142
// into regular snapshot
1138-
func CopySnapshotLabelsAndAnnotations(application *applicationapiv1alpha1.Application, snapshot *applicationapiv1alpha1.Snapshot, componentName string, source *metav1.ObjectMeta, prefixes []string) {
1143+
// ObjectMeta: metav1.ObjectMeta{
1144+
// TODO: replace 'object' with 'componentGroup' after application is deprecated. Also delete Application bool
1145+
func CopySnapshotLabelsAndAnnotations(object *metav1.ObjectMeta, snapshot *applicationapiv1alpha1.Snapshot, componentName string, source *metav1.ObjectMeta, prefixes []string, objectIsApplication bool) {
11391146

11401147
if snapshot.Labels == nil {
11411148
snapshot.Labels = map[string]string{}
@@ -1147,7 +1154,12 @@ func CopySnapshotLabelsAndAnnotations(application *applicationapiv1alpha1.Applic
11471154
snapshot.Labels[SnapshotTypeLabel] = SnapshotComponentType
11481155

11491156
snapshot.Labels[SnapshotComponentLabel] = componentName
1150-
snapshot.Labels[ApplicationNameLabel] = application.Name
1157+
if objectIsApplication {
1158+
snapshot.Labels[ApplicationNameLabel] = object.Name
1159+
} else {
1160+
// the object is a ComponentGroup
1161+
snapshot.Labels[ComponentGroupNameLabel] = object.Name
1162+
}
11511163

11521164
// Copy PAC annotations/labels from source(tested snapshot or pipelinerun) to snapshot.
11531165
_ = metadata.CopyLabelsWithPrefixReplacement(source, &snapshot.ObjectMeta, "pipelinesascode.tekton.dev", PipelinesAsCodePrefix)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.25.0
44

55
require (
66
codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v3 v3.0.0
7-
github.com/konflux-ci/application-api v0.0.0-20260120144946-dc5c619fb3f9
7+
github.com/konflux-ci/application-api v0.0.0-20260213151620-9ac61f5d7ca0
88
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127115143-b5207b335f8b
99
github.com/konflux-ci/operator-toolkit v0.0.0-20251118152634-b4f41f073069
1010
github.com/konflux-ci/release-service v0.0.0-20260127184035-c36c56a3c440

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3J
343343
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
344344
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
345345
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
346-
github.com/konflux-ci/application-api v0.0.0-20260120144946-dc5c619fb3f9 h1:B4WWEeSQziHKStmvb7kT041KF6yeKEmvYzjUUWBue9U=
347-
github.com/konflux-ci/application-api v0.0.0-20260120144946-dc5c619fb3f9/go.mod h1:948Z+a1IbfRT0RtoHzWWSN9YEucSbMJTHaMhz7dVICc=
346+
github.com/konflux-ci/application-api v0.0.0-20260213151620-9ac61f5d7ca0 h1:txe2MpWDtNi3EJpIk7JCjC2QKUOMJnJfLEjJGusc0ds=
347+
github.com/konflux-ci/application-api v0.0.0-20260213151620-9ac61f5d7ca0/go.mod h1:948Z+a1IbfRT0RtoHzWWSN9YEucSbMJTHaMhz7dVICc=
348348
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127115143-b5207b335f8b h1:NoriO1KRc+7d2/JA07JizqxP0LlA2oJdD5AuQOvEIjE=
349349
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127115143-b5207b335f8b/go.mod h1:WVMHU9A2464s/vjH1xOTm4LJDD4xP+VlEiU+KM0gkSU=
350350
github.com/konflux-ci/operator-toolkit v0.0.0-20251118152634-b4f41f073069 h1:nT8V7Bva2LclJhWahIQYSNiYRHcmB22H6v4DD/FD7QU=

helpers/component_group.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2026 Red Hat Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
package helpers
16+
17+
import "github.com/konflux-ci/integration-service/api/v1beta2"
18+
19+
func GetComponentGroupNames(componentGroups *[]v1beta2.ComponentGroup) []string {
20+
names := []string{}
21+
for _, componentGroup := range *componentGroups {
22+
names = append(names, componentGroup.Name)
23+
}
24+
return names
25+
}

0 commit comments

Comments
 (0)