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

Commit cf6e030

Browse files
authored
feat: add coder-sdk methods for resource-pools (#215)
* feat: add coder-sdk methods for multi-cluster * fixup! feat: add coder-sdk methods for multi-cluster * fixup! feat: add coder-sdk methods for multi-cluster
1 parent e516b8c commit cf6e030

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

coder-sdk/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Environment struct {
3434
AutoOffThreshold Duration `json:"auto_off_threshold" table:"-"`
3535
SSHAvailable bool `json:"ssh_available" table:"-"`
3636
UseContainerVM bool `json:"use_container_vm" table:"CVM"`
37+
ResourcePoolID string `json:"resource_pool_id" table:"-"`
3738
}
3839

3940
// RebuildMessage defines the message shown when an Environment requires a rebuild for it can be accessed.

coder-sdk/resourcepools.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package coder
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
// ResourcePool defines an entity capable of deploying and acting as an ingress for Coder environments.
9+
type ResourcePool struct {
10+
ID string `json:"id"`
11+
Name string `json:"name"`
12+
Local bool `json:"local"`
13+
ClusterAddress string `json:"cluster_address"`
14+
DefaultNamespace string `json:"default_namespace"`
15+
StorageClass string `json:"storage_class"`
16+
ClusterDomainSuffix string `json:"cluster_domain_suffix"`
17+
DevurlHost string `json:"devurl_host"`
18+
NamespaceWhitelist []string `json:"namespace_whitelist"`
19+
OrgWhitelist []string `json:"org_whitelist"`
20+
}
21+
22+
// ResourcePoolByID fetches a resource pool entity by its unique ID.
23+
func (c *Client) ResourcePoolByID(ctx context.Context, id string) (*ResourcePool, error) {
24+
var rp ResourcePool
25+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools/"+id, nil, &rp); err != nil {
26+
return nil, err
27+
}
28+
return &rp, nil
29+
}
30+
31+
// DeleteResourcePoolByID deletes a resource pool entity from the Coder control plane.
32+
func (c *Client) DeleteResourcePoolByID(ctx context.Context, id string) error {
33+
return c.requestBody(ctx, http.MethodDelete, "/api/private/resource-pools/"+id, nil, nil)
34+
}
35+
36+
// ResourcePools fetches all resource pools known to the Coder control plane.
37+
func (c *Client) ResourcePools(ctx context.Context) ([]ResourcePool, error) {
38+
var pools []ResourcePool
39+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools", nil, &pools); err != nil {
40+
return nil, err
41+
}
42+
return pools, nil
43+
}
44+
45+
// CreateResourcePoolReq defines the request parameters for creating a new resource pool entity.
46+
type CreateResourcePoolReq struct {
47+
Name string `json:"name"`
48+
Local bool `json:"local"`
49+
ClusterCA string `json:"cluster_ca"`
50+
ClusterAddress string `json:"cluster_address"`
51+
SAToken string `json:"sa_token"`
52+
DefaultNamespace string `json:"default_namespace"`
53+
StorageClass string `json:"storage_class"`
54+
ClusterDomainSuffix string `json:"cluster_domain_suffix"`
55+
DevurlHost string `json:"devurl_host"`
56+
NamespaceWhitelist []string `json:"namespace_whitelist"`
57+
OrgWhitelist []string `json:"org_whitelist"`
58+
}
59+
60+
// CreateResourcePool creates a new ResourcePool entity.
61+
func (c *Client) CreateResourcePool(ctx context.Context, req CreateResourcePoolReq) error {
62+
return c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools", req, nil)
63+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy