From 7bd23e9ac3929e258222df67b8d727709fd89f18 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Wed, 13 Jan 2021 19:33:15 -0600 Subject: [PATCH 1/3] feat: add coder-sdk methods for multi-cluster --- coder-sdk/resourcepools.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 coder-sdk/resourcepools.go diff --git a/coder-sdk/resourcepools.go b/coder-sdk/resourcepools.go new file mode 100644 index 00000000..0972cc90 --- /dev/null +++ b/coder-sdk/resourcepools.go @@ -0,0 +1,43 @@ +package coder + +import ( + "context" + "net/http" +) + +// ResourcePool defines an entity capable of deploying and acting as an ingress for Coder environments. +type ResourcePool struct { + ID string `json:"id"` + Name string `json:"name"` + Local bool `json:"local"` + ClusterAddress string `json:"cluster_address"` + DefaultNamespace string `json:"default_namespace"` + StorageClass string `json:"storage_class"` + ClusterDomainSuffix string `json:"cluster_domain_suffix"` + DevurlHost string `json:"devurl_host"` + NamespaceWhitelist []string `json:"namespace_whitelist"` + OrgWhitelist []string `json:"org_whitelist"` +} + +// ResourcePoolByID fetches a resource pool entity by its unique ID. +func (c *Client) ResourcePoolByID(ctx context.Context, id string) (*ResourcePool, error) { + var rp ResourcePool + if err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools/"+id, nil, &rp); err != nil { + return nil, err + } + return &rp, nil +} + +// DeleteResourcePoolByID deletes a resource pool entity from the Coder control plane. +func (c *Client) DeleteResourcePoolByID(ctx context.Context, id string) error { + return c.requestBody(ctx, http.MethodDelete, "/api/private/resource-pools/"+id, nil, nil) +} + +// ResourcePools fetches all resource pools known to the Coder control plane. +func (c *Client) ResourcePools(ctx context.Context) ([]ResourcePool, error) { + var pools []ResourcePool + if err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools", nil, &pools); err != nil { + return nil, err + } + return pools, nil +} From eea064568bb06b55eb56fd7f0a259d0605ca4f4e Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Thu, 14 Jan 2021 10:10:57 -0600 Subject: [PATCH 2/3] fixup! feat: add coder-sdk methods for multi-cluster --- coder-sdk/resourcepools.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/coder-sdk/resourcepools.go b/coder-sdk/resourcepools.go index 0972cc90..e94e2ec5 100644 --- a/coder-sdk/resourcepools.go +++ b/coder-sdk/resourcepools.go @@ -41,3 +41,23 @@ func (c *Client) ResourcePools(ctx context.Context) ([]ResourcePool, error) { } return pools, nil } + +// CreateResourcePoolReq defines the request parameters for creating a new resource pool entity. +type CreateResourcePoolReq struct { + Name string `json:"name"` + Local bool `json:"local"` + ClusterCA string `json:"cluster_ca"` + ClusterAddress string `json:"cluster_address"` + SAToken string `json:"sa_token"` + DefaultNamespace string `json:"default_namespace"` + StorageClass string `json:"storage_class"` + ClusterDomainSuffix string `json:"cluster_domain_suffix"` + DevurlHost string `json:"devurl_host"` + NamespaceWhitelist []string `json:"namespace_whitelist"` + OrgWhitelist []string `json:"org_whitelist"` +} + +// CreateResourcePool creates a new ResourcePool entity. +func (c *Client) CreateResourcePool(ctx context.Context, req CreateResourcePoolReq) error { + return c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools", req, nil) +} From 1d5e892ddf8314e38c01321eb49da7d968276f07 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Thu, 14 Jan 2021 10:12:56 -0600 Subject: [PATCH 3/3] fixup! feat: add coder-sdk methods for multi-cluster --- coder-sdk/env.go | 1 + 1 file changed, 1 insertion(+) diff --git a/coder-sdk/env.go b/coder-sdk/env.go index 7828f751..e985c238 100644 --- a/coder-sdk/env.go +++ b/coder-sdk/env.go @@ -34,6 +34,7 @@ type Environment struct { AutoOffThreshold Duration `json:"auto_off_threshold" table:"-"` SSHAvailable bool `json:"ssh_available" table:"-"` UseContainerVM bool `json:"use_container_vm" table:"CVM"` + ResourcePoolID string `json:"resource_pool_id" table:"-"` } // RebuildMessage defines the message shown when an Environment requires a rebuild for it can be accessed.