|
1 | 1 | package cdk8s |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
| 5 | + "io" |
| 6 | + "net/http" |
| 7 | + |
4 | 8 | "github.com/wandb/operator/pkg/wandb/cdk8s/config" |
| 9 | + "github.com/wandb/operator/pkg/wandb/deployer" |
5 | 10 | ) |
6 | 11 |
|
7 | 12 | // Deployer returns the config suggested by deployer |
8 | 13 | func Deployer(license string) config.Modifier { |
9 | | - return &deployerChannel{} |
| 14 | + url := deployer.DeployerAPIUrl + "/api/channel/license" |
| 15 | + req, err := http.NewRequest("GET", url, nil) |
| 16 | + if err != nil { |
| 17 | + return nil |
| 18 | + } |
| 19 | + |
| 20 | + req.Header.Add(deployer.DeployerLicenseHeader, license) |
| 21 | + |
| 22 | + client := &http.Client{} |
| 23 | + resp, err := client.Do(req) |
| 24 | + if err != nil { |
| 25 | + return nil |
| 26 | + } |
| 27 | + |
| 28 | + defer resp.Body.Close() |
| 29 | + |
| 30 | + body, err := io.ReadAll(resp.Body) |
| 31 | + if err != nil { |
| 32 | + return nil |
| 33 | + } |
| 34 | + |
| 35 | + var responseStruct deployerResponse |
| 36 | + err = json.Unmarshal(body, &responseStruct) |
| 37 | + if err != nil { |
| 38 | + return nil |
| 39 | + } |
| 40 | + |
| 41 | + return &deployerChannel{ |
| 42 | + response: &responseStruct, |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +type state struct { |
| 47 | + Recommend *config.Config `json:"recommend,omitempty"` |
| 48 | + Override *config.Config `json:"override,omitempty"` |
10 | 49 | } |
11 | 50 |
|
12 | 51 | type deployerResponse struct { |
13 | | - recommend *config.Config |
14 | | - override *config.Config |
| 52 | + Id string `json:"id"` |
| 53 | + Name string `json:"name"` |
| 54 | + State state `json:"state"` |
15 | 55 | } |
16 | 56 |
|
17 | 57 | type deployerChannel struct { |
18 | | - response deployerResponse |
| 58 | + response *deployerResponse |
19 | 59 | } |
20 | 60 |
|
21 | 61 | func (c deployerChannel) Recommend(_ *config.Config) *config.Config { |
22 | | - return c.response.recommend |
| 62 | + return c.response.State.Recommend |
23 | 63 | } |
24 | 64 |
|
25 | 65 | func (c deployerChannel) Override(_ *config.Config) *config.Config { |
26 | | - return c.response.override |
| 66 | + return c.response.State.Override |
27 | 67 | } |
0 commit comments