diff --git a/pkg/model/components/BUILD.bazel b/pkg/model/components/BUILD.bazel index 6968fdff22..b3dd01a07c 100644 --- a/pkg/model/components/BUILD.bazel +++ b/pkg/model/components/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "apiserver.go", + "awscloudcontrollermanager.go", "awsebscsidriver.go", "calico.go", "cilium.go", diff --git a/pkg/model/components/awscloudcontrollermanager.go b/pkg/model/components/awscloudcontrollermanager.go new file mode 100644 index 0000000000..bd352bc105 --- /dev/null +++ b/pkg/model/components/awscloudcontrollermanager.go @@ -0,0 +1,79 @@ +/* +Copyright 2021 The Kubernetes Authors. + +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 components + +import ( + "fmt" + + "k8s.io/kops/pkg/apis/kops" + "k8s.io/kops/upup/pkg/fi" + "k8s.io/kops/upup/pkg/fi/loader" +) + +// KubeControllerManagerOptionsBuilder adds options for the kubernetes controller manager to the model. +type AWSCloudControllerManagerOptionsBuilder struct { + *OptionsContext +} + +var _ loader.OptionsBuilder = &AWSCloudControllerManagerOptionsBuilder{} + +// BuildOptions generates the configurations used for the AWS cloud controller manager manifest +func (b *AWSCloudControllerManagerOptionsBuilder) BuildOptions(o interface{}) error { + + clusterSpec := o.(*kops.ClusterSpec) + + eccm := clusterSpec.ExternalCloudControllerManager + + if eccm == nil || kops.CloudProviderID(eccm.CloudProvider) != kops.CloudProviderAWS { + return nil + } + + eccm.ClusterName = b.ClusterName + + eccm.ClusterCIDR = clusterSpec.NonMasqueradeCIDR + + eccm.AllocateNodeCIDRs = fi.Bool(true) + eccm.ConfigureCloudRoutes = fi.Bool(false) + + // TODO: we want to consolidate this with the logic from KCM + networking := clusterSpec.Networking + if networking == nil { + eccm.ConfigureCloudRoutes = fi.Bool(true) + } else if networking.Kubenet != nil { + eccm.ConfigureCloudRoutes = fi.Bool(true) + } else if networking.GCE != nil { + eccm.ConfigureCloudRoutes = fi.Bool(false) + eccm.CIDRAllocatorType = fi.String("CloudAllocator") + + if eccm.ClusterCIDR == "" { + eccm.ClusterCIDR = clusterSpec.PodCIDR + } + } else if networking.External != nil { + eccm.ConfigureCloudRoutes = fi.Bool(false) + } else if UsesCNI(networking) { + eccm.ConfigureCloudRoutes = fi.Bool(false) + } else if networking.Kopeio != nil { + // Kopeio is based on kubenet / external + eccm.ConfigureCloudRoutes = fi.Bool(false) + } else { + return fmt.Errorf("no networking mode set") + } + + eccm.Master = "https://127.0.0.1" + + return nil +} diff --git a/upup/pkg/fi/cloudup/populate_cluster_spec.go b/upup/pkg/fi/cloudup/populate_cluster_spec.go index 1c91a57d95..6b55a0f027 100644 --- a/upup/pkg/fi/cloudup/populate_cluster_spec.go +++ b/upup/pkg/fi/cloudup/populate_cluster_spec.go @@ -281,6 +281,7 @@ func (c *populateClusterSpec) run(clientset simple.Clientset) error { codeModels = append(codeModels, &components.ClusterAutoscalerOptionsBuilder{OptionsContext: optionsContext}) codeModels = append(codeModels, &components.NodeTerminationHandlerOptionsBuilder{OptionsContext: optionsContext}) codeModels = append(codeModels, &components.AWSEBSCSIDriverOptionsBuilder{OptionsContext: optionsContext}) + codeModels = append(codeModels, &components.AWSCloudControllerManagerOptionsBuilder{OptionsContext: optionsContext}) } } diff --git a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/aws-cloud-controller.addons.k8s.io-k8s-1.18.yaml b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/aws-cloud-controller.addons.k8s.io-k8s-1.18.yaml index 070c6e2031..e92dac5e24 100644 --- a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/aws-cloud-controller.addons.k8s.io-k8s-1.18.yaml +++ b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/aws-cloud-controller.addons.k8s.io-k8s-1.18.yaml @@ -21,8 +21,13 @@ spec: spec: containers: - args: + - --master=https://127.0.0.1 - --v=2 - --cloud-provider=aws + - --cluster-name=minimal.example.com + - --cluster-cidr=100.64.0.0/10 + - --allocate-node-cidrs=true + - --configure-cloud-routes=false - --use-service-account-credentials=true image: gcr.io/k8s-staging-provider-aws/cloud-controller-manager:latest name: aws-cloud-controller-manager diff --git a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/manifest.yaml b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/manifest.yaml index 8220cebdb3..3520502160 100644 --- a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/manifest.yaml +++ b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/awscloudcontroller/manifest.yaml @@ -55,7 +55,7 @@ spec: - id: k8s-1.18 kubernetesVersion: '>=1.18.0' manifest: aws-cloud-controller.addons.k8s.io/k8s-1.18.yaml - manifestHash: c0a92fc15661776506a8861a5600315b930a599b + manifestHash: d1234040768f371ebb4a4e27cac699e215afb173 name: aws-cloud-controller.addons.k8s.io selector: k8s-addon: aws-cloud-controller.addons.k8s.io