Skip to content

Commit

Permalink
Finalize support for zones in Hetzner cloud regions
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheEvilOne committed Jun 17, 2021
1 parent dcc3701 commit 48e5edb
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 131 deletions.
39 changes: 11 additions & 28 deletions charts/internal/machineclass/values.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
machineClasses:
- name: class-1
region: myregion
datacenter: dc1
#hostSystem: esxi1
#resourcePool: pool1
computeCluster: cluster1
network: network1
#switchUuid: "11 22-33 44"
folder: gardener
datastore: datastore1
#datastoreCluster: ds-cluster
templateVM: "gardener/templates/coreos-2191.5.0"
guestId: coreos64Guest
numCpus: 2
memory: 4096
#memoryReservationLockedToMax: true
#extraConfig:
# sched.swap.vmxSwapEnabled: "false"
systemDisk:
size: 20
description: An optional description for machines created by that class.
machineType: t1.small
cluster: shoot--foobar--hcloud
zone: hel1-dc2
machineType: cx11
imageName: ubuntu-20.04
sshFingerprint: "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
networkName: test-namespace-workers
floatingPoolName: MY-FLOATING-POOL
sshKeys:
- 12345-abcd567-aaf2
secret:
cloudConfig: abc
vsphereHost: "a_host"
vsphereUsername: "a_user"
vspherePassword: "a_password"
vsphereInsecureSSL: "true"
hcloudToken: base64token
userData: IyEvYmluL2Jhc2gKCmVjaG8gImhlbGxvIHdvcmxkIgo=
tags:
- kubernetes.io/cluster/foo
- kubernetes.io/role/node
mcm.gardener.cloud/cluster: shoot--foobar--hcloud
mcm.gardener.cloud/role: node
7 changes: 6 additions & 1 deletion example/30-controlplane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ spec:
apiVersion: core.gardener.cloud/v1alpha1
kind: CloudProfile
spec:
regions:
- name: hel1
zones:
- name: hel1-dc2
providerConfig:
apiVersion: hcloud.provider.extensions.gardener.cloud/v1alpha1
kind: CloudProfileConfig
Expand Down Expand Up @@ -60,14 +64,15 @@ metadata:
namespace: shoot--foobar--hcloud
spec:
type: hcloud
region: hel1-dc2
region: hel1
secretRef:
name: cloudprovider
namespace: shoot--foobar--hcloud
providerConfig:
apiVersion: hcloud.provider.extensions.gardener.cloud/v1alpha1
kind: ControlPlaneConfig
loadBalancerProvider: hcloud
zone: hel1-dc2
cloudControllerManager:
featureGates:
CustomResourceValidation: true
Expand Down
10 changes: 4 additions & 6 deletions example/30-infrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ metadata:
type: Opaque
data:
hcloudToken: base64token

---
apiVersion: extensions.gardener.cloud/v1alpha1
kind: Cluster
Expand All @@ -25,21 +24,20 @@ spec:
kind: CloudProfile
spec:
regions:
- name: hel1-dc2
- name: hel1
machineTypes:
- name: cx11
providerConfig:
apiVersion: hcloud.provider.extensions.gardener.cloud/v1alpha1
kind: CloudProfileConfig
regions:
- name: hel1-dc2
- name: hel1
machineImages:
- name: ubuntu
versions:
- version: "20.04"
machineTypes:
- name: cx11

seed:
apiVersion: core.gardener.cloud/v1alpha1
kind: Seed
Expand All @@ -49,7 +47,7 @@ spec:
spec:
kubernetes:
version: 1.13.4
region: hel1-dc2
region: hel1
cloud:
hcloud:
test: foo
Expand All @@ -65,7 +63,7 @@ metadata:
namespace: shoot--foobar--hcloud
spec:
type: hcloud
region: hel1-dc2
region: hel1
secretRef:
name: cloudprovider
namespace: shoot--foobar--hcloud
Expand Down
10 changes: 6 additions & 4 deletions example/30-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ spec:
kind: CloudProfile
spec:
regions:
- name: hel1-dc2
- name: hel1
machineTypes:
- name: cx11
providerConfig:
apiVersion: hcloud.provider.extensions.gardener.cloud/v1alpha1
kind: CloudProfileConfig
regions:
- name: hel1-dc2
- name: hel1
machineImages:
- name: ubuntu
versions:
Expand All @@ -43,7 +43,7 @@ spec:
spec:
kubernetes:
version: 1.13.4
region: hel1-dc2
region: hel1
cloud:
hcloud:
test: foo
Expand All @@ -60,7 +60,7 @@ metadata:
gardener.cloud/operation: reconcile
spec:
type: hcloud
region: hel1-dc2
region: hel1
infrastructureProviderStatus:
apiVersion: hcloud.provider.extensions.gardener.cloud/v1alpha1
kind: InfrastructureStatus
Expand All @@ -75,6 +75,8 @@ spec:
maximum: 1
maxSurge: 1
maxUnavailable: 0
zones:
- hel1-dc2
userData: IyEvYmluL2Jhc2gKCmVjaG8gImhlbGxvIHdvcmxkIgo=
sshPublicKey: ZGF0YQo=
secretRef:
Expand Down
13 changes: 1 addition & 12 deletions pkg/controller/controlplane/valuesprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,9 @@ func (vp *valuesProvider) getControlPlaneChartValues(
checksums map[string]string,
scaledDown bool,
) (map[string]interface{}, error) {
cloudProfileConfig, err := transcoder.DecodeCloudProfileConfigFromControllerCluster(cluster)
if err != nil {
return nil, err
}

regionSpec := apis.FindRegionSpecForGardenerRegion(cluster.Shoot.Spec.Region, cloudProfileConfig)
if regionSpec == nil {
return nil, fmt.Errorf("Region %q not found in cloud profile config", cluster.Shoot.Spec.Region)
}

clusterID, csiClusterID := vp.calcClusterIDs(cp)
region := apis.GetRegionFromZone(regionSpec.Name)
region := apis.GetRegionFromZone(cpConfig.Zone)

// csiResizerEnabled := cloudProfileConfig.CSIResizerDisabled == nil || !*cloudProfileConfig.CSIResizerDisabled
values := map[string]interface{}{
"hcloud-cloud-controller-manager": map[string]interface{}{
"replicas": extensionscontroller.GetControlPlaneReplicas(cluster, scaledDown, 1),
Expand Down
8 changes: 0 additions & 8 deletions pkg/controller/infrastructure/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package infrastructure

import (
"context"
"fmt"

"github.com/23technologies/gardener-extension-provider-hcloud/pkg/hcloud"
"github.com/23technologies/gardener-extension-provider-hcloud/pkg/hcloud/apis"
Expand All @@ -45,7 +44,6 @@ type actuator struct {
type actuatorConfig struct {
cloudProfileConfig *apis.CloudProfileConfig
infraConfig *apis.InfrastructureConfig
region *apis.RegionSpec
token string
}

Expand All @@ -68,11 +66,6 @@ func (a *actuator) getActuatorConfig(ctx context.Context, infra *extensionsv1alp
return nil, err
}

regionSpec := apis.FindRegionSpecForGardenerRegion(infra.Spec.Region, cloudProfileConfig)
if regionSpec == nil {
return nil, fmt.Errorf("Region %q not found in cloud profile", infra.Spec.Region)
}

secret, err := controller.GetSecretByReference(ctx, a.Client(), &infra.Spec.SecretRef)
if err != nil {
return nil, err
Expand All @@ -88,7 +81,6 @@ func (a *actuator) getActuatorConfig(ctx context.Context, infra *extensionsv1alp
config := &actuatorConfig{
cloudProfileConfig: cloudProfileConfig,
infraConfig: infraConfig,
region: regionSpec,
token: token,
}

Expand Down
94 changes: 48 additions & 46 deletions pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,58 +135,60 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
return errors.Wrap(err, "extracting machine values failed")
}

machineClassSpec := map[string]interface{}{
"cluster": w.worker.Namespace,
"zone": string(w.worker.Spec.Region),
"imageName": imageName,
"sshFingerprint": sshFingerprint,
"machineType": string(pool.MachineType),
"networkName": fmt.Sprintf("%s-workers", w.worker.Namespace),
"tags": map[string]string{
"mcm.gardener.cloud/cluster": w.worker.Namespace,
"mcm.gardener.cloud/role": "node",
},
"secret": map[string]interface{}{
for _, zone := range pool.Zones {
secretMap := map[string]interface{}{
"userData": string(pool.UserData),
},
}
}

if "" != infraStatus.FloatingPoolName {
machineClassSpec["floatingPoolName"] = infraStatus.FloatingPoolName
}
for key, value := range machineClassSecretData {
secretMap[key] = string(value)
}

if values.MachineTypeOptions != nil {
if len(values.MachineTypeOptions.ExtraConfig) > 0 {
machineClassSpec["extraConfig"] = values.MachineTypeOptions.ExtraConfig
machineClassSpec := map[string]interface{}{
"cluster": w.worker.Namespace,
"zone": zone,
"imageName": string(imageName),
"sshFingerprint": sshFingerprint,
"machineType": string(pool.MachineType),
"networkName": fmt.Sprintf("%s-workers", w.worker.Namespace),
"tags": map[string]string{
"mcm.gardener.cloud/cluster": w.worker.Namespace,
"mcm.gardener.cloud/role": "node",
},
"secret": secretMap,
}
}

var (
deploymentName = fmt.Sprintf("%s-%s", w.worker.Namespace, pool.Name)
className = fmt.Sprintf("%s-%s", deploymentName, workerPoolHash)
)

machineDeployments = append(machineDeployments, worker.MachineDeployment{
Name: deploymentName,
ClassName: className,
SecretName: className,
Minimum: pool.Minimum,
Maximum: pool.Maximum,
MaxSurge: pool.MaxSurge,
MaxUnavailable: pool.MaxUnavailable,
Labels: pool.Labels,
Annotations: pool.Annotations,
Taints: pool.Taints,
MachineConfiguration: genericworkeractuator.ReadMachineConfiguration(pool),
})

machineClassSpec["name"] = className
secretMap := machineClassSpec["secret"].(map[string]interface{})
for k, v := range machineClassSecretData {
secretMap[k] = string(v)
}
if "" != infraStatus.FloatingPoolName {
machineClassSpec["floatingPoolName"] = infraStatus.FloatingPoolName
}

machineClasses = append(machineClasses, machineClassSpec)
if values.MachineTypeOptions != nil {
if len(values.MachineTypeOptions.ExtraConfig) > 0 {
machineClassSpec["extraConfig"] = values.MachineTypeOptions.ExtraConfig
}
}

deploymentName := fmt.Sprintf("%s-%s-%s", w.worker.Namespace, pool.Name, zone)
className := fmt.Sprintf("%s-%s", deploymentName, workerPoolHash)

machineDeployments = append(machineDeployments, worker.MachineDeployment{
Name: deploymentName,
ClassName: className,
SecretName: className,
Minimum: pool.Minimum,
Maximum: pool.Maximum,
MaxSurge: pool.MaxSurge,
MaxUnavailable: pool.MaxUnavailable,
Labels: pool.Labels,
Annotations: pool.Annotations,
Taints: pool.Taints,
MachineConfiguration: genericworkeractuator.ReadMachineConfiguration(pool),
})

machineClassSpec["name"] = className

machineClasses = append(machineClasses, machineClassSpec)
}

}
w.machineDeployments = machineDeployments
Expand Down
6 changes: 3 additions & 3 deletions pkg/hcloud/apis/mock/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const (
"apiVersion": "core.gardener.cloud/v1alpha1",
"kind": "CloudProfile",
"spec": {
"regions": [{"name": "hel1-dc2"}],
"regions": [{"name": "hel1", "zones": [{"name": "hel1-dc2"}]}],
"machineTypes": [{"name": "cx11"}],
"providerConfig": {
"apiVersion": "hcloud.provider.extensions.gardener.cloud/v1alpha1",
"kind": "CloudProfileConfig",
"regions": [{"name": "hel1-dc2"}],
"regions": [{"name": "hel1"}],
"machineImages": [{"name": "ubuntu", "versions": [{"version": "20.04"}]}],
"machineTypes": [{"name": "cx11"}]
}
Expand All @@ -51,7 +51,7 @@ const (
"spec": {
"kubernetes": {"version": "1.13.4"},
"cloud": {"hcloud": {"test": "foo"}},
"region": "hel1-dc2",
"region": "hel1",
"status": {
"lastOperation": {"state": "Succeeded"}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/hcloud/apis/mock/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

const (
TestInfrastructureName = "abc"
TestInfrastructureRegion = "hel1-dc2"
TestInfrastructureRegion = "hel1"
TestInfrastructureZone = "hel1-dc2"
TestInfrastructureSecretName = "cloudprovider"
TestInfrastructureSpecFloatingPoolName = "MY-FLOATING-POOL"
TestInfrastructureSpecProviderConfig = `{
Expand Down
3 changes: 3 additions & 0 deletions pkg/hcloud/apis/types_controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
type ControlPlaneConfig struct {
metav1.TypeMeta

// Zone is the HCloud zone.
Zone string `json:"zone"`

// CloudControllerManager contains configuration settings for the cloud-controller-manager.
CloudControllerManager *CloudControllerManagerConfig
// LoadBalancerClasses lists the load balancer classes to be used.
Expand Down
10 changes: 0 additions & 10 deletions pkg/hcloud/apis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,3 @@ func GetRegionFromZone(zone string) string {
zoneData := strings.SplitN(zone, "-", 2)
return zoneData[0]
}

// FindRegionSpecForGardenerRegion finds a RegionSpec by name in the cloud profile config
func FindRegionSpecForGardenerRegion(name string, cloudProfileConfig *CloudProfileConfig) *RegionSpec {
for _, r := range cloudProfileConfig.Regions {
if r.Name == name {
return &r
}
}
return nil
}
Loading

0 comments on commit 48e5edb

Please sign in to comment.