Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse custom zone mapping information #3

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
var zonesToURL map[string]v3.URL

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]
pierre-emmanuelJ marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return nil, fmt.Errorf("invalid region zone name: %s", region)
}
Expand Down
Loading