Skip to content

Commit

Permalink
Merge branch 'main' into simulatedenv-recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayada1 authored Feb 12, 2024
2 parents 3f5cd64 + 647c0c7 commit ed54654
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
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

0 comments on commit ed54654

Please sign in to comment.