Merge pull request #7817 from karsten42/feature/hetzner-config-from-configmap

added possibility to retrieve hcloud cluster config from file
This commit is contained in:
Kubernetes Prow Robot 2025-05-02 03:55:54 -07:00 committed by GitHub
commit 41630404f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 20 deletions

View File

@ -41,6 +41,12 @@ The cluster autoscaler for Hetzner Cloud scales worker nodes.
}
```
`HCLOUD_CLUSTER_CONFIG_FILE` Can be used as alternative to `HCLOUD_CLUSTER_CONFIG`. This is the path to a file
containing the JSON structure described above. The file will be read and the contents will be used as the configuration.
Can be useful when you have many different node pools and run into issues of the env var becoming too long.
**NOTE**: In contrast to `HCLOUD_CLUSTER_CONFIG`, this file is not base64 encoded.
`HCLOUD_NETWORK` Default empty , The id or name of the network that is used in the cluster , @see https://docs.hetzner.cloud/#networks

View File

@ -110,32 +110,38 @@ 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{}
var clusterConfigJsonData []byte
var readErr error
if clusterConfigBase64 != "" {
clusterConfigJsonData, readErr = base64.StdEncoding.DecodeString(clusterConfigBase64)
if readErr != nil {
return nil, fmt.Errorf("failed to parse cluster config error: %s", readErr)
}
} else if clusterConfigFile != "" {
clusterConfigJsonData, readErr = os.ReadFile(clusterConfigFile)
if readErr != nil {
return nil, fmt.Errorf("failed to read cluster config file: %s", readErr)
}
}
if clusterConfigJsonData != nil {
unmarshalErr := json.Unmarshal(clusterConfigJsonData, &clusterConfig)
if unmarshalErr != nil {
return nil, fmt.Errorf("failed to unmarshal cluster config JSON: %s", unmarshalErr)
}
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)
}
err = json.Unmarshal(clusterConfigEnv, &clusterConfig)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal cluster config JSON: %s", err)
}
}
if !clusterConfig.IsUsingNewFormat {
cloudInit, err := base64.StdEncoding.DecodeString(cloudInitBase64)
if err != nil {
return nil, fmt.Errorf("failed to parse cloud init error: %s", err)
} else {
cloudInit, decErr := base64.StdEncoding.DecodeString(cloudInitBase64)
if decErr != nil {
return nil, fmt.Errorf("failed to parse cloud init error: %s", decErr)
}
imageName := os.Getenv("HCLOUD_IMAGE")