Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ postsubmits:
- ^branch$
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/is-promotion: "true"
ci.openshift.io/generator: prowgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ postsubmits:
- ^branch$
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/is-promotion: "true"
ci.openshift.io/generator: prowgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ postsubmits:
- ^branch$
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/is-promotion: "true"
ci-operator.openshift.io/variant: rhel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ postsubmits:
- ^branch$
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/is-promotion: "true"
ci.openshift.io/generator: prowgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ presubmits:
context: ci/prow/images
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci.openshift.io/generator: prowgen
pj-rehearse.openshift.io/can-be-rehearsed: "true"
Expand Down Expand Up @@ -62,7 +63,8 @@ presubmits:
context: ci/prow/unit
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
timeout: 8h0m0s
labels:
ci.openshift.io/generator: prowgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ presubmits:
context: ci/prow/images
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci.openshift.io/generator: prowgen
pj-rehearse.openshift.io/can-be-rehearsed: "true"
Expand Down Expand Up @@ -62,7 +63,8 @@ presubmits:
context: ci/prow/unit
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
Comment on lines +66 to +67
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Non-image unit presubmit should not be sparse-checked out to only Dockerfile.

At Line 66-Line 67, this fixture sets image-style sparse checkout on a --target=unit job, which conflicts with the PR objective (“image-build jobs only”) and can encode incorrect expected output.

Proposed fixture correction
     decoration_config:
-      sparse_checkout_files:
-      - Dockerfile
+      skip_cloning: true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sparse_checkout_files:
- Dockerfile
skip_cloning: true
🤖 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
`@cmd/ci-operator-prowgen/testdata/zz_fixture_presubmit_TestFromCIOperatorConfigToProwYaml_Input_is_YAML_and_it_is_correctly_processed.yaml`
around lines 66 - 67, The fixture sets image-style sparse checkout for a
non-image unit presubmit: remove or change the sparse_checkout_files entry that
lists "Dockerfile" for the job with "--target=unit" so the unit presubmit is not
limited to image files; specifically locate the YAML block that contains
sparse_checkout_files and the job metadata referencing "--target=unit" and
either delete the sparse_checkout_files key or replace it with a general
checkout (or an appropriate non-image file list) so the fixture matches the
"image-build jobs only" intent.

labels:
ci.openshift.io/generator: prowgen
pj-rehearse.openshift.io/can-be-rehearsed: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ presubmits:
context: ci/prow/rhel-images
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/variant: rhel
ci.openshift.io/generator: prowgen
Expand Down Expand Up @@ -64,7 +65,8 @@ presubmits:
context: ci/prow/rhel-unit
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/variant: rhel
ci.openshift.io/generator: prowgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ presubmits:
context: ci/prow/images
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci.openshift.io/generator: prowgen
pj-rehearse.openshift.io/can-be-rehearsed: "true"
Expand Down Expand Up @@ -62,7 +63,8 @@ presubmits:
context: ci/prow/unit
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci.openshift.io/generator: prowgen
pj-rehearse.openshift.io/can-be-rehearsed: "true"
Expand Down
62 changes: 44 additions & 18 deletions pkg/prowgen/jobbase.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package prowgen

import (
"path"
"time"

utilpointer "k8s.io/utils/pointer"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
prowv1 "sigs.k8s.io/prow/pkg/apis/prowjobs/v1"
prowconfig "sigs.k8s.io/prow/pkg/config"

Expand All @@ -20,22 +22,40 @@ type prowJobBaseBuilder struct {
testName string
}

// If any included buildRoot uses from_repository we must not skip cloning
func skipCloning(configSpec *cioperatorapi.ReleaseBuildConfiguration) bool {
buildRoots := configSpec.BuildRootImages
if buildRoots == nil {
buildRoots = make(map[string]cioperatorapi.BuildRootImageConfiguration)
}
if configSpec.BuildRootImage != nil {
buildRoots[""] = *configSpec.BuildRootImage
func fromRepositorySet(configSpec *cioperatorapi.ReleaseBuildConfiguration) bool {
if configSpec.BuildRootImage != nil && configSpec.BuildRootImage.FromRepository {
return true
}
for _, buildRoot := range buildRoots {
for _, buildRoot := range configSpec.BuildRootImages {
if buildRoot.FromRepository {
return false
return true
}
}
return false
}

return true
func sparseCheckoutFiles(configSpec *cioperatorapi.ReleaseBuildConfiguration) []string {
files := sets.New[string]()
if fromRepositorySet(configSpec) {
files.Insert(cioperatorapi.CIOperatorInrepoConfigFileName)
}
for _, image := range configSpec.Images.Items {
if image.DockerfileLiteral != nil {
continue
}
if image.Ref != "" {
continue
}
dockerfilePath := image.DockerfilePath
if dockerfilePath == "" {
dockerfilePath = "Dockerfile"
}
if image.ContextDir != "" {
dockerfilePath = path.Join(image.ContextDir, dockerfilePath)
}
files.Insert(dockerfilePath)
}
return sets.List(files)
}

func hasNoBuilds(c *cioperatorapi.ReleaseBuildConfiguration, info *ProwgenInfo) bool {
Expand Down Expand Up @@ -63,18 +83,24 @@ func NewProwJobBaseBuilder(configSpec *cioperatorapi.ReleaseBuildConfiguration,
Agent: string(prowv1.KubernetesAgent),
Labels: map[string]string{},
UtilityConfig: prowconfig.UtilityConfig{
Decorate: utilpointer.Bool(true),
Decorate: ptr.To(true),
DecorationConfig: &prowv1.DecorationConfig{},
},
},
}

private := info.Config.Private || (configSpec.Prowgen != nil && configSpec.Prowgen.Private)
expose := info.Config.Expose || (configSpec.Prowgen != nil && configSpec.Prowgen.Expose)

if skipCloning(configSpec) {
b.base.UtilityConfig.DecorationConfig = &prowv1.DecorationConfig{SkipCloning: utilpointer.Bool(true)}
} else if private {
b.base.UtilityConfig.DecorationConfig = &prowv1.DecorationConfig{OauthTokenSecret: &prowv1.OauthTokenSecret{Key: cioperatorapi.OauthTokenSecretKey, Name: cioperatorapi.OauthTokenSecretName}}
sparseFiles := sparseCheckoutFiles(configSpec)
shouldSkipCloning := len(sparseFiles) == 0
if shouldSkipCloning {
b.base.UtilityConfig.DecorationConfig.SkipCloning = ptr.To(true)
} else {
b.base.UtilityConfig.DecorationConfig.SparseCheckoutFiles = sparseFiles
if private {
b.base.UtilityConfig.DecorationConfig.OauthTokenSecret = &prowv1.OauthTokenSecret{Key: cioperatorapi.OauthTokenSecretKey, Name: cioperatorapi.OauthTokenSecretName}
}
}

if len(info.Variant) > 0 {
Expand All @@ -93,7 +119,7 @@ func NewProwJobBaseBuilder(configSpec *cioperatorapi.ReleaseBuildConfiguration,

b.PodSpec.Add(Variant(info.Variant))
if private {
b.PodSpec.Add(GitHubToken(!skipCloning(configSpec)))
b.PodSpec.Add(GitHubToken(!shouldSkipCloning))
}

if configSpec.CanonicalGoRepository != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/prowgen/prowgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ func GeneratePeriodicForTest(jobBaseBuilder *prowJobBaseBuilder, info *ProwgenIn
if opts.PathAlias != nil {
ref.PathAlias = *opts.PathAlias
}
if dc := base.UtilityConfig.DecorationConfig; dc != nil && len(dc.SparseCheckoutFiles) > 0 {
ref.SparseCheckoutFiles = dc.SparseCheckoutFiles
}
base.ExtraRefs = append([]prowv1.Refs{ref}, base.ExtraRefs...)
if opts.ReleaseController {
opts.Interval = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ postsubmits:
- ^branch$
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/is-promotion: "true"
max_concurrency: 1
Expand Down Expand Up @@ -69,7 +70,8 @@ presubmits:
context: ci/prow/images
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
labels:
pj-rehearse.openshift.io/can-be-rehearsed: "true"
name: pull-ci-organization-repository-branch-images
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ periodics:
cron: 5 4 * * *
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
extra_refs:
- base_ref: branch
org: organization
repo: repository
sparse_checkout_files:
- Dockerfile
labels:
ci-operator.openshift.io/is-promotion: "true"
max_concurrency: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
agent: kubernetes
decorate: true
decoration_config:
sparse_checkout_files:
- .ci-operator.yaml
timeout: 1s
name: prefix-ci-o-r-b-simple
spec:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
agent: kubernetes
decorate: true
decoration_config:
skip_cloning: true
sparse_checkout_files:
- Dockerfile
name: default-ci-openshift-release-main-
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ decoration_config:
oauth_token_secret:
key: oauth
name: github-credentials-openshift-ci-robot-private-git-cloner
sparse_checkout_files:
- .ci-operator.yaml
hidden: true
name: default-ci-vorg-vrepo-vbranch-
spec:
Expand Down
3 changes: 3 additions & 0 deletions pkg/rehearse/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func makeRehearsalPresubmit(source *prowconfig.Presubmit, repo string, refs *pja
rehearsal.CloneURI = ""
rehearsal.SkipSubmodules = false
rehearsal.CloneDepth = 0
if rehearsal.DecorationConfig != nil {
rehearsal.DecorationConfig.SparseCheckoutFiles = nil
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
ghContext += repo + "/"
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/steps/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func createBuild(config api.SourceStepConfiguration, jobSpec *api.JobSpec, clone
}
}

for i := range refs {
refs[i].SparseCheckoutFiles = nil
}

dockerfile := sourceDockerfile(config.From, decorate.DetermineWorkDir(gopath, refs), cloneAuthConfig)
buildSource := buildapi.BuildSource{
Type: buildapi.BuildSourceDockerfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ presubmits:
oauth_token_secret:
key: oauth
name: github-credentials-openshift-ci-robot-private-git-cloner
sparse_checkout_files:
- .ci-operator.yaml
hidden: true
labels:
ci.openshift.io/generator: prowgen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ periodics:
cron: '@yearly'
decorate: true
decoration_config:
skip_cloning: true
oauth_token_secret:
key: oauth
name: github-credentials-openshift-ci-robot-private-git-cloner
sparse_checkout_files:
- Dockerfile
extra_refs:
- base_ref: master
org: private
repo: duper
sparse_checkout_files:
- Dockerfile
hidden: true
labels:
ci.openshift.io/generator: prowgen
Expand Down Expand Up @@ -55,9 +61,6 @@ periodics:
readOnly: true
serviceAccountName: ci-operator
volumes:
- name: github-credentials-openshift-ci-robot-private-git-cloner
secret:
secretName: github-credentials-openshift-ci-robot-private-git-cloner
- name: manifest-tool-local-pusher
secret:
secretName: manifest-tool-local-pusher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ postsubmits:
- ^master$
decorate: true
decoration_config:
skip_cloning: true
oauth_token_secret:
key: oauth
name: github-credentials-openshift-ci-robot-private-git-cloner
sparse_checkout_files:
- Dockerfile
hidden: true
labels:
ci-operator.openshift.io/is-promotion: "true"
Expand Down Expand Up @@ -52,9 +56,6 @@ postsubmits:
readOnly: true
serviceAccountName: ci-operator
volumes:
- name: github-credentials-openshift-ci-robot-private-git-cloner
secret:
secretName: github-credentials-openshift-ci-robot-private-git-cloner
- name: manifest-tool-local-pusher
secret:
secretName: manifest-tool-local-pusher
Expand Down
Loading