- 
                Notifications
    
You must be signed in to change notification settings  - Fork 133
 
Add New Environment Variables for Load Balancer Configuration #1052
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -5,10 +5,12 @@ import ( | |||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| "k8s.io/klog/v2" | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| "github.com/hetznercloud/hcloud-go/v2/hcloud" | ||||||||||||||||||||||||||
| "github.com/hetznercloud/hcloud-go/v2/hcloud/exp/kit/envutil" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| 
        
          
        
         | 
    @@ -31,12 +33,20 @@ const ( | |||||||||||||||||||||||||
| hcloudNetworkDisableAttachedCheck = "HCLOUD_NETWORK_DISABLE_ATTACHED_CHECK" | ||||||||||||||||||||||||||
| hcloudNetworkRoutesEnabled = "HCLOUD_NETWORK_ROUTES_ENABLED" | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| hcloudLoadBalancersAlgorithmType = "HCLOUD_LOAD_BALANCERS_ALGORITHM_TYPE" | ||||||||||||||||||||||||||
| hcloudLoadBalancersDisableIPv6 = "HCLOUD_LOAD_BALANCERS_DISABLE_IPV6" | ||||||||||||||||||||||||||
| hcloudLoadBalancersDisablePrivateIngress = "HCLOUD_LOAD_BALANCERS_DISABLE_PRIVATE_INGRESS" | ||||||||||||||||||||||||||
| hcloudLoadBalancersDisablePublicNetwork = "HCLOUD_LOAD_BALANCERS_DISABLE_PUBLIC_NETWORK" | ||||||||||||||||||||||||||
| hcloudLoadBalancersEnabled = "HCLOUD_LOAD_BALANCERS_ENABLED" | ||||||||||||||||||||||||||
| hcloudLoadBalancersHealthCheckInterval = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_INTERVAL" | ||||||||||||||||||||||||||
| hcloudLoadBalancersHealthCheckRetries = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_RETRIES" | ||||||||||||||||||||||||||
| hcloudLoadBalancersHealthCheckTimeout = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_TIMEOUT" | ||||||||||||||||||||||||||
| hcloudLoadBalancersLocation = "HCLOUD_LOAD_BALANCERS_LOCATION" | ||||||||||||||||||||||||||
| hcloudLoadBalancersNetworkZone = "HCLOUD_LOAD_BALANCERS_NETWORK_ZONE" | ||||||||||||||||||||||||||
| hcloudLoadBalancersDisablePrivateIngress = "HCLOUD_LOAD_BALANCERS_DISABLE_PRIVATE_INGRESS" | ||||||||||||||||||||||||||
| hcloudLoadBalancersPrivateSubnetIPRange = "HCLOUD_LOAD_BALANCERS_PRIVATE_SUBNET_IP_RANGE" | ||||||||||||||||||||||||||
| hcloudLoadBalancersType = "HCLOUD_LOAD_BALANCERS_TYPE" | ||||||||||||||||||||||||||
| hcloudLoadBalancersUsePrivateIP = "HCLOUD_LOAD_BALANCERS_USE_PRIVATE_IP" | ||||||||||||||||||||||||||
| hcloudLoadBalancersDisableIPv6 = "HCLOUD_LOAD_BALANCERS_DISABLE_IPV6" | ||||||||||||||||||||||||||
| hcloudLoadBalancersUsesProxyProtocol = "HCLOUD_LOAD_BALANCERS_USES_PROXYPROTOCOL" | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| hcloudMetricsEnabled = "HCLOUD_METRICS_ENABLED" | ||||||||||||||||||||||||||
| hcloudMetricsAddress = ":8233" | ||||||||||||||||||||||||||
| 
          
            
          
           | 
    @@ -76,12 +86,21 @@ type InstanceConfiguration struct { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| type LoadBalancerConfiguration struct { | ||||||||||||||||||||||||||
| Enabled bool | ||||||||||||||||||||||||||
| Location string | ||||||||||||||||||||||||||
| NetworkZone string | ||||||||||||||||||||||||||
| PrivateIngressEnabled bool | ||||||||||||||||||||||||||
| PrivateIPEnabled bool | ||||||||||||||||||||||||||
| IPv6Enabled bool | ||||||||||||||||||||||||||
| AlgorithmType hcloud.LoadBalancerAlgorithmType | ||||||||||||||||||||||||||
| DisablePublicNetwork bool | ||||||||||||||||||||||||||
| Enabled bool | ||||||||||||||||||||||||||
| HealthCheckInterval time.Duration | ||||||||||||||||||||||||||
| HealthCheckRetries int | ||||||||||||||||||||||||||
| HealthCheckTimeout time.Duration | ||||||||||||||||||||||||||
| IPv6Enabled bool | ||||||||||||||||||||||||||
| Location string | ||||||||||||||||||||||||||
| NetworkZone string | ||||||||||||||||||||||||||
| PrivateIngressEnabled bool | ||||||||||||||||||||||||||
| PrivateIPEnabled bool | ||||||||||||||||||||||||||
| PrivateSubnetIPRange string | ||||||||||||||||||||||||||
| ProxyProtocolEnabled bool | ||||||||||||||||||||||||||
| ProxyProtocolEnabledSet bool | ||||||||||||||||||||||||||
| Type string | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| type NetworkConfiguration struct { | ||||||||||||||||||||||||||
| 
          
            
          
           | 
    @@ -183,12 +202,70 @@ func Read() (HCCMConfiguration, error) { | |||||||||||||||||||||||||
| errs = append(errs, err) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| cfg.LoadBalancer.ProxyProtocolEnabled, err = getEnvBool(hcloudLoadBalancersUsesProxyProtocol, false) | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| errs = append(errs, err) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| // Workaround to keep bug https://github.com/hetznercloud/hcloud-cloud-controller-manager/issues/876 | ||||||||||||||||||||||||||
| if _, exists := os.LookupEnv(hcloudLoadBalancersUsesProxyProtocol); exists { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.ProxyProtocolEnabledSet = true | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| disableIPv6, err := getEnvBool(hcloudLoadBalancersDisableIPv6, false) | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| errs = append(errs, err) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| cfg.LoadBalancer.IPv6Enabled = !disableIPv6 // Invert the logic, as the env var is prefixed with DISABLE_. | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if subnetRange, ok := os.LookupEnv(hcloudLoadBalancersPrivateSubnetIPRange); ok { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.PrivateSubnetIPRange = subnetRange | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +220
     to 
      +222
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use   | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if algorithmType, ok := os.LookupEnv(hcloudLoadBalancersAlgorithmType); ok { | ||||||||||||||||||||||||||
| alg, parseErr := parseLoadBalancerAlgorithmType(algorithmType) | ||||||||||||||||||||||||||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are mixing   | 
||||||||||||||||||||||||||
| if parseErr != nil { | ||||||||||||||||||||||||||
| errs = append(errs, fmt.Errorf("failed to parse %s: %w", hcloudLoadBalancersAlgorithmType, parseErr)) | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.AlgorithmType = alg | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if interval, ok := os.LookupEnv(hcloudLoadBalancersHealthCheckInterval); ok { | ||||||||||||||||||||||||||
| d, parseErr := time.ParseDuration(interval) | ||||||||||||||||||||||||||
| if parseErr != nil { | ||||||||||||||||||||||||||
| errs = append(errs, fmt.Errorf("failed to parse %s: %w", hcloudLoadBalancersHealthCheckInterval, parseErr)) | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.HealthCheckInterval = d | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +233
     to 
      +240
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
    
 We already have a util function for this. If   | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if timeout, ok := os.LookupEnv(hcloudLoadBalancersHealthCheckTimeout); ok { | ||||||||||||||||||||||||||
| d, parseErr := time.ParseDuration(timeout) | ||||||||||||||||||||||||||
| if parseErr != nil { | ||||||||||||||||||||||||||
| errs = append(errs, fmt.Errorf("failed to parse %s: %w", hcloudLoadBalancersHealthCheckTimeout, parseErr)) | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.HealthCheckTimeout = d | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +242
     to 
      +249
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
    
 Same here  | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if retries, ok := os.LookupEnv(hcloudLoadBalancersHealthCheckRetries); ok { | ||||||||||||||||||||||||||
| v, parseErr := strconv.Atoi(retries) | ||||||||||||||||||||||||||
| if parseErr != nil { | ||||||||||||||||||||||||||
| errs = append(errs, fmt.Errorf("failed to parse %s: %w", hcloudLoadBalancersHealthCheckRetries, parseErr)) | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.HealthCheckRetries = v | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +251
     to 
      +258
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
    
 Same here  | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| cfg.LoadBalancer.DisablePublicNetwork, err = getEnvBool(hcloudLoadBalancersDisablePublicNetwork, false) | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| errs = append(errs, err) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| if lbType, ok := os.LookupEnv(hcloudLoadBalancersType); ok { | ||||||||||||||||||||||||||
| cfg.LoadBalancer.Type = lbType | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +265
     to 
      +267
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
    
 
  | 
||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| cfg.Network.NameOrID = os.Getenv(hcloudNetwork) | ||||||||||||||||||||||||||
| disableAttachedCheck, err := getEnvBool(hcloudNetworkDisableAttachedCheck, false) | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| 
          
            
          
           | 
    @@ -280,3 +357,12 @@ func getEnvDuration(key string) (time.Duration, error) { | |||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| return b, nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 
     | 
||||||||||||||||||||||||||
| func parseLoadBalancerAlgorithmType(value string) (hcloud.LoadBalancerAlgorithmType, error) { | ||||||||||||||||||||||||||
| v := strings.ToLower(strings.TrimSpace(value)) | ||||||||||||||||||||||||||
| alg := hcloud.LoadBalancerAlgorithmType(v) | ||||||||||||||||||||||||||
| if alg == hcloud.LoadBalancerAlgorithmTypeRoundRobin || alg == hcloud.LoadBalancerAlgorithmTypeLeastConnections { | ||||||||||||||||||||||||||
| return alg, nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return "", fmt.Errorf("unsupported value %q", value) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.