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

onboard delete env command #207

Merged
merged 1 commit into from
Apr 24, 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
16 changes: 16 additions & 0 deletions cmd/delete/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package delete

import (
"github.com/dream11/odin/cmd"
"github.com/spf13/cobra"
)

var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete resources",
Long: `Delete resources`,
}

func init() {
cmd.RootCmd.AddCommand(deleteCmd)
}
40 changes: 40 additions & 0 deletions cmd/delete/environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package delete

import (
"github.com/dream11/odin/internal/service"
environment "github.com/dream11/odin/proto/gen/go/dream11/od/environment/v1"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var name string

var environmentClient = service.Environment{}

var environmentCmd = &cobra.Command{
Use: "environment",
Short: "Delete environment",
Long: `Delete environment`,
Args: func(cmd *cobra.Command, args []string) error {
return cobra.NoArgs(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
execute(cmd)
},
}

func init() {
environmentCmd.Flags().StringVar(&name, "name", "", "name of the env")
deleteCmd.AddCommand(environmentCmd)
}

func execute(cmd *cobra.Command) {
ctx := cmd.Context()
err := environmentClient.DeleteEnvironment(&ctx, &environment.DeleteEnvironmentRequest{
EnvName: name,
})

if err != nil {
log.Fatal("Failed to delete environment ", err)
}
}
40 changes: 38 additions & 2 deletions internal/service/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/briandowns/spinner"
"github.com/dream11/odin/pkg/constant"
environment "github.com/dream11/odin/proto/gen/go/dream11/od/environment/v1"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -54,7 +53,44 @@ func (e *Environment) CreateEnvironment(ctx *context.Context, request *environme
if err == context.Canceled || err == io.EOF {
break
}
log.Error(err.Error())
return err
}
if response != nil {
message = response.Message
spinner.Prefix = fmt.Sprintf(" %s ", response.Message)
spinner.Start()
}
}
log.Info(message)
return err
}

// DeleteEnvironment : Delete environment
func (e *Environment) DeleteEnvironment(ctx *context.Context, request *environment.DeleteEnvironmentRequest) error {
conn, requestCtx, err := grpcClient(ctx)
if err != nil {
return err
}

client := environment.NewEnvironmentServiceClient(conn)
stream, err := client.DeleteEnvironment(*requestCtx, request)

if err != nil {
return err
}

log.Info("Deleting environment...")
spinner := spinner.New(spinner.CharSets[constant.SpinnerType], constant.SpinnerDelay)
spinner.Color(constant.SpinnerColor, constant.SpinnerStyle)

var message string
for {
response, err := stream.Recv()
spinner.Stop()
if err != nil {
if err == context.Canceled || err == io.EOF {
break
}
return err
}
if response != nil {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/dream11/odin/cmd"
_ "github.com/dream11/odin/cmd/configure"
_ "github.com/dream11/odin/cmd/create"
_ "github.com/dream11/odin/cmd/delete"
_ "github.com/dream11/odin/cmd/list"
_ "github.com/dream11/odin/internal/ui"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import "strings"

// SplitProviderAccount: splits string into list of cloud provider accounts

Check failure on line 5 in pkg/util/util.go

View workflow job for this annotation

GitHub Actions / lint

comment on exported function SplitProviderAccount should be of the form "SplitProviderAccount ..."
func SplitProviderAccount(providerAccounts string) []string {
if providerAccounts == "" {
return nil
Expand Down
9 changes: 9 additions & 0 deletions proto/dream11/od/environment/v1/environment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ service EnvironmentService {
rpc DescribeEnvironment(DescribeEnvironmentRequest) returns (DescribeEnvironmentResponse) {}
rpc UpdateEnvironment(UpdateEnvironmentRequest) returns (UpdateEnvironmentResponse) {}
rpc CreateEnvironment(CreateEnvironmentRequest) returns (stream CreateEnvironmentResponse) {}
rpc DeleteEnvironment(DeleteEnvironmentRequest) returns (stream DeleteEnvironmentResponse) {}
}

message ListEnvironmentRequest {
Expand Down Expand Up @@ -46,3 +47,11 @@ message CreateEnvironmentRequest {
message CreateEnvironmentResponse {
string message = 1;
}

message DeleteEnvironmentRequest {
string env_name = 1;
}

message DeleteEnvironmentResponse {
string message = 1;
}
244 changes: 191 additions & 53 deletions proto/gen/go/dream11/od/environment/v1/environment.pb.go

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions proto/gen/go/dream11/od/environment/v1/environment_grpc.pb.go

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

Loading