Skip to content

Commit c9eb12d

Browse files
committed
Support for referencePolicy Source while importing release payload
1 parent b3abef2 commit c9eb12d

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed

pkg/api/types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ type Integration struct {
335335
// IncludeBuiltImages determines if the release we assemble will include
336336
// images built during the test itself.
337337
IncludeBuiltImages bool `json:"include_built_images,omitempty"`
338+
// ReferencePolicy is the policy to use when resolving references (Local or Source)
339+
ReferencePolicy string `json:"reference_policy,omitempty"`
338340
}
339341

340342
// ReleaseDescriptor holds common data for different types of release payloads
@@ -494,6 +496,14 @@ func (i *ImageStreamTagReference) ISTagName() string {
494496
return fmt.Sprintf("%s/%s:%s", i.Namespace, i.Name, i.Tag)
495497
}
496498

499+
// // ReferencePolicyTag defines the possible values for the reference policy.
500+
// type ReferencePolicyTag string
501+
502+
// const (
503+
// ReferencePolicyLocal ReferencePolicyTag = "Local"
504+
// ReferencePolicySource ReferencePolicyTag = "Source"
505+
// )
506+
497507
// ReleaseTagConfiguration describes how a release is
498508
// assembled from release artifacts. A release image stream is a
499509
// single stream with multiple tags (openshift/origin-v3.9:control-plane),
@@ -511,6 +521,9 @@ type ReleaseTagConfiguration struct {
511521
// IncludeBuiltImages determines if the release we assemble will include
512522
// images built during the test itself.
513523
IncludeBuiltImages bool `json:"include_built_images,omitempty"`
524+
525+
// ReferencePolicy is the policy to use when resolving references (Local or Source)
526+
ReferencePolicy string `json:"reference_policy,omitempty"`
514527
}
515528

516529
func (config ReleaseTagConfiguration) InputsName() string {

pkg/defaults/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ func fromConfig(
220220
Namespace: resolveConfig.Integration.Namespace,
221221
Name: resolveConfig.Integration.Name,
222222
IncludeBuiltImages: resolveConfig.Integration.IncludeBuiltImages,
223+
ReferencePolicy: resolveConfig.Integration.ReferencePolicy,
223224
}, config.Resources, podClient, jobSpec)
224225
for _, s := range []api.Step{snapshot, assemble} {
225226
buildSteps = append(buildSteps, s)

pkg/util/imagestreamtagwrapper/testdata/imagestream.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
importPolicy: {}
3232
name: root
3333
referencePolicy:
34-
type: Local
34+
type: Source
3535
status:
3636
dockerImageRepository: docker-registry.default.svc:5000/ci-op-jpdy23wx/pipeline
3737
publicDockerImageRepository: registry.svc.ci.openshift.org/ci-op-jpdy23wx/pipeline

pkg/util/imagestreamtagwrapper/testdata/imagestreamtags.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ items:
224224
apiVersion: "1.0"
225225
kind: DockerImage
226226
dockerImageMetadataVersion: "1.0"
227-
dockerImageReference: docker-registry.default.svc:5000/ci-op-jpdy23wx/pipeline@sha256:fd41b8b3efb8db1187ac231ca84863a8106880d049123d6eddfe21d7f751c627
227+
dockerImageReference: docker.io/openshift/origin-release@sha256:fd41b8b3efb8db1187ac231ca84863a8106880d049123d6eddfe21d7f751c627
228228
metadata:
229229
annotations:
230230
image.openshift.io/dockerLayersOrder: ascending
@@ -252,7 +252,7 @@ items:
252252
importPolicy: {}
253253
name: root
254254
referencePolicy:
255-
type: Local
255+
type: Source
256256
- apiVersion: image.openshift.io/v1
257257
generation: 3
258258
image:

pkg/validation/release.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func validateIntegration(fieldRoot, name string, integration api.Integration) []
7171
if integration.IncludeBuiltImages && name != api.LatestReleaseName {
7272
validationErrors = append(validationErrors, fmt.Errorf("%s: only the `latest` release can set `include_built_images`", fieldRoot))
7373
}
74+
if integration.ReferencePolicy == "" {
75+
integration.ReferencePolicy = "Local" // Set default value
76+
}
77+
if integration.ReferencePolicy != "Local" && integration.ReferencePolicy != "Source" {
78+
validationErrors = append(validationErrors, fmt.Errorf("%s.reference_policy: must be one of Local or Source or empty defaults to Local", fieldRoot))
79+
}
7480
return validationErrors
7581
}
7682

pkg/validation/release_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,49 @@ func TestValidateIntegration(t *testing.T) {
543543
IncludeBuiltImages: true,
544544
},
545545
},
546+
{
547+
name: "valid integration with local reference policy",
548+
inputName: "latest",
549+
input: api.Integration{
550+
Name: "4.8",
551+
Namespace: "ocp",
552+
IncludeBuiltImages: true,
553+
ReferencePolicy: "Local",
554+
},
555+
},
556+
{
557+
name: "valid integration with source reference policy",
558+
inputName: "latest",
559+
input: api.Integration{
560+
Name: "4.8",
561+
Namespace: "ocp",
562+
IncludeBuiltImages: true,
563+
ReferencePolicy: "Source",
564+
},
565+
},
566+
{
567+
name: "valid integration with empty reference policy setting to Local as default",
568+
inputName: "latest",
569+
input: api.Integration{
570+
Name: "4.8",
571+
Namespace: "ocp",
572+
IncludeBuiltImages: true,
573+
ReferencePolicy: "",
574+
},
575+
},
576+
{
577+
name: "invalid integration with reference policy",
578+
inputName: "latest",
579+
input: api.Integration{
580+
Name: "4.8",
581+
Namespace: "ocp",
582+
IncludeBuiltImages: true,
583+
ReferencePolicy: "something",
584+
},
585+
output: []error{
586+
errors.New("root.reference_policy: must be one of Local or Source or empty defaults to Local"),
587+
},
588+
},
546589
{
547590
name: "invalid integration missing namespace",
548591
inputName: "latest",

pkg/webreg/zz_generated.ci_operator_reference.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" +
479479
" # all release artifacts not built in the current\n" +
480480
" # job are tagged from.\n" +
481481
" namespace: ' '\n" +
482+
" # ReferencePolicy is the policy to use when resolving references (Local or Source)\n" +
483+
" reference_policy: ' '\n" +
482484
" resolved_release_images_step:\n" +
483485
" # Candidate describes a candidate release payload\n" +
484486
" candidate:\n" +
@@ -500,6 +502,8 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" +
500502
" name: ' '\n" +
501503
" # Namespace is the namespace in which the integration stream lives.\n" +
502504
" namespace: ' '\n" +
505+
" # ReferencePolicy is the policy to use when resolving references (Local or Source)\n" +
506+
" reference_policy: ' '\n" +
503507
" name: ' '\n" +
504508
" # Prerelease describes a yet-to-be released payload\n" +
505509
" prerelease:\n" +
@@ -1328,6 +1332,8 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" +
13281332
" name: ' '\n" +
13291333
" # Namespace is the namespace in which the integration stream lives.\n" +
13301334
" namespace: ' '\n" +
1335+
" # ReferencePolicy is the policy to use when resolving references (Local or Source)\n" +
1336+
" reference_policy: ' '\n" +
13311337
" # Prerelease describes a yet-to-be released payload\n" +
13321338
" prerelease:\n" +
13331339
" # Architecture is the architecture for the product.\n" +
@@ -1399,6 +1405,8 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" +
13991405
" # all release artifacts not built in the current\n" +
14001406
" # job are tagged from.\n" +
14011407
" namespace: ' '\n" +
1408+
" # ReferencePolicy is the policy to use when resolving references (Local or Source)\n" +
1409+
" reference_policy: ' '\n" +
14021410
"# TestBinaryBuildCommands will create a \"test-bin\" image based on \"src\" that\n" +
14031411
"# contains the output of this command. This allows reuse of binary artifacts\n" +
14041412
"# across other steps. If empty, no \"test-bin\" image will be created.\n" +

0 commit comments

Comments
 (0)