Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for Coder CLI

.PHONY: clean build build/macos build/windows build/linux fmt lint gendocs test/go
.PHONY: clean build build/macos build/windows build/linux fmt lint gendocs test/go dev

PROJECT_ROOT := $(shell git rev-parse --show-toplevel)
MAKE_ROOT := $(shell pwd)
Expand Down Expand Up @@ -42,3 +42,10 @@ test/coverage:
$$(go list ./... | grep -v pkg/tcli | grep -v ci/integration)

goveralls -coverprofile=coverage -service=github

dev: build/linux
@echo "removing project root binary if exists"
-rm ./coder
@echo "untarring..."
@tar -xzf ./ci/bin/coder-cli-linux-amd64.tar.gz
@echo "new dev binary ready"
Binary file added coder
Binary file not shown.
7 changes: 7 additions & 0 deletions coder-sdk/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,11 @@ type Client interface {

// BaseURL returns the BaseURL configured for this Client.
BaseURL() url.URL

// CordonWorkspaceProvider prevents the provider from having any more workspaces placed on it.
CordonWorkspaceProvider(ctx context.Context, id, reason string) error

// UnCordonWorkspaceProvider changes an existing cordoned providers status to 'Ready';
// allowing it to continue creating new workspaces and provisioning resources for them.
UnCordonWorkspaceProvider(ctx context.Context, id string) error
}
25 changes: 25 additions & 0 deletions coder-sdk/workspace_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,28 @@ func (c *DefaultClient) CreateWorkspaceProvider(ctx context.Context, req CreateW
func (c *DefaultClient) DeleteWorkspaceProviderByID(ctx context.Context, id string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/resource-pools/"+id, nil, nil)
}

// CordoneWorkspaceProviderReq defines the request parameters for creating a new workspace provider entity.
type CordoneWorkspaceProviderReq struct {
Reason string `json:"reason"`
}

// CordonWorkspaceProvider prevents the provider from having any more workspaces placed on it.
func (c *DefaultClient) CordonWorkspaceProvider(ctx context.Context, id, reason string) error {
req := CordoneWorkspaceProviderReq{Reason: reason}
err := c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools/"+id+"/cordon", req, nil)
if err != nil {
return err
}
return nil
}

// UnCordonWorkspaceProvider changes an existing cordoned providers status to 'Ready';
// allowing it to continue creating new workspaces and provisioning resources for them.
func (c *DefaultClient) UnCordonWorkspaceProvider(ctx context.Context, id string) error {
err := c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools/"+id+"/uncordon", nil, nil)
if err != nil {
return err
}
return nil
}
69 changes: 69 additions & 0 deletions internal/cmd/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/url"

"cdr.dev/coder-cli/internal/coderutil"
"cdr.dev/coder-cli/internal/x/xcobra"

"github.com/spf13/cobra"
Expand All @@ -26,6 +27,8 @@ func providersCmd() *cobra.Command {
createProviderCmd(),
listProviderCmd(),
deleteProviderCmd(),
cordonProviderCmd(),
unCordonProviderCmd(),
)
return cmd
}
Expand Down Expand Up @@ -215,3 +218,69 @@ coder providers rm my-workspace-provider`,
}
return cmd
}

func cordonProviderCmd() *cobra.Command {
var reason string

cmd := &cobra.Command{
Use: "cordon [workspace_provider_name]",
Args: xcobra.ExactArgs(1),
Short: "cordon a workspace provider.",
Long: "Prevent an existing Coder workspace provider from supporting any additional workspaces.",
Example: `# cordon an existing workspace provider by name
coder providers cordon my-workspace-provider --reason "limit cloud clost"`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
client, err := newClient(ctx)
if err != nil {
return err
}

wpName := args[0]
provider, err := coderutil.ProviderByName(ctx, client, wpName)
if err != nil {
return err
}

if err := client.CordonWorkspaceProvider(ctx, provider.ID, reason); err != nil {
return err
}
clog.LogSuccess(fmt.Sprintf("provider %q successfully cordoned - you can no longer create workspaces on this provider without uncordoning first", wpName))
return nil
},
}
cmd.Flags().StringVar(&reason, "reason", "", "reason for cordoning the provider")
_ = cmd.MarkFlagRequired("reason")
return cmd
}

func unCordonProviderCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "uncordon [workspace_provider_name]",
Args: xcobra.ExactArgs(1),
Short: "uncordon a workspace provider.",
Long: "Set a currently cordoned provider as ready; enabling it to continue provisioning resources for new workspaces.",
Example: `# uncordon an existing workspace provider by name
coder providers uncordon my-workspace-provider`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
client, err := newClient(ctx)
if err != nil {
return err
}

wpName := args[0]
provider, err := coderutil.ProviderByName(ctx, client, wpName)
if err != nil {
return err
}

if err := client.UnCordonWorkspaceProvider(ctx, provider.ID); err != nil {
return err
}
clog.LogSuccess(fmt.Sprintf("provider %q successfully uncordoned - you can now create workspaces on this provider", wpName))
return nil
},
}
return cmd
}