Skip to content

Commit 24b7587

Browse files
committed
feat(prowgen): utilize sparse checkout
1 parent f3270da commit 24b7587

45 files changed

Lines changed: 492 additions & 116 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/ci-operator-prowgen/testdata/zz_fixture_postsubmit_TestFromCIOperatorConfigToProwYaml_Custom_test_timeout.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ postsubmits:
2525
- ^branch$
2626
decorate: true
2727
decoration_config:
28-
skip_cloning: true
28+
sparse_checkout_files:
29+
- Dockerfile
2930
labels:
3031
ci-operator.openshift.io/is-promotion: "true"
3132
ci.openshift.io/generator: prowgen

cmd/ci-operator-prowgen/testdata/zz_fixture_postsubmit_TestFromCIOperatorConfigToProwYaml_Input_is_YAML_and_it_is_correctly_processed.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ postsubmits:
2525
- ^branch$
2626
decorate: true
2727
decoration_config:
28-
skip_cloning: true
28+
sparse_checkout_files:
29+
- Dockerfile
2930
labels:
3031
ci-operator.openshift.io/is-promotion: "true"
3132
ci.openshift.io/generator: prowgen

cmd/ci-operator-prowgen/testdata/zz_fixture_postsubmit_TestFromCIOperatorConfigToProwYaml_Using_a_variant_config__one_test_and_images__one_existing_job._Expect_one_presubmit__pre_post_submit_images_jobs._Existing_job_should_not_be_changed..yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ postsubmits:
2727
- ^branch$
2828
decorate: true
2929
decoration_config:
30-
skip_cloning: true
30+
sparse_checkout_files:
31+
- Dockerfile
3132
labels:
3233
ci-operator.openshift.io/is-promotion: "true"
3334
ci-operator.openshift.io/variant: rhel

cmd/ci-operator-prowgen/testdata/zz_fixture_postsubmit_TestFromCIOperatorConfigToProwYaml_one_test_and_images__no_previous_jobs._Expect_test_presubmit__pre_post_submit_images_jobs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ postsubmits:
66
- ^branch$
77
decorate: true
88
decoration_config:
9-
skip_cloning: true
9+
sparse_checkout_files:
10+
- Dockerfile
1011
labels:
1112
ci-operator.openshift.io/is-promotion: "true"
1213
ci.openshift.io/generator: prowgen

cmd/ci-operator-prowgen/testdata/zz_fixture_presubmit_TestFromCIOperatorConfigToProwYaml_Custom_test_timeout.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ presubmits:
88
context: ci/prow/images
99
decorate: true
1010
decoration_config:
11-
skip_cloning: true
11+
sparse_checkout_files:
12+
- Dockerfile
1213
labels:
1314
ci.openshift.io/generator: prowgen
1415
pj-rehearse.openshift.io/can-be-rehearsed: "true"
@@ -62,7 +63,8 @@ presubmits:
6263
context: ci/prow/unit
6364
decorate: true
6465
decoration_config:
65-
skip_cloning: true
66+
sparse_checkout_files:
67+
- Dockerfile
6668
timeout: 8h0m0s
6769
labels:
6870
ci.openshift.io/generator: prowgen

cmd/ci-operator-prowgen/testdata/zz_fixture_presubmit_TestFromCIOperatorConfigToProwYaml_Input_is_YAML_and_it_is_correctly_processed.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ presubmits:
88
context: ci/prow/images
99
decorate: true
1010
decoration_config:
11-
skip_cloning: true
11+
sparse_checkout_files:
12+
- Dockerfile
1213
labels:
1314
ci.openshift.io/generator: prowgen
1415
pj-rehearse.openshift.io/can-be-rehearsed: "true"
@@ -62,7 +63,8 @@ presubmits:
6263
context: ci/prow/unit
6364
decorate: true
6465
decoration_config:
65-
skip_cloning: true
66+
sparse_checkout_files:
67+
- Dockerfile
6668
labels:
6769
ci.openshift.io/generator: prowgen
6870
pj-rehearse.openshift.io/can-be-rehearsed: "true"

cmd/ci-operator-prowgen/testdata/zz_fixture_presubmit_TestFromCIOperatorConfigToProwYaml_Using_a_variant_config__one_test_and_images__one_existing_job._Expect_one_presubmit__pre_post_submit_images_jobs._Existing_job_should_not_be_changed..yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ presubmits:
88
context: ci/prow/rhel-images
99
decorate: true
1010
decoration_config:
11-
skip_cloning: true
11+
sparse_checkout_files:
12+
- Dockerfile
1213
labels:
1314
ci-operator.openshift.io/variant: rhel
1415
ci.openshift.io/generator: prowgen
@@ -64,7 +65,8 @@ presubmits:
6465
context: ci/prow/rhel-unit
6566
decorate: true
6667
decoration_config:
67-
skip_cloning: true
68+
sparse_checkout_files:
69+
- Dockerfile
6870
labels:
6971
ci-operator.openshift.io/variant: rhel
7072
ci.openshift.io/generator: prowgen

cmd/ci-operator-prowgen/testdata/zz_fixture_presubmit_TestFromCIOperatorConfigToProwYaml_one_test_and_images__no_previous_jobs._Expect_test_presubmit__pre_post_submit_images_jobs.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ presubmits:
88
context: ci/prow/images
99
decorate: true
1010
decoration_config:
11-
skip_cloning: true
11+
sparse_checkout_files:
12+
- Dockerfile
1213
labels:
1314
ci.openshift.io/generator: prowgen
1415
pj-rehearse.openshift.io/can-be-rehearsed: "true"
@@ -62,7 +63,8 @@ presubmits:
6263
context: ci/prow/unit
6364
decorate: true
6465
decoration_config:
65-
skip_cloning: true
66+
sparse_checkout_files:
67+
- Dockerfile
6668
labels:
6769
ci.openshift.io/generator: prowgen
6870
pj-rehearse.openshift.io/can-be-rehearsed: "true"

pkg/prowgen/jobbase.go

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package prowgen
22

33
import (
4+
"path"
45
"time"
56

67
utilpointer "k8s.io/utils/pointer"
@@ -20,22 +21,51 @@ type prowJobBaseBuilder struct {
2021
testName string
2122
}
2223

23-
// If any included buildRoot uses from_repository we must not skip cloning
24-
func skipCloning(configSpec *cioperatorapi.ReleaseBuildConfiguration) bool {
25-
buildRoots := configSpec.BuildRootImages
26-
if buildRoots == nil {
27-
buildRoots = make(map[string]cioperatorapi.BuildRootImageConfiguration)
28-
}
29-
if configSpec.BuildRootImage != nil {
30-
buildRoots[""] = *configSpec.BuildRootImage
24+
func fromRepositorySet(configSpec *cioperatorapi.ReleaseBuildConfiguration) bool {
25+
if configSpec.BuildRootImage != nil && configSpec.BuildRootImage.FromRepository {
26+
return true
3127
}
32-
for _, buildRoot := range buildRoots {
28+
for _, buildRoot := range configSpec.BuildRootImages {
3329
if buildRoot.FromRepository {
34-
return false
30+
return true
3531
}
3632
}
33+
return false
34+
}
3735

38-
return true
36+
// sparseCheckoutFiles returns the list of files to include in a sparse checkout
37+
// when the configuration requires cloning. This includes the in-repo ci-operator
38+
// configuration file and any Dockerfiles that need to be built.
39+
// Returns an empty slice if no sparse checkout is needed.
40+
func sparseCheckoutFiles(configSpec *cioperatorapi.ReleaseBuildConfiguration) []string {
41+
seen := map[string]bool{}
42+
var result []string
43+
add := func(path string) {
44+
if !seen[path] {
45+
seen[path] = true
46+
result = append(result, path)
47+
}
48+
}
49+
if fromRepositorySet(configSpec) {
50+
add(cioperatorapi.CIOperatorInrepoConfigFileName)
51+
}
52+
for _, image := range configSpec.Images.Items {
53+
if image.DockerfileLiteral != nil {
54+
continue
55+
}
56+
if image.Ref != "" {
57+
continue
58+
}
59+
dockerfilePath := image.DockerfilePath
60+
if dockerfilePath == "" {
61+
dockerfilePath = "Dockerfile"
62+
}
63+
if image.ContextDir != "" {
64+
dockerfilePath = path.Join(image.ContextDir, dockerfilePath)
65+
}
66+
add(dockerfilePath)
67+
}
68+
return result
3969
}
4070

4171
func hasNoBuilds(c *cioperatorapi.ReleaseBuildConfiguration, info *ProwgenInfo) bool {
@@ -63,16 +93,20 @@ func NewProwJobBaseBuilder(configSpec *cioperatorapi.ReleaseBuildConfiguration,
6393
Agent: string(prowv1.KubernetesAgent),
6494
Labels: map[string]string{},
6595
UtilityConfig: prowconfig.UtilityConfig{
66-
Decorate: utilpointer.Bool(true),
96+
Decorate: utilpointer.Bool(true),
97+
DecorationConfig: &prowv1.DecorationConfig{},
6798
},
6899
},
69100
}
70101

71-
if skipCloning(configSpec) {
72-
b.base.UtilityConfig.DecorationConfig = &prowv1.DecorationConfig{SkipCloning: utilpointer.Bool(true)}
102+
sparseFiles := sparseCheckoutFiles(configSpec)
103+
shouldSkipCloning := len(sparseFiles) == 0
104+
if shouldSkipCloning {
105+
b.base.UtilityConfig.DecorationConfig.SkipCloning = utilpointer.Bool(true)
73106
} else if info.Config.Private {
74-
b.base.UtilityConfig.DecorationConfig = &prowv1.DecorationConfig{OauthTokenSecret: &prowv1.OauthTokenSecret{Key: cioperatorapi.OauthTokenSecretKey, Name: cioperatorapi.OauthTokenSecretName}}
107+
b.base.UtilityConfig.DecorationConfig.OauthTokenSecret = &prowv1.OauthTokenSecret{Key: cioperatorapi.OauthTokenSecretKey, Name: cioperatorapi.OauthTokenSecretName}
75108
}
109+
b.base.UtilityConfig.DecorationConfig.SparseCheckoutFiles = sparseFiles
76110

77111
if len(info.Variant) > 0 {
78112
b.base.Labels[jc.ProwJobLabelVariant] = info.Variant
@@ -91,7 +125,7 @@ func NewProwJobBaseBuilder(configSpec *cioperatorapi.ReleaseBuildConfiguration,
91125
b.PodSpec.Add(Variant(info.Variant))
92126
if info.Config.Private {
93127
// We can reuse Prow's volume with the token if ProwJob itself is cloning the code
94-
b.PodSpec.Add(GitHubToken(!skipCloning(configSpec)))
128+
b.PodSpec.Add(GitHubToken(!shouldSkipCloning))
95129
}
96130

97131
if configSpec.CanonicalGoRepository != nil {

0 commit comments

Comments
 (0)