Skip to content

Commit

Permalink
Parse custom zone mapping information
Browse files Browse the repository at this point in the history
from env `ZONE_TO_URL`
  • Loading branch information
remyrd committed Jan 24, 2024
1 parent fd62922 commit 4e46fa9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driver

import (
"context"
"encoding/json"
"fmt"
"net"
"net/url"
Expand Down Expand Up @@ -176,6 +177,15 @@ type nodeMetadata struct {
InstanceID v3.UUID
}

func customZones(customZonesStr string) (map[string]v3.URL, error) {
zonesMap := map[string]v3.URL{}
err := json.Unmarshal([]byte(customZonesStr), &zonesMap)
if err != nil {
return nil, err
}
return zonesMap, nil
}

func getExoscaleNodeMetadata() (*nodeMetadata, error) {
podName := os.Getenv("POD_NAME")
namespace := os.Getenv("POD_NAMESPACE")
Expand Down Expand Up @@ -213,7 +223,19 @@ func getExoscaleNodeMetadata() (*nodeMetadata, error) {
return nil, fmt.Errorf("node meta data Instance ID %s: %w", node.Spec.ProviderID, err)
}

zone, ok := v3.Zones[region]
zonesToURL := map[string]v3.URL{}

Check failure on line 226 in driver/driver.go

View workflow job for this annotation

GitHub Actions / build

ineffectual assignment to zonesToURL (ineffassign)

customZonesStr := os.Getenv("ZONE_TO_URL")
if customZonesStr != "" {
zonesToURL, err = customZones(customZonesStr)
if err != nil {
return nil, fmt.Errorf("couldn't read custom zone mapping %w", err)
}
} else {
zonesToURL = v3.Zones
}

zone, ok := zonesToURL[region]
if !ok {
return nil, fmt.Errorf("invalid region zone name: %s", region)
}
Expand Down

0 comments on commit 4e46fa9

Please sign in to comment.