From 160b7ca175941b0266cde4e1e44a8b9bd932cb1b Mon Sep 17 00:00:00 2001 From: Anik Bhattacharjee Date: Tue, 24 Sep 2024 19:39:58 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Use=20creds=20if=20present=20for=20?= =?UTF-8?q?pulling=20bundle=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/manager/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 55951ca83..fce0dd8ad 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -26,6 +26,7 @@ import ( "time" "github.com/containers/image/v5/types" + "github.com/go-logr/logr" "github.com/spf13/pflag" "go.uber.org/zap/zapcore" apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" @@ -67,6 +68,8 @@ var ( defaultSystemNamespace = "olmv1-system" ) +const authFilePath = "/etc/operator-controller/auth.json" + // podNamespace checks whether the controller is running in a Pod vs. // being run locally by inspecting the namespace file that gets mounted // automatically for Pods at runtime. If that file doesn't exist, then @@ -201,6 +204,7 @@ func main() { SourceContext: &types.SystemContext{ DockerCertPath: caCertDir, OCICertPath: caCertDir, + AuthFilePath: authFilePathIfPresent(setupLog), }, } @@ -311,3 +315,15 @@ type finalizerFunc func(ctx context.Context, obj client.Object) (crfinalizer.Res func (f finalizerFunc) Finalize(ctx context.Context, obj client.Object) (crfinalizer.Result, error) { return f(ctx, obj) } + +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 +}