diff --git a/cmd/context/create.go b/cmd/context/create.go index d29faed1a54f..f330bf713627 100644 --- a/cmd/context/create.go +++ b/cmd/context/create.go @@ -121,6 +121,17 @@ func UseContext(ctx context.Context, ctxOptions *ContextOptions) error { return err } } + if ctxOptions.isOkteto && ctxOptions.Save { + hasAccess, err := utils.HasAccessToNamespace(ctx, ctxOptions.Namespace) + if err != nil { + return err + } + if !hasAccess { + return errors.UserError{E: fmt.Errorf("namespace '%s' not found on context '%s'", ctxOptions.Namespace, ctxOptions.Context), + Hint: "Please verify that the namespace exists and that you have access to it.", + } + } + } if ctxOptions.Save { if err := okteto.WriteOktetoContextConfig(); err != nil { return err