Skip to content

Commit 819d019

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

File tree

8 files changed

+111
-15
lines changed

8 files changed

+111
-15
lines changed

pkg/api/types.go

Lines changed: 8 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
@@ -488,6 +490,9 @@ type ImageStreamTagReference struct {
488490

489491
// As is an optional string to use as the intermediate name for this reference.
490492
As string `json:"as,omitempty"`
493+
494+
// ReferencePolicy is an optional string to use as the reference policy for image pull.
495+
ReferencePolicy string `json:"reference_policy,omitempty"`
491496
}
492497

493498
func (i *ImageStreamTagReference) ISTagName() string {
@@ -511,6 +516,9 @@ type ReleaseTagConfiguration struct {
511516
// IncludeBuiltImages determines if the release we assemble will include
512517
// images built during the test itself.
513518
IncludeBuiltImages bool `json:"include_built_images,omitempty"`
519+
520+
// ReferencePolicy is the policy to use when resolving references (Local or Source)
521+
ReferencePolicy string `json:"reference_policy,omitempty"`
514522
}
515523

516524
func (config ReleaseTagConfiguration) InputsName() string {

pkg/defaults/defaults.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ func fromConfig(
215215
case resolveConfig.Integration != nil:
216216
logrus.Infof("Building release %s from a snapshot of %s/%s", resolveConfig.Name, resolveConfig.Integration.Namespace, resolveConfig.Integration.Name)
217217
// this is the one case where we're not importing a payload, we need to get the images and build one
218-
snapshot := releasesteps.ReleaseSnapshotStep(resolveConfig.Name, *resolveConfig.Integration, podClient, jobSpec, integratedStreams[fmt.Sprintf("%s/%s", resolveConfig.Integration.Namespace, resolveConfig.Integration.Name)])
218+
snapshot := releasesteps.ReleaseSnapshotStep(resolveConfig.Name, *resolveConfig.Integration, podClient, jobSpec, integratedStreams[fmt.Sprintf("%s/%s/%s", resolveConfig.Integration.Namespace, resolveConfig.Integration.Name, resolveConfig.Integration.ReferencePolicy)])
219219
assemble := releasesteps.AssembleReleaseStep(resolveConfig.Name, nodeName, &api.ReleaseTagConfiguration{
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)
@@ -231,7 +232,7 @@ func fromConfig(
231232
source = releasesteps.NewReleaseSourceFromConfig(resolveConfig, httpClient)
232233
}
233234
}
234-
step := releasesteps.ImportReleaseStep(resolveConfig.Name, nodeName, resolveConfig.TargetName(), source, false, config.Resources, podClient, jobSpec, pullSecret, overrideCLIReleaseExtractImage)
235+
step := releasesteps.ImportReleaseStep(resolveConfig.Name, nodeName, resolveConfig.TargetName(), imagev1.TagReferencePolicyType(resolveConfig.Integration.ReferencePolicy), source, false, config.Resources, podClient, jobSpec, pullSecret, overrideCLIReleaseExtractImage)
235236
buildSteps = append(buildSteps, step)
236237
addProvidesForStep(step, params)
237238
continue
@@ -283,6 +284,10 @@ func fromConfig(
283284
for _, name := range []string{api.InitialReleaseName, api.LatestReleaseName} {
284285
var releaseStep api.Step
285286
envVar := utils.ReleaseImageEnv(name)
287+
referencePolicy := imagev1.LocalTagReferencePolicy
288+
if rawStep.ReleaseImagesTagStepConfiguration.ReferencePolicy != "" && rawStep.ReleaseImagesTagStepConfiguration.ReferencePolicy == "Source" {
289+
referencePolicy = imagev1.SourceTagReferencePolicy
290+
}
286291
if params.HasInput(envVar) {
287292
pullSpec, err := params.Get(envVar)
288293
if err != nil {
@@ -291,10 +296,11 @@ func fromConfig(
291296
logrus.Infof("Using explicitly provided pull-spec for release %s (%s)", name, pullSpec)
292297
target := rawStep.ReleaseImagesTagStepConfiguration.TargetName(name)
293298
source := releasesteps.NewReleaseSourceFromPullSpec(pullSpec)
294-
releaseStep = releasesteps.ImportReleaseStep(name, nodeName, target, source, true, config.Resources, podClient, jobSpec, pullSecret, nil)
299+
releaseStep = releasesteps.ImportReleaseStep(name, nodeName, target, referencePolicy, source, true, config.Resources, podClient, jobSpec, pullSecret, nil)
295300
} else {
296301
// for backwards compatibility, users get inclusion for free with tag_spec
297302
cfg := *rawStep.ReleaseImagesTagStepConfiguration
303+
cfg.ReferencePolicy = string(referencePolicy)
298304
cfg.IncludeBuiltImages = name == api.LatestReleaseName
299305
releaseStep = releasesteps.AssembleReleaseStep(name, nodeName, &cfg, config.Resources, podClient, jobSpec)
300306
}

pkg/steps/release/import_release.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ import (
4949
// branches of those releases.
5050
type importReleaseStep struct {
5151
// name is the name of the release we're importing, like 'latest'
52-
name string
53-
nodeName string
54-
target string
55-
source ReleaseSource
52+
name string
53+
nodeName string
54+
target string
55+
referencePolicy imagev1.TagReferencePolicyType
56+
source ReleaseSource
5657
// append determines if we wait for other processes to create images first
5758
append bool
5859
resources api.ResourceConfiguration
@@ -97,6 +98,18 @@ func (s *importReleaseStep) run(ctx context.Context) error {
9798
LookupPolicy: imagev1.ImageLookupPolicy{
9899
Local: true,
99100
},
101+
Tags: []imagev1.TagReference{
102+
{
103+
ReferencePolicy: imagev1.TagReferencePolicy{
104+
Type: func() imagev1.TagReferencePolicyType {
105+
if s != nil && s.referencePolicy == imagev1.SourceTagReferencePolicy {
106+
return imagev1.SourceTagReferencePolicy
107+
}
108+
return imagev1.LocalTagReferencePolicy
109+
}(),
110+
},
111+
},
112+
},
100113
},
101114
})
102115
if err != nil && !kerrors.IsAlreadyExists(err) {
@@ -229,11 +242,12 @@ oc create configmap release-%s --from-file=%s.yaml=${ARTIFACT_DIR}/%s
229242
}
230243
}
231244

245+
referencePolicy := imagev1.LocalTagReferencePolicy
232246
existing := sets.New[string]()
233247
tags := make([]imagev1.TagReference, 0, len(releaseIS.Spec.Tags)+len(stable.Spec.Tags))
234248
for _, tag := range releaseIS.Spec.Tags {
235249
existing.Insert(tag.Name)
236-
tag.ReferencePolicy.Type = imagev1.LocalTagReferencePolicy
250+
tag.ReferencePolicy.Type = referencePolicy
237251
tag.ImportPolicy.ImportMode = imagev1.ImportModePreserveOriginal
238252
tags = append(tags, tag)
239253
}
@@ -242,7 +256,7 @@ oc create configmap release-%s --from-file=%s.yaml=${ARTIFACT_DIR}/%s
242256
continue
243257
}
244258
existing.Insert(tag.Name)
245-
tag.ReferencePolicy.Type = imagev1.LocalTagReferencePolicy
259+
tag.ReferencePolicy.Type = referencePolicy
246260
tag.ImportPolicy.ImportMode = imagev1.ImportModePreserveOriginal
247261
tags = append(tags, tag)
248262
}
@@ -315,6 +329,7 @@ func (s *importReleaseStep) Objects() []ctrlruntimeclient.Object {
315329
// ImportReleaseStep imports an existing update payload image
316330
func ImportReleaseStep(
317331
name, nodeName, target string,
332+
referencePolicy imagev1.TagReferencePolicyType,
318333
source ReleaseSource,
319334
append bool,
320335
resources api.ResourceConfiguration,
@@ -326,6 +341,7 @@ func ImportReleaseStep(
326341
name: name,
327342
nodeName: nodeName,
328343
target: target,
344+
referencePolicy: referencePolicy,
329345
source: source,
330346
append: append,
331347
resources: resources,
@@ -345,18 +361,23 @@ func (s *importReleaseStep) getCLIImage(ctx context.Context, target, streamName
345361
// create the imagestream to be able to set it there.
346362
if err := s.client.Create(ctx, &imagev1.ImageStream{
347363
ObjectMeta: metav1.ObjectMeta{Name: overrideCLIStreamName, Namespace: s.jobSpec.Namespace()},
348-
Spec: imagev1.ImageStreamSpec{LookupPolicy: imagev1.ImageLookupPolicy{Local: true}},
364+
Spec: imagev1.ImageStreamSpec{LookupPolicy: imagev1.ImageLookupPolicy{Local: true}, Tags: []imagev1.TagReference{{ReferencePolicy: imagev1.TagReferencePolicy{Type: s.referencePolicy}}}},
349365
}); err != nil && !kerrors.IsAlreadyExists(err) {
350366
return nil, fmt.Errorf("failed to create %s imagestream: %w", overrideCLIStreamName, err)
351367
}
368+
369+
referencePolicy := imagev1.LocalTagReferencePolicy
370+
if s.referencePolicy == imagev1.SourceTagReferencePolicy {
371+
referencePolicy = imagev1.SourceTagReferencePolicy
372+
}
352373
streamTag := &imagev1.ImageStreamTag{
353374
ObjectMeta: meta.ObjectMeta{
354375
Namespace: s.jobSpec.Namespace(),
355376
Name: overrideCLIStreamName + ":latest",
356377
},
357378
Tag: &imagev1.TagReference{
358379
ReferencePolicy: imagev1.TagReferencePolicy{
359-
Type: imagev1.LocalTagReferencePolicy,
380+
Type: referencePolicy,
360381
},
361382
From: s.overrideCLIReleaseExtractImage,
362383
},
@@ -416,14 +437,18 @@ func (s *importReleaseStep) getCLIImage(ctx context.Context, target, streamName
416437
return nil, err
417438
}
418439
// tag the cli image into stable so we use the correct pull secrets from the namespace
440+
referencePolicy := imagev1.LocalTagReferencePolicy
441+
if s.referencePolicy == "source" {
442+
referencePolicy = imagev1.SourceTagReferencePolicy
443+
}
419444
streamTag := &imagev1.ImageStreamTag{
420445
ObjectMeta: meta.ObjectMeta{
421446
Namespace: s.jobSpec.Namespace(),
422447
Name: fmt.Sprintf("%s:cli", streamName),
423448
},
424449
Tag: &imagev1.TagReference{
425450
ReferencePolicy: imagev1.TagReferencePolicy{
426-
Type: imagev1.LocalTagReferencePolicy,
451+
Type: referencePolicy,
427452
},
428453
From: &coreapi.ObjectReference{
429454
Kind: "DockerImage",

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)