Skip to content

Commit 480b380

Browse files
committed
fix: Use deployer release channels
1 parent 21fae12 commit 480b380

2 files changed

Lines changed: 48 additions & 7 deletions

File tree

pkg/wandb/cdk8s/deployer.go

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,67 @@
11
package cdk8s
22

33
import (
4+
"encoding/json"
5+
"io"
6+
"net/http"
7+
48
"github.com/wandb/operator/pkg/wandb/cdk8s/config"
9+
"github.com/wandb/operator/pkg/wandb/deployer"
510
)
611

712
// Deployer returns the config suggested by deployer
813
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"`
1049
}
1150

1251
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"`
1555
}
1656

1757
type deployerChannel struct {
18-
response deployerResponse
58+
response *deployerResponse
1959
}
2060

2161
func (c deployerChannel) Recommend(_ *config.Config) *config.Config {
22-
return c.response.recommend
62+
return c.response.State.Recommend
2363
}
2464

2565
func (c deployerChannel) Override(_ *config.Config) *config.Config {
26-
return c.response.override
66+
return c.response.State.Override
2767
}

pkg/wandb/deployer/deployer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ package deployer
33
import "github.com/wandb/operator/pkg/utils"
44

55
var (
6-
DeployerAPIUrl = utils.Getenv("DEPLOYER_API_URL", "https://localhost:3000/api")
6+
DeployerAPIUrl = utils.Getenv("DEPLOYER_API_URL", "https://localhost:3000/api")
7+
DeployerLicenseHeader = utils.Getenv("DEPLOYER_LICENSE_HEADER", "x-wandb-license")
78
)

0 commit comments

Comments
 (0)