Skip to content

Commit

Permalink
Merge pull request #1418 from hongkailiu/prefix
Browse files Browse the repository at this point in the history
registrysyncer: support imageStreamPrefixes
  • Loading branch information
openshift-merge-robot authored Nov 16, 2020
2 parents cb2996e + e06b30c commit df0a006
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cmd/dptp-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion pkg/controller/registrysyncer/registrysyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -44,6 +45,7 @@ func AddToManager(mgr manager.Manager,
pullSecretGetter: pullSecretGetter,
imageStreamTags: imageStreamTags,
imageStreams: imageStreams,
imageStreamPrefixes: imageStreamPrefixes,
imageStreamNamespaces: imageStreamNamespaces,
}
for clusterName, m := range managers {
Expand All @@ -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)
}
Expand Down Expand Up @@ -97,6 +99,7 @@ type reconciler struct {
pullSecretGetter func() []byte
imageStreamTags sets.String
imageStreams sets.String
imageStreamPrefixes sets.String
imageStreamNamespaces sets.String
}

Expand Down Expand Up @@ -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")
Expand All @@ -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
}
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/controller/registrysyncer/registrysyncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"},
Expand All @@ -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)
}
Expand Down

0 comments on commit df0a006

Please sign in to comment.