Skip to content

Commit

Permalink
chore(util): Only check if namespace exists when no pods are found
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 14, 2024
1 parent afd3f82 commit 4a5e558
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/util/cmd_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) er
conf.Context = conf.Client.Context
conf.Namespace = conf.Client.Namespace

if _, err := conf.Client.Namespaces().Get(ctx, conf.Namespace, metav1.GetOptions{}); err != nil {
slog.Warn("Namespace may not exist", "error", err)
}

podFlag, err := cmd.Flags().GetString(consts.PodFlag)
if err != nil {
panic(err)
Expand All @@ -73,6 +69,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) er
}
pod, err := conf.Client.Pods().Get(ctx, podFlag, metav1.GetOptions{})
if err != nil {
checkNamespaceExists(ctx, conf)
return err
}
pods = []corev1.Pod{*pod}
Expand All @@ -87,6 +84,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) er
if len(pods) == 0 {
result, err := database.DetectDialect(ctx, conf.Client)
if err != nil {
checkNamespaceExists(ctx, conf)
return err
}
if len(result) == 1 || opts.NoSurvey {
Expand Down Expand Up @@ -116,6 +114,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) er
} else {
conf.Dialect, err = database.DetectDialectFromPod(pods[0])
if err != nil {
checkNamespaceExists(ctx, conf)
return err
}
}
Expand Down Expand Up @@ -533,3 +532,9 @@ func jobPodNameLabel(conf *config.Global, job *batchv1.Job) (string, string) {
}
return key, job.Name
}

func checkNamespaceExists(ctx context.Context, conf *config.Global) {
if _, err := conf.Client.Namespaces().Get(ctx, conf.Namespace, metav1.GetOptions{}); err != nil {
slog.Warn("Namespace may not exist", "error", err)
}
}

0 comments on commit 4a5e558

Please sign in to comment.