This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathworkspace_providers.go
More file actions
140 lines (121 loc) · 5.62 KB
/
workspace_providers.go
File metadata and controls
140 lines (121 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package coder
import (
"context"
"net/http"
)
// WorkspaceProviders defines all available Coder workspace provider targets.
type WorkspaceProviders struct {
Kubernetes []KubernetesProvider `json:"kubernetes"`
}
// KubernetesProvider defines an entity capable of deploying and acting as an ingress for Coder workspaces.
type KubernetesProvider struct {
ID string `json:"id" table:"-"`
Name string `json:"name" table:"Name"`
Status WorkspaceProviderStatus `json:"status" table:"Status"`
BuiltIn bool `json:"built_in" table:"-"`
EnvproxyAccessURL string `json:"envproxy_access_url" table:"Access URL" validate:"required"`
DevurlHost string `json:"devurl_host" table:"Devurl Host"`
OrgWhitelist []string `json:"org_whitelist" table:"-"`
KubeProviderConfig `json:"config" table:"_"`
}
// KubeProviderConfig defines Kubernetes-specific configuration options.
type KubeProviderConfig struct {
ClusterAddress string `json:"cluster_address" table:"Cluster Address"`
DefaultNamespace string `json:"default_namespace" table:"Namespace"`
StorageClass string `json:"storage_class" table:"Storage Class"`
ClusterDomainSuffix string `json:"cluster_domain_suffix" table:"Cluster Domain Suffix"`
SSHEnabled bool `json:"ssh_enabled" table:"SSH Enabled"`
}
// WorkspaceProviderStatus represents the configuration state of a workspace provider.
type WorkspaceProviderStatus string
// Workspace Provider statuses.
const (
WorkspaceProviderPending WorkspaceProviderStatus = "pending"
WorkspaceProviderReady WorkspaceProviderStatus = "ready"
)
// WorkspaceProviderType represents the type of workspace provider.
type WorkspaceProviderType string
// Workspace Provider types.
const (
WorkspaceProviderKubernetes WorkspaceProviderType = "kubernetes"
)
// WorkspaceProviderByID fetches a workspace provider entity by its unique ID.
func (c *DefaultClient) WorkspaceProviderByID(ctx context.Context, id string) (*KubernetesProvider, error) {
var wp KubernetesProvider
err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools/"+id, nil, &wp)
if err != nil {
return nil, err
}
return &wp, nil
}
// WorkspaceProviders fetches all workspace providers known to the Coder control plane.
func (c *DefaultClient) WorkspaceProviders(ctx context.Context) (*WorkspaceProviders, error) {
var providers WorkspaceProviders
err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools", nil, &providers)
if err != nil {
return nil, err
}
return &providers, nil
}
// CreateWorkspaceProviderReq defines the request parameters for creating a new workspace provider entity.
type CreateWorkspaceProviderReq struct {
Name string `json:"name"`
Type WorkspaceProviderType `json:"type"`
Hostname string `json:"hostname"`
ClusterAddress string `json:"cluster_address"`
}
// CreateWorkspaceProviderRes defines the response from creating a new workspace provider entity.
type CreateWorkspaceProviderRes struct {
ID string `json:"id" table:"ID"`
Name string `json:"name" table:"Name"`
Status WorkspaceProviderStatus `json:"status" table:"Status"`
EnvproxyToken string `json:"envproxy_token" table:"Envproxy Token"`
}
// CreateWorkspaceProvider creates a new WorkspaceProvider entity.
func (c *DefaultClient) CreateWorkspaceProvider(ctx context.Context, req CreateWorkspaceProviderReq) (*CreateWorkspaceProviderRes, error) {
var res CreateWorkspaceProviderRes
err := c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools", req, &res)
if err != nil {
return nil, err
}
return &res, nil
}
// DeleteWorkspaceProviderByID deletes a workspace provider entity from the Coder control plane.
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
}
// RenameWorkspaceProviderReq defines the request parameters for changing a workspace provider name.
type RenameWorkspaceProviderReq struct {
Name string `json:"name"`
}
// RenameWorkspaceProvider changes an existing cordoned providers name field.
func (c *DefaultClient) RenameWorkspaceProvider(ctx context.Context, id string, name string) error {
req := RenameWorkspaceProviderReq{Name: name}
err := c.requestBody(ctx, http.MethodPatch, "/api/private/resource-pools/"+id, req, nil)
if err != nil {
return err
}
return nil
}