Skip to content

Commit

Permalink
fix(image-builder): use google keychain for Artifact Registry domains (
Browse files Browse the repository at this point in the history
…#372)

* fix(image-builder): use google keychain for Artifact Registry domains

* fix(image-builder): format code
  • Loading branch information
mbruner authored Mar 19, 2024
1 parent 80ea310 commit 9fc8000
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions api/turing/imagebuilder/imagebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"strings"
"time"

"github.com/caraml-dev/turing/api/turing/cluster"
"github.com/caraml-dev/turing/api/turing/config"
"github.com/caraml-dev/turing/api/turing/log"
"github.com/caraml-dev/turing/api/turing/models"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/google"
Expand All @@ -22,6 +18,11 @@ import (
apicorev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"

"github.com/caraml-dev/turing/api/turing/cluster"
"github.com/caraml-dev/turing/api/turing/config"
"github.com/caraml-dev/turing/api/turing/log"
"github.com/caraml-dev/turing/api/turing/models"
)

var (
Expand Down Expand Up @@ -356,11 +357,22 @@ func (ib *imageBuilder) createKanikoJob(
)
}

// getGCPSubDomains returns the list of GCP container registry and artifact registry subdomains.
//
// GCP container registry and artifact registry domains are used to determine which keychain
// to use when interacting with container registry.
// This is needed because GCP registries use different authentication method than other container registry.
func getGCPSubDomains() []string {
return []string{"gcr.io", "pkg.dev"}
}

func (ib *imageBuilder) checkIfImageExists(imageName string, imageTag string) (bool, error) {
keychain := authn.DefaultKeychain

if strings.Contains(ib.imageBuildingConfig.DestinationRegistry, "gcr.io") {
keychain = google.Keychain
for _, domain := range getGCPSubDomains() {
if strings.Contains(ib.imageBuildingConfig.DestinationRegistry, domain) {
keychain = google.Keychain
}
}

repo, err := name.NewRepository(imageName)
Expand Down

0 comments on commit 9fc8000

Please sign in to comment.