-
Notifications
You must be signed in to change notification settings - Fork 315
enable in-repo ci-op config #5212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Prucek
wants to merge
1
commit into
openshift:main
Choose a base branch
from
Prucek:in-repo-config-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| prowv1 "sigs.k8s.io/prow/pkg/apis/prowjobs/v1" | ||
| prowconfig "sigs.k8s.io/prow/pkg/config" | ||
|
|
||
| jc "github.com/openshift/ci-tools/pkg/jobconfig" | ||
| ) | ||
|
|
||
| func generateBootstrapJobs(org, repo, branch, prowgenImage, checkconfigImage string) *prowconfig.JobConfig { | ||
| orgrepo := fmt.Sprintf("%s/%s", org, repo) | ||
| branchRegex := jc.ExactlyBranch(branch) | ||
|
|
||
| return &prowconfig.JobConfig{ | ||
| PresubmitsStatic: map[string][]prowconfig.Presubmit{ | ||
| orgrepo: {generateConfigCheckerPresubmit(org, repo, branch, branchRegex, checkconfigImage)}, | ||
| }, | ||
| PostsubmitsStatic: map[string][]prowconfig.Postsubmit{ | ||
| orgrepo: {generateProwgenPostsubmit(org, repo, branch, branchRegex, prowgenImage)}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func generateConfigCheckerPresubmit(org, repo, branch, branchRegex, image string) prowconfig.Presubmit { | ||
| name := fmt.Sprintf("pull-ci-%s-%s-%s-ci-operator-config-check", org, repo, branch) | ||
| trueBool := true | ||
| repoPath := fmt.Sprintf("/home/prow/go/src/github.com/%s/%s", org, repo) | ||
|
|
||
| return prowconfig.Presubmit{ | ||
| JobBase: prowconfig.JobBase{ | ||
| Name: name, | ||
| Agent: string(prowv1.KubernetesAgent), | ||
| Labels: map[string]string{ | ||
| jc.LabelGenerator: string(pluginGenerator), | ||
| }, | ||
| Spec: &corev1.PodSpec{ | ||
| Containers: []corev1.Container{{ | ||
| Name: "checkconfig", | ||
| Image: image, | ||
| Command: []string{"ci-operator-checkconfig"}, | ||
| Args: []string{ | ||
| fmt.Sprintf("--config-dir=%s/%s", repoPath, ciOperatorDir), | ||
| }, | ||
| }}, | ||
| }, | ||
| UtilityConfig: prowconfig.UtilityConfig{ | ||
| Decorate: &trueBool, | ||
| }, | ||
| }, | ||
| Brancher: prowconfig.Brancher{ | ||
| Branches: []string{branchRegex}, | ||
| }, | ||
| RegexpChangeMatcher: prowconfig.RegexpChangeMatcher{ | ||
| RunIfChanged: `\.ci-operator/`, | ||
| }, | ||
| AlwaysRun: false, | ||
| } | ||
| } | ||
|
|
||
| func generateProwgenPostsubmit(org, repo, branch, branchRegex, image string) prowconfig.Postsubmit { | ||
| name := fmt.Sprintf("branch-ci-%s-%s-%s-prowgen", org, repo, branch) | ||
| trueBool := true | ||
| repoPath := fmt.Sprintf("/home/prow/go/src/github.com/%s/%s", org, repo) | ||
|
|
||
| return prowconfig.Postsubmit{ | ||
| JobBase: prowconfig.JobBase{ | ||
| Name: name, | ||
| Agent: string(prowv1.KubernetesAgent), | ||
| Labels: map[string]string{ | ||
| jc.LabelGenerator: string(pluginGenerator), | ||
| }, | ||
| Spec: &corev1.PodSpec{ | ||
| Containers: []corev1.Container{{ | ||
| Name: "prowgen", | ||
| Image: image, | ||
| Command: []string{"ci-operator-prowgen"}, | ||
| Args: []string{ | ||
| fmt.Sprintf("--from-file=%s/.ci-operator.yaml", repoPath), | ||
| "--to-dir=/etc/jobs", | ||
| }, | ||
| VolumeMounts: []corev1.VolumeMount{{ | ||
| Name: "job-configs", | ||
| MountPath: "/etc/jobs", | ||
| }}, | ||
| }}, | ||
| Volumes: []corev1.Volume{{ | ||
| Name: "job-configs", | ||
| VolumeSource: corev1.VolumeSource{ | ||
| PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ | ||
| ClaimName: "job-configs-nfs", | ||
| }, | ||
| }, | ||
| }}, | ||
| }, | ||
| UtilityConfig: prowconfig.UtilityConfig{ | ||
| Decorate: &trueBool, | ||
| }, | ||
| MaxConcurrency: 1, | ||
| }, | ||
| Brancher: prowconfig.Brancher{ | ||
| Branches: []string{branchRegex}, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestGenerateBootstrapJobs(t *testing.T) { | ||
| org := "openshift" | ||
| repo := "installer" | ||
| branch := "main" | ||
| prowgenImage := "quay.io/openshift/ci-operator-prowgen:latest" | ||
| checkconfigImage := "quay.io/openshift/ci-operator-checkconfig:latest" | ||
|
|
||
| jobConfig := generateBootstrapJobs(org, repo, branch, prowgenImage, checkconfigImage) | ||
|
|
||
| orgrepo := "openshift/installer" | ||
|
|
||
| presubmits := jobConfig.PresubmitsStatic[orgrepo] | ||
| if len(presubmits) != 1 { | ||
| t.Fatalf("expected 1 presubmit, got %d", len(presubmits)) | ||
| } | ||
|
|
||
| pre := presubmits[0] | ||
| expectedPreName := "pull-ci-openshift-installer-main-ci-operator-config-check" | ||
| if pre.Name != expectedPreName { | ||
| t.Errorf("expected presubmit name %q, got %q", expectedPreName, pre.Name) | ||
| } | ||
| if len(pre.Branches) != 1 || pre.Branches[0] != "^main$" { | ||
| t.Errorf("expected branch regex ^main$, got %v", pre.Branches) | ||
| } | ||
| if pre.RunIfChanged != `\.ci-operator/` { | ||
| t.Errorf("expected run_if_changed %q, got %q", `\.ci-operator/`, pre.RunIfChanged) | ||
| } | ||
| if pre.AlwaysRun { | ||
| t.Error("expected always_run to be false") | ||
| } | ||
| if pre.Spec == nil || len(pre.Spec.Containers) != 1 { | ||
| t.Fatal("expected 1 container in presubmit spec") | ||
| } | ||
| if pre.Spec.Containers[0].Image != checkconfigImage { | ||
| t.Errorf("expected image %q, got %q", checkconfigImage, pre.Spec.Containers[0].Image) | ||
| } | ||
|
|
||
| postsubmits := jobConfig.PostsubmitsStatic[orgrepo] | ||
| if len(postsubmits) != 1 { | ||
| t.Fatalf("expected 1 postsubmit, got %d", len(postsubmits)) | ||
| } | ||
|
|
||
| post := postsubmits[0] | ||
| expectedPostName := "branch-ci-openshift-installer-main-prowgen" | ||
| if post.Name != expectedPostName { | ||
| t.Errorf("expected postsubmit name %q, got %q", expectedPostName, post.Name) | ||
| } | ||
| if len(post.Branches) != 1 || post.Branches[0] != "^main$" { | ||
| t.Errorf("expected branch regex ^main$, got %v", post.Branches) | ||
| } | ||
| if post.MaxConcurrency != 1 { | ||
| t.Errorf("expected max_concurrency 1, got %d", post.MaxConcurrency) | ||
| } | ||
| if post.Spec == nil || len(post.Spec.Containers) != 1 { | ||
| t.Fatal("expected 1 container in postsubmit spec") | ||
| } | ||
| container := post.Spec.Containers[0] | ||
| if container.Image != prowgenImage { | ||
| t.Errorf("expected image %q, got %q", prowgenImage, container.Image) | ||
| } | ||
| if len(container.VolumeMounts) != 1 || container.VolumeMounts[0].MountPath != "/etc/jobs" { | ||
| t.Error("expected volume mount at /etc/jobs") | ||
| } | ||
| if len(post.Spec.Volumes) != 1 || post.Spec.Volumes[0].PersistentVolumeClaim == nil { | ||
| t.Error("expected PVC volume for job-configs") | ||
| } | ||
| if post.Spec.Volumes[0].PersistentVolumeClaim.ClaimName != "job-configs-nfs" { | ||
| t.Errorf("expected PVC claim name job-configs-nfs, got %q", post.Spec.Volumes[0].PersistentVolumeClaim.ClaimName) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateBootstrapJobsEscapesBranch(t *testing.T) { | ||
| jobConfig := generateBootstrapJobs("org", "repo", "release-4.15", "img", "img") | ||
| orgrepo := "org/repo" | ||
|
|
||
| pre := jobConfig.PresubmitsStatic[orgrepo][0] | ||
| if pre.Branches[0] != `^release-4\.15$` { | ||
| t.Errorf("expected escaped branch regex, got %q", pre.Branches[0]) | ||
| } | ||
|
|
||
| post := jobConfig.PostsubmitsStatic[orgrepo][0] | ||
| if post.Branches[0] != `^release-4\.15$` { | ||
| t.Errorf("expected escaped branch regex, got %q", post.Branches[0]) | ||
| } | ||
|
|
||
| expectedPreName := "pull-ci-org-repo-release-4.15-ci-operator-config-check" | ||
| if pre.Name != expectedPreName { | ||
| t.Errorf("expected %q, got %q", expectedPreName, pre.Name) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--unresolved-configis populated with a host path, not a repo path.On Line 135,
UnresolvedConfigPathis set too.fromFiledirectly. In--from-fileusage this can be an absolute/local path, which is then embedded in generated jobs and won’t exist inside the job container.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents