Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 0b0fd54

Browse files
committed
Merge origin/master
2 parents 721a927 + ca68fdb commit 0b0fd54

File tree

10 files changed

+335
-116
lines changed

10 files changed

+335
-116
lines changed

.github/workflows/test.yaml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ on: [push]
33

44
jobs:
55
fmt:
6-
runs-on: ubuntu-latest
6+
runs-on: ubuntu-20.04
77
steps:
8-
- uses: actions/checkout@v1
9-
- uses: actions/cache@v1
8+
- uses: actions/checkout@v2
9+
- uses: actions/cache@v2
1010
with:
1111
path: ~/go/pkg/mod
1212
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
@@ -18,33 +18,35 @@ jobs:
1818
args: make -j fmt
1919
- run: ./ci/scripts/files_changed.sh
2020
lint:
21-
runs-on: ubuntu-latest
21+
runs-on: ubuntu-20.04
2222
steps:
2323
- uses: actions/checkout@v2
2424
- name: golangci-lint
2525
uses: golangci/golangci-lint-action@v2
2626
with:
2727
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
28-
version: v1.29
28+
version: v1.36
2929
test:
30-
runs-on: ubuntu-latest
30+
runs-on: ubuntu-20.04
3131
steps:
32-
- uses: actions/checkout@v1
33-
- uses: actions/cache@v1
32+
- uses: actions/checkout@v2
33+
- uses: actions/cache@v2
3434
with:
3535
path: ~/go/pkg/mod
3636
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3737
restore-keys: |
3838
${{ runner.os }}-go-
3939
- name: test
4040
uses: ./ci/image
41+
env:
42+
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4143
with:
42-
args: make -j test/go
44+
args: make -j test/coverage
4345
gendocs:
44-
runs-on: ubuntu-latest
46+
runs-on: ubuntu-20.04
4547
steps:
46-
- uses: actions/checkout@v1
47-
- uses: actions/cache@v1
48+
- uses: actions/checkout@v2
49+
- uses: actions/cache@v2
4850
with:
4951
path: ~/go/pkg/mod
5052
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ gendocs:
3333

3434
test/go:
3535
go test $$(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk)
36+
37+
test/coverage:
38+
go test \
39+
-race \
40+
-covermode atomic \
41+
-coverprofile coverage \
42+
$$(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk)
43+
44+
goveralls -coverprofile=coverage -service=github

coder-sdk/resourcepools.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

coder-sdk/workspace_providers.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package coder
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
// WorkspaceProvider defines an entity capable of deploying and acting as an ingress for Coder environments.
9+
type WorkspaceProvider struct {
10+
ID string `json:"id" table:"-"`
11+
Name string `json:"name" table:"Name"`
12+
Status WorkspaceProviderStatus `json:"status" table:"Status"`
13+
Local bool `json:"local" table:"-"`
14+
ClusterAddress string `json:"cluster_address" table:"Cluster Address"`
15+
DefaultNamespace string `json:"default_namespace" table:"Namespace"`
16+
StorageClass string `json:"storage_class" table:"Storage Class"`
17+
ClusterDomainSuffix string `json:"cluster_domain_suffix" table:"Cluster Domain Suffix"`
18+
EnvproxyAccessURL string `json:"envproxy_access_url" validate:"required" table:"Access URL"`
19+
DevurlHost string `json:"devurl_host" table:"Devurl Host"`
20+
SSHEnabled bool `json:"ssh_enabled" table:"SSH Enabled"`
21+
NamespaceWhitelist []string `json:"namespace_whitelist" table:"Namespace Allowlist"`
22+
OrgWhitelist []string `json:"org_whitelist" table:"-"`
23+
}
24+
25+
// WorkspaceProviderStatus represents the configuration state of a workspace provider.
26+
type WorkspaceProviderStatus string
27+
28+
// Workspace Provider statuses.
29+
const (
30+
WorkspaceProviderPending WorkspaceProviderStatus = "pending"
31+
WorkspaceProviderReady WorkspaceProviderStatus = "ready"
32+
)
33+
34+
// WorkspaceProviderByID fetches a workspace provider entity by its unique ID.
35+
func (c *Client) WorkspaceProviderByID(ctx context.Context, id string) (*WorkspaceProvider, error) {
36+
var wp WorkspaceProvider
37+
err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools/"+id, nil, &wp)
38+
if err != nil {
39+
return nil, err
40+
}
41+
return &wp, nil
42+
}
43+
44+
// WorkspaceProviders fetches all workspace providers known to the Coder control plane.
45+
func (c *Client) WorkspaceProviders(ctx context.Context) ([]WorkspaceProvider, error) {
46+
var providers []WorkspaceProvider
47+
err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools", nil, &providers)
48+
if err != nil {
49+
return nil, err
50+
}
51+
return providers, nil
52+
}
53+
54+
// CreateWorkspaceProviderReq defines the request parameters for creating a new workspace provider entity.
55+
type CreateWorkspaceProviderReq struct {
56+
Name string `json:"name"`
57+
}
58+
59+
// CreateWorkspaceProviderRes defines the response from creating a new workspace provider entity.
60+
type CreateWorkspaceProviderRes struct {
61+
ID string `json:"id" table:"ID"`
62+
Name string `json:"name" table:"Name"`
63+
Status WorkspaceProviderStatus `json:"status" table:"Status"`
64+
EnvproxyToken string `json:"envproxy_token" table:"Envproxy Token"`
65+
}
66+
67+
// CreateWorkspaceProvider creates a new WorkspaceProvider entity.
68+
func (c *Client) CreateWorkspaceProvider(ctx context.Context, req CreateWorkspaceProviderReq) (*CreateWorkspaceProviderRes, error) {
69+
var res CreateWorkspaceProviderRes
70+
err := c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools", req, &res)
71+
if err != nil {
72+
return nil, err
73+
}
74+
return &res, nil
75+
}
76+
77+
// DeleteWorkspaceProviderByID deletes a workspace provider entity from the Coder control plane.
78+
func (c *Client) DeleteWorkspaceProviderByID(ctx context.Context, id string) error {
79+
return c.requestBody(ctx, http.MethodDelete, "/api/private/resource-pools/"+id, nil, nil)
80+
}

internal/cmd/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func Make() *cobra.Command {
3737
resourceCmd(),
3838
completionCmd(),
3939
imgsCmd(),
40+
providersCmd(),
4041
genDocsCmd(app),
4142
autostartCmd(),
4243
)

internal/cmd/configssh.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
104104
return xerrors.New("no environments found")
105105
}
106106

107-
envsWithPools, err := coderutil.EnvsWithPool(ctx, client, envs)
107+
envsWithProviders, err := coderutil.EnvsWithProvider(ctx, client, envs)
108108
if err != nil {
109-
return xerrors.Errorf("resolve env pools: %w", err)
109+
return xerrors.Errorf("resolve env workspace providers: %w", err)
110110
}
111111

112-
if !sshAvailable(envsWithPools) {
112+
if !sshAvailable(envsWithProviders) {
113113
return xerrors.New("SSH is disabled or not available for any environments in your Coder Enterprise deployment.")
114114
}
115115

116-
newConfig := makeNewConfigs(user.Username, envsWithPools, privateKeyFilepath)
116+
newConfig := makeNewConfigs(user.Username, envsWithProviders, privateKeyFilepath)
117117

118118
err = os.MkdirAll(filepath.Dir(*configpath), os.ModePerm)
119119
if err != nil {
@@ -157,9 +157,9 @@ func removeOldConfig(config string) (string, bool) {
157157
}
158158

159159
// sshAvailable returns true if SSH is available for at least one environment.
160-
func sshAvailable(envs []coderutil.EnvWithPool) bool {
160+
func sshAvailable(envs []coderutil.EnvWithWorkspaceProvider) bool {
161161
for _, env := range envs {
162-
if env.Pool.SSHEnabled {
162+
if env.WorkspaceProvider.SSHEnabled {
163163
return true
164164
}
165165
}
@@ -174,19 +174,19 @@ func writeSSHKey(ctx context.Context, client *coder.Client, privateKeyPath strin
174174
return ioutil.WriteFile(privateKeyPath, []byte(key.PrivateKey), 0600)
175175
}
176176

177-
func makeNewConfigs(userName string, envs []coderutil.EnvWithPool, privateKeyFilepath string) string {
177+
func makeNewConfigs(userName string, envs []coderutil.EnvWithWorkspaceProvider, privateKeyFilepath string) string {
178178
newConfig := fmt.Sprintf("\n%s\n%s\n\n", sshStartToken, sshStartMessage)
179179
for _, env := range envs {
180-
if !env.Pool.SSHEnabled {
181-
clog.LogWarn(fmt.Sprintf("SSH is not enabled for pool %q", env.Pool.Name),
180+
if !env.WorkspaceProvider.SSHEnabled {
181+
clog.LogWarn(fmt.Sprintf("SSH is not enabled for workspace provider %q", env.WorkspaceProvider.Name),
182182
clog.BlankLine,
183-
clog.Tipf("ask an infrastructure administrator to enable SSH for this resource pool"),
183+
clog.Tipf("ask an infrastructure administrator to enable SSH for this workspace provider"),
184184
)
185185
continue
186186
}
187-
u, err := url.Parse(env.Pool.AccessURL)
187+
u, err := url.Parse(env.WorkspaceProvider.EnvproxyAccessURL)
188188
if err != nil {
189-
clog.LogWarn("invalid access url", clog.Causef("malformed url: %q", env.Pool.AccessURL))
189+
clog.LogWarn("invalid access url", clog.Causef("malformed url: %q", env.WorkspaceProvider.EnvproxyAccessURL))
190190
continue
191191
}
192192
newConfig += makeSSHConfig(u.Host, userName, env.Env.Name, privateKeyFilepath)
@@ -203,6 +203,7 @@ func makeSSHConfig(host, userName, envName, privateKeyFilepath string) string {
203203
User %s-%s
204204
StrictHostKeyChecking no
205205
ConnectTimeout=0
206+
IdentitiesOnly yes
206207
IdentityFile="%s"
207208
ServerAliveInterval 60
208209
ServerAliveCountMax 3

0 commit comments

Comments
 (0)