diff --git a/cmd/dptp-controller-manager/main.go b/cmd/dptp-controller-manager/main.go index e711ad8b0b3..cc1bcab6ae0 100644 --- a/cmd/dptp-controller-manager/main.go +++ b/cmd/dptp-controller-manager/main.go @@ -90,6 +90,8 @@ type registrySyncerOptions struct { imageStreamTags sets.String imageStreamsRaw flagutil.Strings imageStreams sets.String + imageStreamPrefixesRaw flagutil.Strings + imageStreamPrefixes sets.String imageStreamNamespacesRaw flagutil.Strings imageStreamNamespaces sets.String } @@ -126,6 +128,7 @@ func newOpts() (*options, error) { flag.Var(&opts.testImagesDistributorOptions.additionalImageStreamNamespacesRaw, "testImagesDistributorOptions.additional-image-stream-namespace", "A namespace in which imagestreams will be distributed even if no test explicitly references them (e.G `ci`). Can be passed multiple times.") flag.Var(&opts.registrySyncerOptions.imageStreamTagsRaw, "registrySyncerOptions.image-stream-tag", "An imagestreamtag that will be synced. It must be in namespace/name:tag format (e.G `ci/clonerefs:latest`). Can be passed multiple times.") flag.Var(&opts.registrySyncerOptions.imageStreamsRaw, "registrySyncerOptions.image-stream", "An imagestream that will be synced. It must be in namespace/name format (e.G `ci/clonerefs`). Can be passed multiple times.") + flag.Var(&opts.registrySyncerOptions.imageStreamPrefixesRaw, "registrySyncerOptions.image-stream-prefix", "An imagestream prefix that will be synced. It must be in namespace/name format (e.G `ci/clonerefs`). Can be passed multiple times.") flag.Var(&opts.registrySyncerOptions.imageStreamNamespacesRaw, "registrySyncerOptions.image-stream-namespace", "A namespace in which imagestreams will be synced (e.G `ci`). Can be passed multiple times.") flag.Var(&opts.testImagesDistributorOptions.forbiddenRegistriesRaw, "testImagesDistributorOptions.forbidden-registry", "The hostname of an image registry from which there is no synchronization of its images. Can be passed multiple times.") flag.StringVar(&opts.registrySyncerOptions.imagePullSecretPath, "registrySyncerOptions.imagePullSecretPath", "", "A file to use for reading an ImagePullSecret that will be bound to all `default` ServiceAccounts in all namespaces that have a test ImageStream on all build clusters") @@ -174,6 +177,10 @@ func newOpts() (*options, error) { errs = append(errs, isErrors...) opts.registrySyncerOptions.imageStreams = imageStreams + imageStreamPrefixes, isErrors := completeImageStream("registrySyncerOptions.image-stream-prefix", opts.registrySyncerOptions.imageStreamPrefixesRaw) + errs = append(errs, isErrors...) + opts.registrySyncerOptions.imageStreamPrefixes = imageStreamPrefixes + opts.registrySyncerOptions.imageStreamNamespaces = completeSet(opts.registrySyncerOptions.imageStreamNamespacesRaw) if opts.enabledControllersSet.Has(testimagesdistributor.ControllerName) && opts.stepConfigPath == "" { @@ -459,6 +466,7 @@ func main() { secretAgent.GetTokenGenerator(opts.registrySyncerOptions.imagePullSecretPath), opts.registrySyncerOptions.imageStreamTags, opts.registrySyncerOptions.imageStreams, + opts.registrySyncerOptions.imageStreamPrefixes, opts.registrySyncerOptions.imageStreamNamespaces, ); err != nil { logrus.WithError(err).Fatal("failed to add registrysyncer") diff --git a/pkg/controller/registrysyncer/registrysyncer.go b/pkg/controller/registrysyncer/registrysyncer.go index 18641b78f12..474beb11f70 100644 --- a/pkg/controller/registrysyncer/registrysyncer.go +++ b/pkg/controller/registrysyncer/registrysyncer.go @@ -35,6 +35,7 @@ func AddToManager(mgr manager.Manager, pullSecretGetter func() []byte, imageStreamTags sets.String, imageStreams sets.String, + imageStreamPrefixes sets.String, imageStreamNamespaces sets.String, ) error { log := logrus.WithField("controller", ControllerName) @@ -44,6 +45,7 @@ func AddToManager(mgr manager.Manager, pullSecretGetter: pullSecretGetter, imageStreamTags: imageStreamTags, imageStreams: imageStreams, + imageStreamPrefixes: imageStreamPrefixes, imageStreamNamespaces: imageStreamNamespaces, } for clusterName, m := range managers { @@ -64,7 +66,7 @@ func AddToManager(mgr manager.Manager, for _, m := range managers { if err := c.Watch( source.NewKindWithCache(&imagev1.ImageStream{}, m.GetCache()), - handlerFactory(testInputImageStreamTagFilterFactory(log, imageStreamTags, imageStreams, imageStreamNamespaces)), + handlerFactory(testInputImageStreamTagFilterFactory(log, imageStreamTags, imageStreams, imageStreamPrefixes, imageStreamNamespaces)), ); err != nil { return fmt.Errorf("failed to create watch for ImageStreams: %w", err) } @@ -97,6 +99,7 @@ type reconciler struct { pullSecretGetter func() []byte imageStreamTags sets.String imageStreams sets.String + imageStreamPrefixes sets.String imageStreamNamespaces sets.String } @@ -307,6 +310,7 @@ func testInputImageStreamTagFilterFactory( l *logrus.Entry, imageStreamTags sets.String, imageStreams sets.String, + imageStreamPrefixes sets.String, imageStreamNamespaces sets.String, ) objectFilter { l = logrus.WithField("subcomponent", "test-input-image-stream-tag-filter") @@ -325,6 +329,11 @@ func testInputImageStreamTagFilterFactory( if imageStreams.Has(imageStreamName.String()) { return true } + for _, prefix := range imageStreamPrefixes.List() { + if strings.HasPrefix(imageStreamName.String(), prefix) { + return true + } + } return false } } diff --git a/pkg/controller/registrysyncer/registrysyncer_test.go b/pkg/controller/registrysyncer/registrysyncer_test.go index 30ef7ee4829..93964b3f828 100644 --- a/pkg/controller/registrysyncer/registrysyncer_test.go +++ b/pkg/controller/registrysyncer/registrysyncer_test.go @@ -482,6 +482,7 @@ func TestTestInputImageStreamTagFilterFactory(t *testing.T) { l *logrus.Entry imageStreamTags sets.String imageStreams sets.String + imageStreamPrefixes sets.String imageStreamNamespaces sets.String nn types.NamespacedName expected bool @@ -508,6 +509,17 @@ func TestTestInputImageStreamTagFilterFactory(t *testing.T) { imageStreamNamespaces: sets.NewString("some-namespace"), expected: true, }, + { + name: "imageStreamPrefixes: true", + nn: types.NamespacedName{Namespace: "openshift", Name: "knative-v0.11.0:knative-eventing-sources-heartbeats-receiver"}, + imageStreamPrefixes: sets.NewString("openshift/knative-"), + expected: true, + }, + { + name: "imageStreamPrefixes: false", + nn: types.NamespacedName{Namespace: "openshift", Name: "ruby:2.3"}, + imageStreamPrefixes: sets.NewString("openshift/knative-"), + }, { name: "not valid isTag name", nn: types.NamespacedName{Namespace: "some-namespace", Name: "not-valid-name"}, @@ -517,7 +529,7 @@ func TestTestInputImageStreamTagFilterFactory(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { tc.l = logrus.WithField("tc.name", tc.name) - objectFilter := testInputImageStreamTagFilterFactory(tc.l, tc.imageStreamTags, tc.imageStreams, tc.imageStreamNamespaces) + objectFilter := testInputImageStreamTagFilterFactory(tc.l, tc.imageStreamTags, tc.imageStreams, tc.imageStreamPrefixes, tc.imageStreamNamespaces) if diff := cmp.Diff(tc.expected, objectFilter(tc.nn)); diff != "" { t.Errorf("actual does not match expected, diff: %s", diff) }