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

added possibility to retrieve hcloud cluster config from file #7817

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 17 additions & 9 deletions cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,15 @@ func newManager() (*hetznerManager, error) {
var err error

clusterConfigBase64 := os.Getenv("HCLOUD_CLUSTER_CONFIG")
clusterConfigFile := os.Getenv("HCLOUD_CLUSTER_CONFIG_FILE")
cloudInitBase64 := os.Getenv("HCLOUD_CLOUD_INIT")

if clusterConfigBase64 == "" && cloudInitBase64 == "" {
return nil, errors.New("`HCLOUD_CLUSTER_CONFIG` or `HCLOUD_CLOUD_INIT` is not specified")
if clusterConfigBase64 == "" && cloudInitBase64 == "" && clusterConfigFile == "" {
return nil, errors.New("neither `HCLOUD_CLUSTER_CONFIG`, `HCLOUD_CLOUD_INIT` nor `HCLOUD_CLUSTER_CONFIG_FILE` is specified")
}
var clusterConfig *ClusterConfig = &ClusterConfig{}
var clusterConfig = &ClusterConfig{}

if clusterConfigBase64 != "" {
clusterConfig.IsUsingNewFormat = true
}

if clusterConfig.IsUsingNewFormat {
clusterConfigEnv, err := base64.StdEncoding.DecodeString(clusterConfigBase64)
if err != nil {
return nil, fmt.Errorf("failed to parse cluster config error: %s", err)
Expand All @@ -130,9 +127,20 @@ func newManager() (*hetznerManager, error) {
if err != nil {
return nil, fmt.Errorf("failed to unmarshal cluster config JSON: %s", err)
}
}
clusterConfig.IsUsingNewFormat = true

if !clusterConfig.IsUsingNewFormat {
} else if clusterConfigFile != "" {
clusterConfigData, err := os.ReadFile(clusterConfigFile)
if err != nil {
return nil, fmt.Errorf("failed to read cluster config file: %s", err)
}
err = json.Unmarshal(clusterConfigData, &clusterConfig)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal cluster config JSON: %s", err)
}
clusterConfig.IsUsingNewFormat = true

} else {
cloudInit, err := base64.StdEncoding.DecodeString(cloudInitBase64)
if err != nil {
return nil, fmt.Errorf("failed to parse cloud init error: %s", err)
Expand Down
Loading