Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MOCKGEN := $(abspath $(TOOLS_BIN_DIR)/mockgen)
YQ := $(abspath $(TOOLS_BIN_DIR)/yq)
VERIFY_API_DEPS := $(abspath $(TOOLS_BIN_DIR)/verify-api-deps)
CRD_SCHEMA_CHECK := $(abspath $(TOOLS_BIN_DIR)/crd-schema-check)
FIND_PUSH_PIPELINERUN := $(abspath $(TOOLS_BIN_DIR)/find-push-pipelinerun)

CODESPELL_VER := 2.4.1
CODESPELL_BIN := codespell
Expand Down Expand Up @@ -183,6 +184,12 @@ $(VERIFY_API_DEPS): $(TOOLS_DIR)/go.mod # Build verify-api-deps tool
$(CRD_SCHEMA_CHECK): $(TOOLS_DIR)/go.mod # Build crd-schema-check tool
cd $(TOOLS_DIR); $(GO) build -o $(BIN_DIR)/crd-schema-check ./crd-schema-check

$(FIND_PUSH_PIPELINERUN): $(TOOLS_DIR)/go.mod # Build find-push-pipelinerun tool
cd $(TOOLS_DIR); $(GO) build -o $(BIN_DIR)/find-push-pipelinerun ./find-push-pipelinerun

.PHONY: find-push-pipelinerun
find-push-pipelinerun: $(FIND_PUSH_PIPELINERUN) ## Build the find-push-pipelinerun tool.

.PHONY: generate
generate: $(MOCKGEN)
@echo "Cleaning stale mock files..."
Expand Down
52 changes: 52 additions & 0 deletions docs/content/contribute/konflux-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,58 @@ hack/tools/scripts/find_task_version_by_digest.sh clair-scan \

Prerequisites: `skopeo`, `jq`

## Track post-merge build and release pipelines

Your PR just merged and you need to know: did the push build complete?
Have the images been released to acm-d or registry.redhat.io? Which
PipelineRuns are still in progress?

**Tool:** `hack/tools/find-push-pipelinerun/`

Finds the on-push PipelineRuns triggered by a merged PR's commit SHA.
Falls back to KubeArchive when the PipelineRuns have already been
archived (which happens quickly). Optionally tracks the downstream
release pipeline across both `crt-redhat-acm-tenant` (Releases) and
`rhtap-releng-tenant` (release PipelineRuns).

```bash
# Build:
make find-push-pipelinerun

# Show push PipelineRuns for a merged PR:
hack/tools/bin/find-push-pipelinerun 8908

# Filter to a specific Konflux Component (the appstudio.openshift.io/component
# label on PipelineRuns and Releases — e.g., hypershift-operator-main,
# hypershift-release-mce-50, hypershift-cli-mce-50):
hack/tools/bin/find-push-pipelinerun 8908 hypershift-operator

# Also show release pipeline status and destination images:
hack/tools/bin/find-push-pipelinerun --release 8908

# Poll until everything completes:
hack/tools/bin/find-push-pipelinerun --release --watch 8908

# Works with full URLs and owner/repo#number syntax too:
hack/tools/bin/find-push-pipelinerun --release https://github.com/openshift/hypershift/pull/8908

# Or run directly without pre-building:
(cd hack/tools && go run ./find-push-pipelinerun/ --release 8908)
```

The `--release` flag shows:

- **Releases** — the Release resources created from the build Snapshot,
with their release plan, status, and expected destination image
(`repo@sha256:digest` derived from the ReleasePlan mapping and the
Snapshot's source digest).
- **Release PipelineRuns** — the `managed-*` PipelineRuns in the
`rhtap-releng-tenant` namespace that execute the release (push to
registry, sign, create advisory, etc.).

Prerequisites: valid kubeconfig for the Konflux cluster. Set `GITHUB_TOKEN` for
private repos or to avoid GitHub API rate limits.

## Test tag pipeline changes

You're modifying the tag pipeline definition in `.tekton/` (e.g., adding a
Expand Down
52 changes: 52 additions & 0 deletions docs/content/reference/aggregated-docs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

243 changes: 243 additions & 0 deletions hack/tools/find-push-pipelinerun/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
package main

import (
"fmt"
"io"
"sort"
"strings"
"text/tabwriter"
)

const logURLAnnotation = "pipelinesascode.tekton.dev/log-url"

var (
pipelineRunTerminalStatuses = map[string]bool{
"Completed": true, "Failed": true, "Succeeded": true, "Error": true,
}
releaseTerminalStatuses = map[string]bool{
"Succeeded": true, "Failed": true, "Error": true, "Rejected": true,
}
)

// HasPending returns true if any PipelineRun has a non-terminal status.
func HasPending(prs []PipelineRun) bool {
for _, pr := range prs {
if !pipelineRunTerminalStatuses[pipelineRunStatus(pr)] {
return true
}
}
return false
}

// HasPendingReleases returns true if any Release has a non-terminal status.
func HasPendingReleases(releases []Release) bool {
for _, rel := range releases {
if !releaseTerminalStatuses[releaseStatus(rel)] {
return true
}
}
return false
}
Comment on lines +13 to +40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== format.go =="
nl -ba hack/tools/find-push-pipelinerun/format.go | sed -n '1,120p'

echo
echo "== watch loop usages =="
rg -n "HasPending\(|HasPendingReleases\(|WatchBuildPipeline|WatchReleasePipeline|pipelineRunTerminalStatuses|releaseTerminalStatuses" hack/tools/find-push-pipelinerun -n

echo
echo "== surrounding watch.go =="
nl -ba hack/tools/find-push-pipelinerun/watch.go | sed -n '1,220p'

Repository: openshift/hypershift

Length of output: 214


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== format.go =="
cat -n hack/tools/find-push-pipelinerun/format.go | sed -n '1,120p'

echo
echo "== watch loop usages =="
rg -n "HasPending\\(|HasPendingReleases\\(|WatchBuildPipeline|WatchReleasePipeline|pipelineRunTerminalStatuses|releaseTerminalStatuses" hack/tools/find-push-pipelinerun

echo
echo "== watch.go =="
cat -n hack/tools/find-push-pipelinerun/watch.go | sed -n '1,240p'

Repository: openshift/hypershift

Length of output: 10767


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== status helpers =="
rg -n "func pipelineRunStatus|func releaseStatus|Succeeded|Reason|Condition" hack/tools/find-push-pipelinerun/*.go

echo
echo "== relevant slices of format.go =="
sed -n '120,260p' hack/tools/find-push-pipelinerun/format.go | cat -n

echo
echo "== format tests around HasPending =="
sed -n '100,290p' hack/tools/find-push-pipelinerun/format_test.go | cat -n

Repository: openshift/hypershift

Length of output: 16571


Expand the PipelineRun terminal set. Any terminal reason missing from pipelineRunTerminalStatuses is treated as pending, so WatchBuildPipeline and the PipelineRun phase of WatchReleasePipeline can keep polling forever.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hack/tools/find-push-pipelinerun/format.go` around lines 13 - 40, The
PipelineRun terminal status set in pipelineRunTerminalStatuses is incomplete, so
HasPending treats some finished runs as pending and can cause WatchBuildPipeline
and the PipelineRun path in WatchReleasePipeline to poll forever. Update the
terminal status map to include any additional terminal PipelineRun reasons used
by pipelineRunStatus, and keep HasPending relying on that expanded set so
finished runs are no longer reported as pending.


// FilterByComponent filters PipelineRuns whose name starts with the component prefix.
func FilterByComponent(prs []PipelineRun, component string) []PipelineRun {
var filtered []PipelineRun
for _, pr := range prs {
if strings.HasPrefix(pr.Metadata.Name, component) {
filtered = append(filtered, pr)
}
}
return filtered
}

// FilterReleasesByComponent filters Releases by the appstudio.openshift.io/component label prefix.
func FilterReleasesByComponent(releases []Release, component string) []Release {
var filtered []Release
for _, rel := range releases {
comp := rel.Metadata.Labels["appstudio.openshift.io/component"]
if strings.HasPrefix(comp, component) {
filtered = append(filtered, rel)
}
}
return filtered
}

// FormatPipelineRuns writes a table of PipelineRuns to w.
// Returns false if there are no PipelineRuns to format.
func FormatPipelineRuns(w io.Writer, prs []PipelineRun) bool {
if len(prs) == 0 {
return false
}

sort.Slice(prs, func(i, j int) bool {
return prs[i].Metadata.CreationTimestamp < prs[j].Metadata.CreationTimestamp
})

tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
fmt.Fprintln(tw, "NAME\tSTATUS\tCREATED\tURL\tIMAGE")
for _, pr := range prs {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n",
pr.Metadata.Name,
pipelineRunStatus(pr),
pr.Metadata.CreationTimestamp,
pr.Metadata.Annotations[logURLAnnotation],
pipelineRunImage(pr),
)
}
tw.Flush()
return true
}

// FormatReleases writes a table of Releases to w.
// Returns false if there are no Releases to format.
func FormatReleases(w io.Writer, releases []Release) bool {
if len(releases) == 0 {
return false
}

sort.Slice(releases, func(i, j int) bool {
return releases[i].Metadata.CreationTimestamp < releases[j].Metadata.CreationTimestamp
})

tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
fmt.Fprintln(tw, "NAME\tPLAN\tCOMPONENT\tSTATUS\tCREATED")
for _, rel := range releases {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n",
rel.Metadata.Name,
rel.Spec.ReleasePlan,
rel.Metadata.Labels["appstudio.openshift.io/component"],
releaseStatus(rel),
rel.Metadata.CreationTimestamp,
)
}
tw.Flush()
return true
}

// FormatReleasesWithImages writes a table of Releases enriched with destination images.
func FormatReleasesWithImages(w io.Writer, releases []Release, images map[string]string) bool {
if len(releases) == 0 {
return false
}

sort.Slice(releases, func(i, j int) bool {
return releases[i].Metadata.CreationTimestamp < releases[j].Metadata.CreationTimestamp
})

tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
fmt.Fprintln(tw, "NAME\tPLAN\tCOMPONENT\tSTATUS\tCREATED\tDEST-IMAGE")
for _, rel := range releases {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\t%s\n",
rel.Metadata.Name,
rel.Spec.ReleasePlan,
rel.Metadata.Labels["appstudio.openshift.io/component"],
releaseStatus(rel),
rel.Metadata.CreationTimestamp,
images[rel.Metadata.Name],
)
}
tw.Flush()
return true
}

// FormatReleasePipelineRuns writes a table of release PipelineRuns to w.
func FormatReleasePipelineRuns(w io.Writer, prs []PipelineRun) bool {
if len(prs) == 0 {
return false
}

sort.Slice(prs, func(i, j int) bool {
return prs[i].Metadata.CreationTimestamp < prs[j].Metadata.CreationTimestamp
})

tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
fmt.Fprintln(tw, "NAME\tRELEASE\tSTATUS\tCREATED")
for _, pr := range prs {
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n",
pr.Metadata.Name,
pr.Metadata.Labels["release.appstudio.openshift.io/name"],
pipelineRunStatus(pr),
pr.Metadata.CreationTimestamp,
)
}
tw.Flush()
return true
}

// ResolveDestImages resolves destination images for a list of releases using
// the release plan mapping and snapshot data.
func ResolveDestImages(q Querier, releases []Release) map[string]string {
images := make(map[string]string)
for _, rel := range releases {
img := resolveDestImage(q, rel)
if img != "" {
images[rel.Metadata.Name] = img
}
}
return images
}

func resolveDestImage(q Querier, rel Release) string {
mapping := getMappingForRelease(q, rel.Spec.ReleasePlan)
if mapping == nil {
return ""
}

compName := rel.Metadata.Labels["appstudio.openshift.io/component"]
if compName == "" || rel.Spec.Snapshot == "" {
return ""
}

snap, err := q.GetSnapshot(rel.Spec.Snapshot)
if err != nil || snap == nil {
return ""
}

var sourceDigest string
for _, sc := range snap.Spec.Components {
if sc.Name == compName {
if idx := strings.LastIndex(sc.ContainerImage, "@"); idx >= 0 {
sourceDigest = sc.ContainerImage[idx+1:]
}
break
}
}
if sourceDigest == "" {
return ""
}

for _, mc := range mapping.Components {
if mc.Name == compName && len(mc.Repositories) > 0 {
return mc.Repositories[0].URL + "@" + sourceDigest
}
}
return ""
}

func getMappingForRelease(q Querier, planName string) *Mapping {
plan, err := q.GetReleasePlan(planName)
if err != nil || plan == nil {
return nil
}

if plan.Spec.Data.Mapping != nil {
return plan.Spec.Data.Mapping
}

rpaRef := plan.Status.ReleasePlanAdmission.Name
if rpaRef == "" {
return nil
}

parts := strings.SplitN(rpaRef, "/", 2)
if len(parts) != 2 {
return nil
}

rpa, err := q.GetReleasePlanAdmission(parts[0], parts[1])
if err != nil || rpa == nil {
return nil
}

return rpa.Spec.Data.Mapping
}
Loading
Loading