Allow pkg.dev repositories to make gcr subscriptions

pull/653/head
Sebastian Köttinger 2022-02-01 15:31:59 +01:00
parent 74a5f3b0c2
commit fec2590a84
2 changed files with 16 additions and 4 deletions

View File

@ -3,7 +3,7 @@ package pubsub
import (
"io/ioutil"
"net/http"
"strings"
"regexp"
log "github.com/sirupsen/logrus"
)
@ -51,10 +51,17 @@ func getClusterName(metadataEndpoint string) (string, error) {
return string(body), nil
}
// isGoogleContainerRegistry - we only care about gcr.io images,
// isGoogleContainerRegistry - we only care about gcr.io and pkg.dev images,
// with other registries - we won't be able to receive events.
// Theoretically if someone publishes messages for updated images to
// google pubsub - we could turn this off
func isGoogleContainerRegistry(registry string) bool {
return strings.Contains(registry, "gcr.io")
}
matched, err := regexp.MatchString(`(gcr\.io|pkg\.dev)`, registry)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Warn("trigger.pubsub.isGoogleContainerRegistry: got error while checking if registry is gcr")
return false
}
return matched
}

View File

@ -30,6 +30,11 @@ func Test_isGoogleContainerRegistry(t *testing.T) {
args: args{registry: unsafeImageRef("gcr.io/v2-namespace/hello-world:1.1").Registry()},
want: true,
},
{
name: "google artifact registry",
args: args{registry: unsafeImageRef("europe-west3-docker.pkg.dev/v2-namespace/hello-world:1.1").Registry()},
want: true,
},
{
name: "docker registry",
args: args{registry: unsafeImageRef("docker.io/v2-namespace/hello-world:1.1").Registry()},