Skip to content

Commit da631e3

Browse files
akurinnoyclaude
andcommitted
fix: return error when operator namespace cannot be resolved
Return an error instead of silently returning nil when infrastructure.GetNamespace() fails on the restore path. This makes auth failures visible immediately rather than causing a confusing image pull error later. Also properly save and restore the WATCH_NAMESPACE env var in tests. Assisted-by: Claude Code Signed-off-by: Oleksii Kurinnyi <okurynny@redhat.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
1 parent 925f3bb commit da631e3

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

pkg/secrets/backup.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ func HandleRegistryAuthSecret(ctx context.Context, c client.Client, workspace *d
6363
if operatorConfigNamespace == "" {
6464
resolvedNS, nsErr := infrastructure.GetNamespace()
6565
if nsErr != nil {
66-
log.Info("Cannot resolve operator namespace for auth secret fallback", "error", nsErr)
67-
return nil, nil
66+
return nil, fmt.Errorf("cannot resolve operator namespace to copy registry auth secret: %w", nsErr)
6867
}
6968
operatorConfigNamespace = resolvedNS
7069
}

pkg/secrets/backup_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ var _ = Describe("HandleRegistryAuthSecret (restore path: operatorConfigNamespac
117117
Expect(result.Name).To(Equal(constants.DevWorkspaceBackupAuthSecretName))
118118
})
119119

120-
It("returns nil when the predefined secret does not exist in the workspace namespace", func() {
121-
By("using a fake client with no secrets")
120+
It("returns error when secret is missing and operator namespace cannot be resolved", func() {
121+
By("using a fake client with no secrets and no WATCH_NAMESPACE set")
122122
fakeClient := fake.NewClientBuilder().WithScheme(scheme).Build()
123123
workspace := makeWorkspace(workspaceNS)
124124
config := makeConfig("quay-backup-auth")
125125

126126
result, err := secrets.HandleRegistryAuthSecret(ctx, fakeClient, workspace, config, "", scheme, log)
127-
Expect(err).NotTo(HaveOccurred())
127+
Expect(err).To(HaveOccurred())
128+
Expect(err.Error()).To(ContainSubstring("cannot resolve operator namespace"))
128129
Expect(result).To(BeNil())
129130
})
130131

@@ -271,19 +272,26 @@ var _ = Describe("HandleRegistryAuthSecret (restore path: fallback to operator n
271272
)
272273

273274
var (
274-
ctx context.Context
275-
scheme *runtime.Scheme
276-
log = zap.New(zap.UseDevMode(true)).WithName("SecretsTest")
275+
ctx context.Context
276+
scheme *runtime.Scheme
277+
log = zap.New(zap.UseDevMode(true)).WithName("SecretsTest")
278+
origWatchNS string
279+
hadWatchNS bool
277280
)
278281

279282
BeforeEach(func() {
280283
ctx = context.Background()
281284
scheme = buildScheme()
285+
origWatchNS, hadWatchNS = os.LookupEnv(infrastructure.WatchNamespaceEnvVar)
282286
os.Setenv(infrastructure.WatchNamespaceEnvVar, operatorNS)
283287
})
284288

285289
AfterEach(func() {
286-
os.Unsetenv(infrastructure.WatchNamespaceEnvVar)
290+
if hadWatchNS {
291+
os.Setenv(infrastructure.WatchNamespaceEnvVar, origWatchNS)
292+
} else {
293+
os.Unsetenv(infrastructure.WatchNamespaceEnvVar)
294+
}
287295
})
288296

289297
It("copies the secret from operator namespace when missing in workspace namespace", func() {

0 commit comments

Comments
 (0)