Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Namespace.ValidateNamespace to add workspace to arguments #7154

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/cmd/env/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
return err
}

err = r.NamespaceInterface.ValidateNamespace(cmd.Context(), r.Namespace)
err = r.NamespaceInterface.ValidateNamespace(cmd.Context(), r.Namespace, *r.Workspace)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmd/env/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ func createMocksWithInvalidResourceGroup(namespaceClient *namespace.MockInterfac

func createValidateNamespaceSuccess(namespaceClient *namespace.MockInterface) {
namespaceClient.EXPECT().
ValidateNamespace(gomock.Any(), "testingenv").
ValidateNamespace(gomock.Any(), "testingenv", gomock.Any()).
Return(nil).Times(1)
}

func createValidateNamespaceError(namespaceClient *namespace.MockInterface) {
namespaceClient.EXPECT().
ValidateNamespace(gomock.Any(), gomock.Any()).
ValidateNamespace(gomock.Any(), gomock.Any(), gomock.Any()).
Return(fmt.Errorf("failed to create namespace")).Times(1)
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/cli/cmd/env/namespace/mock_namespace.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions pkg/cli/cmd/env/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package namespace
import (
"context"

"github.com/radius-project/radius/pkg/cli/clierrors"
"github.com/radius-project/radius/pkg/cli/kubernetes"
"github.com/radius-project/radius/pkg/cli/workspaces"
)

//go:generate mockgen -destination=./mock_namespace.go -package=namespace -self_package github.com/radius-project/radius/pkg/cli/cmd/env/namespace github.com/radius-project/radius/pkg/cli/cmd/env/namespace Interface
type Interface interface {
ValidateNamespace(ctx context.Context, namespace string) error
ValidateNamespace(ctx context.Context, namespace string, workspace workspaces.Workspace) error
}

type Impl struct {
Expand All @@ -35,8 +37,13 @@ type Impl struct {

// ValidateNamespace creates a Kubernetes client and checks if the given namespace exists. If it does not exist, creates it.
// If unsuccessful, returns an error.
func (i *Impl) ValidateNamespace(ctx context.Context, namespace string) error {
client, _, err := kubernetes.NewClientset("")
func (i *Impl) ValidateNamespace(ctx context.Context, namespace string, workspace workspaces.Workspace) error {
// get the current kubernetes context from the workspace
kubernetesContext, hasContext := workspace.KubernetesContext()
if !hasContext {
return clierrors.Message("no kubernetes context found in the current workspace")
}
client, _, err := kubernetes.NewClientset(kubernetesContext)
if err != nil {
return err
}
Expand Down
Loading