From 8cd2cf1e064d5963b6c767dcb059549dd2fb72b2 Mon Sep 17 00:00:00 2001 From: Anik Bhattacharjee Date: Thu, 26 Sep 2024 16:15:09 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Use=20default=20creds=20if=20presen?= =?UTF-8?q?t=20for=20pulling=20catalog=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/manager/main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/manager/main.go b/cmd/manager/main.go index bb0b6df3..4ea1b9e0 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -27,6 +27,7 @@ import ( "time" "github.com/containers/image/v5/types" + "github.com/go-logr/logr" "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -58,7 +59,10 @@ var ( setupLog = ctrl.Log.WithName("setup") ) -const storageDir = "catalogs" +const ( + storageDir = "catalogs" + authFilePath = "/etc/catalogd/auth.json" +) func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) @@ -188,6 +192,7 @@ func main() { SourceContext: &types.SystemContext{ OCICertPath: caCertDir, DockerCertPath: caCertDir, + AuthFilePath: authFilePathIfPresent(setupLog), }, } @@ -286,3 +291,15 @@ func podNamespace() string { } return string(namespace) } + +func authFilePathIfPresent(logger logr.Logger) string { + _, err := os.Stat(authFilePath) + if os.IsNotExist(err) { + return "" + } + if err != nil { + logger.Error(err, "could not stat auth file path", "path", authFilePath) + os.Exit(1) + } + return authFilePath +}