Skip to content

Commit

Permalink
Fix api endpoint for preprod
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed Nov 13, 2024
1 parent c207c69 commit 1647332
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions exoscale/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func newRefreshableExoscaleClient(ctx context.Context, config *globalConfig) (*r
if err != nil {
return nil, err
}

if c.apiEndpoint != "" {
exo = exo.WithEndpoint(v3.Endpoint(c.apiEndpoint))
}

c.exo = exo
} else if config.APICredentialsFile != "" {
infof("reading (watching) Exoscale API credentials from file %q", config.APICredentialsFile)
Expand Down Expand Up @@ -155,6 +160,9 @@ func (c *refreshableExoscaleClient) refreshCredentialsFromFile(path string) {
}

c.Lock()
if c.apiEndpoint != "" {
client = client.WithEndpoint(v3.Endpoint(c.apiEndpoint))
}
c.exo = client
c.apiCredentials = apiCredentials
c.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion exoscale/exoscale_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func readExoscaleConfig(config io.Reader) (cloudConfig, error) {
if value, exists := os.LookupEnv("EXOSCALE_API_CREDENTIALS_FILE"); exists {
cfg.Global.APICredentialsFile = value
}
if value, exists := os.LookupEnv("EXOSCALE_API_ENPOINT"); exists {
if value, exists := os.LookupEnv("EXOSCALE_API_ENDPOINT"); exists {
cfg.Global.APIEndpoint = value
}

Expand Down
12 changes: 6 additions & 6 deletions exoscale/exoscale_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
testAPIKey = new(exoscaleCCMTestSuite).randomString(10)
testAPISecret = new(exoscaleCCMTestSuite).randomString(10)
testAPICredentialsFile = new(exoscaleCCMTestSuite).randomString(10)
testAPIEnvironment = "test"
testAPIEndpoint = "test"

// Config
testConfig_empty = cloudConfig{}
Expand Down Expand Up @@ -54,8 +54,8 @@ global:
zone: "%s"
apiKey: "%s"
apiSecret: "%s"
apiEnvironment: "%s"
`, testZone, testAPIKey, testAPISecret, testAPIEnvironment)
apiEndpoint: "%s"
`, testZone, testAPIKey, testAPISecret, testAPIEndpoint)
)

func (ts *exoscaleCCMTestSuite) Test_readExoscaleConfig_empty() {
Expand Down Expand Up @@ -91,12 +91,12 @@ func (ts *exoscaleCCMTestSuite) Test_readExoscaleConfig_env_typical() {
os.Setenv("EXOSCALE_ZONE", testZone)
os.Setenv("EXOSCALE_API_KEY", testAPIKey)
os.Setenv("EXOSCALE_API_SECRET", testAPISecret)
os.Setenv("EXOSCALE_API_ENVIRONMENT", testAPIEnvironment)
os.Setenv("EXOSCALE_API_ENDPOINT", testAPIEndpoint)
defer func() {
os.Unsetenv("EXOSCALE_ZONE")
os.Unsetenv("EXOSCALE_API_KEY")
os.Unsetenv("EXOSCALE_API_SECRET")
os.Unsetenv("EXOSCALE_API_ENVIRONMENT")
os.Unsetenv("EXOSCALE_API_ENDPOINT")
}()

cfg, err := readExoscaleConfig(strings.NewReader(testConfigYAML_empty))
Expand Down Expand Up @@ -128,7 +128,7 @@ func (ts *exoscaleCCMTestSuite) Test_readExoscaleConfig_typical() {
os.Unsetenv("EXOSCALE_ZONE")
os.Unsetenv("EXOSCALE_API_KEY")
os.Unsetenv("EXOSCALE_API_SECRET")
os.Unsetenv("EXOSCALE_API_ENVIRONMENT")
os.Unsetenv("EXOSCALE_API_ENDPOINT")

cfg, err := readExoscaleConfig(strings.NewReader(testConfigYAML_typical))
ts.Require().NoError(err)
Expand Down

0 comments on commit 1647332

Please sign in to comment.