Skip to content

Commit ec042d0

Browse files
committed
Allow testing step registry changes via payload-job-with-prs
1 parent 9908494 commit ec042d0

4 files changed

Lines changed: 128 additions & 0 deletions

File tree

pkg/controller/prpqr_reconciler/prpqr_reconciler.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ func (r *reconciler) generateProwjob(ciopConfig *api.ReleaseBuildConfiguration,
641641
jobBaseGen.PodSpec.Add(prowgen.ShardArgs(shardCount, shardIndex))
642642
}
643643

644+
// If openshift/release is among the PRs being tested, configure ci-operator
645+
// to use the step registry from the local checkout instead of the remote
646+
// config resolver. This allows testing step registry changes via PRPQR.
647+
if hasReleaseRepoPR(prs) {
648+
jobBaseGen.PodSpec.Add(prowgen.Registry("/go/src/github.com/openshift/release/ci-operator/step-registry"))
649+
}
650+
644651
// Avoid sharing when we run the same job multiple times.
645652
// PRPQR name should be safe to use as a discriminating input, because
646653
// there should never be more than one execution of a specific job per
@@ -917,3 +924,14 @@ func hasDependantProwJobsFinalizer(objMeta *metav1.ObjectMeta) bool {
917924
}
918925
return false
919926
}
927+
928+
// hasReleaseRepoPR checks if openshift/release is among the PRs being tested.
929+
// When it is, we need to use the step registry from the local checkout.
930+
func hasReleaseRepoPR(prs []v1.PullRequestUnderTest) bool {
931+
for _, pr := range prs {
932+
if pr.Org == "openshift" && pr.Repo == "release" {
933+
return true
934+
}
935+
}
936+
return false
937+
}

pkg/controller/prpqr_reconciler/prpqr_reconciler_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,55 @@ func (f *fakeDispatcherClient) ClusterForJob(jobName string) (string, error) {
580580
return "build02", nil
581581
}
582582
}
583+
584+
func TestHasReleaseRepoPR(t *testing.T) {
585+
tests := []struct {
586+
name string
587+
prs []v1.PullRequestUnderTest
588+
want bool
589+
}{
590+
{
591+
name: "no PRs",
592+
prs: nil,
593+
want: false,
594+
},
595+
{
596+
name: "single PR from different repo",
597+
prs: []v1.PullRequestUnderTest{
598+
{Org: "openshift", Repo: "origin"},
599+
},
600+
want: false,
601+
},
602+
{
603+
name: "single PR from openshift/release",
604+
prs: []v1.PullRequestUnderTest{
605+
{Org: "openshift", Repo: "release"},
606+
},
607+
want: true,
608+
},
609+
{
610+
name: "multiple PRs including openshift/release",
611+
prs: []v1.PullRequestUnderTest{
612+
{Org: "openshift", Repo: "origin"},
613+
{Org: "openshift", Repo: "release"},
614+
},
615+
want: true,
616+
},
617+
{
618+
name: "multiple PRs not including openshift/release",
619+
prs: []v1.PullRequestUnderTest{
620+
{Org: "openshift", Repo: "origin"},
621+
{Org: "openshift", Repo: "installer"},
622+
},
623+
want: false,
624+
},
625+
}
626+
for _, tc := range tests {
627+
t.Run(tc.name, func(t *testing.T) {
628+
got := hasReleaseRepoPR(tc.prs)
629+
if got != tc.want {
630+
t.Errorf("hasReleaseRepoPR() = %v, want %v", got, tc.want)
631+
}
632+
})
633+
}
634+
}

pkg/prowgen/podspec.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,17 @@ func newFakePodSpecBuilder() CiOperatorPodSpecGenerator {
750750
f := fakePodSpecBuilder(0)
751751
return &f
752752
}
753+
754+
// Registry configures ci-operator to use a local step registry path instead of
755+
// the remote config resolver. This is useful when testing changes to the step
756+
// registry from a PR in openshift/release.
757+
func Registry(registryPath string) PodSpecMutator {
758+
return func(spec *corev1.PodSpec) error {
759+
if registryPath == "" {
760+
return nil
761+
}
762+
container := &spec.Containers[0]
763+
addUniqueParameter(container, fmt.Sprintf("--registry=%s", registryPath))
764+
return nil
765+
}
766+
}

pkg/prowgen/podspec_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,47 @@ func TestGSMConfig(t *testing.T) {
528528
testhelper.CompareWithFixture(t, podspec)
529529
})
530530
}
531+
532+
func TestRegistry(t *testing.T) {
533+
t.Parallel()
534+
tests := []struct {
535+
name string
536+
registryPath string
537+
wantArg string
538+
}{
539+
{
540+
name: "registry path is added",
541+
registryPath: "/go/src/github.com/openshift/release/ci-operator/step-registry",
542+
wantArg: "--registry=/go/src/github.com/openshift/release/ci-operator/step-registry",
543+
},
544+
{
545+
name: "empty registry path is a nop",
546+
registryPath: "",
547+
wantArg: "",
548+
},
549+
}
550+
for _, tc := range tests {
551+
tc := tc
552+
t.Run(tc.name, func(t *testing.T) {
553+
t.Parallel()
554+
g := NewCiOperatorPodSpecGenerator()
555+
g.Add(Registry(tc.registryPath))
556+
podspec, err := g.Build()
557+
if err != nil {
558+
t.Fatalf("Unexpected error: %v", err)
559+
}
560+
if tc.wantArg != "" {
561+
found := false
562+
for _, arg := range podspec.Containers[0].Args {
563+
if arg == tc.wantArg {
564+
found = true
565+
break
566+
}
567+
}
568+
if !found {
569+
t.Errorf("Expected arg %q not found in args: %v", tc.wantArg, podspec.Containers[0].Args)
570+
}
571+
}
572+
})
573+
}
574+
}

0 commit comments

Comments
 (0)