Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #80 from rfranzke/feature/improve-controlplane-act…
Browse files Browse the repository at this point in the history
…uators

Simplify AWS and GCP controlplane actuators
  • Loading branch information
rfranzke authored May 9, 2019

Verified

This commit was signed with the committer’s verified signature.
rsandell Robert Sandell
2 parents c556a7a + 969ee4a commit b1c110d
Showing 25 changed files with 270 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ spec:
- --cluster-cidr={{ .Values.podNetwork }}
- --cluster-name={{ .Values.clusterName }}
- --concurrent-service-syncs=10
- --configure-cloud-routes={{ .Values.configureRoutes }}
- --configure-cloud-routes=false
{{- include "cloud-controller-manager.featureGates" . | trimSuffix "," | indent 8 }}
- --kubeconfig=/var/lib/cloud-controller-manager/kubeconfig
- --leader-elect=true
@@ -81,7 +81,16 @@ spec:
- {{ $param }}
{{- end }}
env:
{{ toYaml .Values.environment | indent 10 }}
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: cloudprovider
key: accessKeyID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: cloudprovider
key: secretAccessKey
livenessProbe:
httpGet:
path: /healthz
@@ -109,8 +118,6 @@ spec:
mountPath: /var/lib/cloud-controller-manager-server
- name: cloud-provider-config
mountPath: /etc/kubernetes/cloudprovider
- name: cloudprovider
mountPath: /srv/cloudprovider
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
@@ -125,6 +132,3 @@ spec:
- name: cloud-provider-config
configMap:
name: cloud-provider-config
- name: cloudprovider
secret:
secretName: cloudprovider
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
replicas: 1
kubernetesVersion: 1.7.5
configureRoutes: true
clusterName: shoot-foo-bar
kubernetesVersion: 1.7.5
podNetwork: 192.168.0.0/16
environment: []
additionalParameters: []
podAnnotations: {}
featureGates: {}
# CustomResourceValidation: true
@@ -16,5 +13,5 @@ resources:
cpu: 100m
memory: 64Mi
limits:
cpu: 250m
memory: 300Mi
cpu: 500m
memory: 512Mi
Original file line number Diff line number Diff line change
@@ -5,4 +5,10 @@ metadata:
namespace: {{ .Release.Namespace }}
data:
cloudprovider.conf: |
{{ .Values.cloudProviderConfig | indent 4 }}
[Global]
VPC="{{ .Values.vpcID }}"
SubnetID="{{ .Values.subnetID }}"
DisableSecurityGroupIngress=true
KubernetesClusterTag="{{ .Values.clusterName }}"
KubernetesClusterID="{{ .Values.clusterName }}"
Zone="{{ .Values.zone }}"
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
cloudProviderConfig: ""
vpcID: vpc-1234
subnetID: subnet-1234
clusterName: foo-bar
zone: eu-west-1a
7 changes: 5 additions & 2 deletions controllers/provider-aws/pkg/aws/types.go
Original file line number Diff line number Diff line change
@@ -19,14 +19,17 @@ import "path/filepath"
const (
// TerraformerImageName is the name of the Terraformer image.
TerraformerImageName = "terraformer"
// HyperkubeImageName is the name of the hyperkube image.
HyperkubeImageName = "hyperkube"

// AccessKeyID is a constant for the key in a cloud provider secret and backup secret that holds the AWS access key id.
AccessKeyID = "accessKeyID"
// SecretAccessKey is a constant for the key in a cloud provider secret and backup secret that holds the AWS secret access key.
SecretAccessKey = "secretAccessKey"
// Region is a constant for the key in a backup secret that holds the AWS region.
Region = "region"
// TerrformerPurposeInfra is a constant for the complete Terraform setup with purpose 'infrastructure'.
TerrformerPurposeInfra = "infra"
// TerraformerPurposeInfra is a constant for the complete Terraform setup with purpose 'infrastructure'.
TerraformerPurposeInfra = "infra"
// VPCIDKey is the vpc_id tf state key
VPCIDKey = "vpc_id"
// SubnetPublicPrefix is the prefix for the subnets
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package controlplane_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestControlplane(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "AWS Controlplane Suite")
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ package controlplane

import (
"context"
"fmt"
"path/filepath"

apisaws "github.com/gardener/gardener-extensions/controllers/provider-aws/pkg/apis/aws"
@@ -30,8 +29,11 @@ import (
"github.com/gardener/gardener/pkg/operation/common"
"github.com/gardener/gardener/pkg/utils/chart"
"github.com/gardener/gardener/pkg/utils/secrets"

"github.com/go-logr/logr"

"github.com/pkg/errors"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -95,7 +97,7 @@ var configChart = &chart.Chart{
var ccmChart = &chart.Chart{
Name: "cloud-controller-manager",
Path: filepath.Join(aws.InternalChartsPath, "cloud-controller-manager"),
Images: []string{common.HyperkubeImageName},
Images: []string{aws.HyperkubeImageName},
Objects: []*chart.Object{
{Type: &corev1.Service{}, Name: "cloud-controller-manager"},
{Type: &appsv1.Deployment{}, Name: "cloud-controller-manager"},
@@ -173,7 +175,10 @@ func getConfigChartValues(

// Collect config chart values
return map[string]interface{}{
"cloudProviderConfig": getCloudProviderConfig(infraStatus.VPC.ID, subnetID, zone, cp.Namespace),
"vpcID": infraStatus.VPC.ID,
"subnetID": subnetID,
"clusterName": cp.Namespace,
"zone": zone,
}, nil
}

@@ -185,11 +190,10 @@ func getCCMChartValues(
checksums map[string]string,
) (map[string]interface{}, error) {
values := map[string]interface{}{
"cloudProvider": "aws",
"replicas": extensionscontroller.GetReplicas(cluster.Shoot, 1),
"clusterName": cp.Namespace,
"kubernetesVersion": cluster.Shoot.Spec.Kubernetes.Version,
"podNetwork": extensionscontroller.GetPodNetwork(cluster.Shoot),
"replicas": extensionscontroller.GetReplicas(cluster.Shoot, 1),
"podAnnotations": map[string]interface{}{
"checksum/secret-cloud-controller-manager": checksums[cloudControllerManagerDeploymentName],
"checksum/secret-cloud-controller-manager-server": checksums[cloudControllerManagerServerName],
@@ -198,42 +202,18 @@ func getCCMChartValues(
"checksum/secret-cloudprovider": checksums[common.CloudProviderSecretName],
"checksum/configmap-cloud-provider-config": checksums[aws.CloudProviderConfigName],
},
"configureRoutes": false,
"environment": []map[string]interface{}{
{
"name": "AWS_ACCESS_KEY_ID",
"valueFrom": map[string]interface{}{
"secretKeyRef": map[string]interface{}{
"key": aws.AccessKeyID,
"name": common.CloudProviderSecretName,
},
},
},
{
"name": "AWS_SECRET_ACCESS_KEY",
"valueFrom": map[string]interface{}{
"secretKeyRef": map[string]interface{}{
"key": aws.SecretAccessKey,
"name": common.CloudProviderSecretName,
},
},
},
},
"resources": map[string]interface{}{
"limits": map[string]interface{}{
"cpu": "500m",
"memory": "512Mi",
},
},
}

if cpConfig.CloudControllerManager != nil {
values["featureGates"] = cpConfig.CloudControllerManager.FeatureGates
}

return values, nil
}

// getSubnetIDAndZone determines the subnet ID and zone from the given infrastructure status by looking for the first
// subnet with purpose "public".
// TODO: Move to pkg/apis/aws/v1alpha1/helper once https://github.com/gardener/gardener-extensions/pull/71 is merged.
func getSubnetIDAndZone(infraStatus *apisaws.InfrastructureStatus) (string, string, error) {
for _, subnet := range infraStatus.VPC.Subnets {
if subnet.Purpose == apisaws.PurposePublic {
@@ -242,17 +222,3 @@ func getSubnetIDAndZone(infraStatus *apisaws.InfrastructureStatus) (string, stri
}
return "", "", errors.Errorf("subnet with purpose 'public' not found")
}

// getCloudProviderConfig builds and returns a AWS config from the given parameters.
func getCloudProviderConfig(vpcID, subnetID, zone, clusterID string) string {
return fmt.Sprintf(
`[Global]
VPC=%q
SubnetID=%q
DisableSecurityGroupIngress=true
KubernetesClusterTag=%q
KubernetesClusterID=%q
Zone=%q
`,
vpcID, subnetID, clusterID, clusterID, zone)
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ package controlplane
import (
"context"
"encoding/json"
"testing"

apisaws "github.com/gardener/gardener-extensions/controllers/provider-aws/pkg/apis/aws"
"github.com/gardener/gardener-extensions/controllers/provider-aws/pkg/aws"
@@ -27,11 +26,15 @@ import (
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
gardenv1beta1 "github.com/gardener/gardener/pkg/apis/garden/v1beta1"
"github.com/gardener/gardener/pkg/operation/common"

"github.com/golang/mock/gomock"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
@@ -40,11 +43,6 @@ const (
namespace = "test"
)

func TestController(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "AWS Controlplane Suite")
}

var _ = Describe("ValuesProvider", func() {
var (
ctrl *gomock.Controller
@@ -115,55 +113,23 @@ var _ = Describe("ValuesProvider", func() {
}

configChartValues = map[string]interface{}{
"cloudProviderConfig": `[Global]
VPC="vpc-1234"
SubnetID="subnet-acbd1234"
DisableSecurityGroupIngress=true
KubernetesClusterTag="` + namespace + `"
KubernetesClusterID="` + namespace + `"
Zone="eu-west-1a"
`,
"vpcID": "vpc-1234",
"subnetID": "subnet-acbd1234",
"clusterName": namespace,
"zone": "eu-west-1a",
}

ccmChartValues = map[string]interface{}{
"cloudProvider": "aws",
"replicas": 1,
"clusterName": namespace,
"kubernetesVersion": "1.13.4",
"podNetwork": cidr,
"replicas": 1,
"podAnnotations": map[string]interface{}{
"checksum/secret-cloud-controller-manager": "3d791b164a808638da9a8df03924be2a41e34cd664e42231c00fe369e3588272",
"checksum/secret-cloud-controller-manager-server": "6dff2a2e6f14444b66d8e4a351c049f7e89ee24ba3eaab95dbec40ba6bdebb52",
"checksum/secret-cloudprovider": "8bafb35ff1ac60275d62e1cbd495aceb511fb354f74a20f7d06ecb48b3a68432",
"checksum/configmap-cloud-provider-config": "08a7bc7fe8f59b055f173145e211760a83f02cf89635cef26ebb351378635606",
},
"configureRoutes": false,
"environment": []map[string]interface{}{
{
"name": "AWS_ACCESS_KEY_ID",
"valueFrom": map[string]interface{}{
"secretKeyRef": map[string]interface{}{
"key": aws.AccessKeyID,
"name": common.CloudProviderSecretName,
},
},
},
{
"name": "AWS_SECRET_ACCESS_KEY",
"valueFrom": map[string]interface{}{
"secretKeyRef": map[string]interface{}{
"key": aws.SecretAccessKey,
"name": common.CloudProviderSecretName,
},
},
},
},
"resources": map[string]interface{}{
"limits": map[string]interface{}{
"cpu": "500m",
"memory": "512Mi",
},
},
"featureGates": map[string]bool{
"CustomResourceValidation": true,
},
@@ -175,6 +141,7 @@ Zone="eu-west-1a"
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
})

AfterEach(func() {
ctrl.Finish()
})
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ import (
)

func (a *actuator) delete(ctx context.Context, infrastructure *extensionsv1alpha1.Infrastructure, cluster *extensionscontroller.Cluster) error {
tf, err := a.newTerraformer(aws.TerrformerPurposeInfra, infrastructure.Namespace, infrastructure.Name)
tf, err := a.newTerraformer(aws.TerraformerPurposeInfra, infrastructure.Namespace, infrastructure.Name)
if err != nil {
return fmt.Errorf("could not create the Terraformer: %+v", err)
}
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ func (a *actuator) reconcile(ctx context.Context, infrastructure *extensionsv1al
return fmt.Errorf("could not render Terraform chart: %+v", err)
}

tf, err := a.newTerraformer(aws.TerrformerPurposeInfra, infrastructure.Namespace, infrastructure.Name)
tf, err := a.newTerraformer(aws.TerraformerPurposeInfra, infrastructure.Namespace, infrastructure.Name)
if err != nil {
return fmt.Errorf("could not create terraformer object: %+v", err)
}
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ var (
DefaultAddOptions = AddOptions{}
)

// AddOptions are options to apply when adding the gcp infrastructure controller to the manager.
// AddOptions are options to apply when adding the AWS infrastructure controller to the manager.
type AddOptions struct {
// Controller are the controller.Options.
Controller controller.Options
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ var (
DefaultAddOptions = AddOptions{}
)

// AddOptions are options to apply when adding the azure infrastructure controller to the manager.
// AddOptions are options to apply when adding the Azure infrastructure controller to the manager.
type AddOptions struct {
// Controller are the controller.Options.
Controller controller.Options
Loading

0 comments on commit b1c110d

Please sign in to comment.