Skip to content
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

Create cluster requirements for DigitalOcean #3248

Merged
merged 1 commit into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ codegen: kops-gobindata
go install k8s.io/kops/upup/tools/generators/...
PATH=${GOPATH_1ST}/bin:${PATH} go generate k8s.io/kops/upup/pkg/fi/cloudup/awstasks
PATH=${GOPATH_1ST}/bin:${PATH} go generate k8s.io/kops/upup/pkg/fi/cloudup/gcetasks
PATH=${GOPATH_1ST}/bin:${PATH} go generate k8s.io/kops/upup/pkg/fi/assettasks
PATH=${GOPATH_1ST}/bin:${PATH} go generate k8s.io/kops/upup/pkg/fi/cloudup/dotasks
PATH=${GOPATH_1ST}/bin:${PATH} go generate k8s.io/kops/upup/pkg/fi/assettasks
PATH=${GOPATH_1ST}/bin:${PATH} go generate k8s.io/kops/upup/pkg/fi/fitasks

.PHONY: protobuf
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/kops/validation/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,22 @@ func ValidateCluster(c *kops.Cluster, strict bool) *field.Error {
return field.Required(fieldSpec.Child("CloudProvider"), "")
}
if c.Spec.Kubelet != nil && (strict || c.Spec.Kubelet.CloudProvider != "") {
if cloudProvider != c.Spec.Kubelet.CloudProvider {
if cloudProvider != c.Spec.Kubelet.CloudProvider && c.Spec.Kubelet.CloudProvider != "external" {
return field.Invalid(fieldSpec.Child("Kubelet", "CloudProvider"), c.Spec.Kubelet.CloudProvider, "Did not match cluster CloudProvider")
}
}
if c.Spec.MasterKubelet != nil && (strict || c.Spec.MasterKubelet.CloudProvider != "") {
if cloudProvider != c.Spec.MasterKubelet.CloudProvider {
if cloudProvider != c.Spec.MasterKubelet.CloudProvider && c.Spec.MasterKubelet.CloudProvider != "external" {
return field.Invalid(fieldSpec.Child("MasterKubelet", "CloudProvider"), c.Spec.MasterKubelet.CloudProvider, "Did not match cluster CloudProvider")
}
}
if c.Spec.KubeAPIServer != nil && (strict || c.Spec.KubeAPIServer.CloudProvider != "") {
if cloudProvider != c.Spec.KubeAPIServer.CloudProvider {
if cloudProvider != c.Spec.KubeAPIServer.CloudProvider && c.Spec.KubeAPIServer.CloudProvider != "external" {
return field.Invalid(fieldSpec.Child("KubeAPIServer", "CloudProvider"), c.Spec.KubeAPIServer.CloudProvider, "Did not match cluster CloudProvider")
}
}
if c.Spec.KubeControllerManager != nil && (strict || c.Spec.KubeControllerManager.CloudProvider != "") {
if cloudProvider != c.Spec.KubeControllerManager.CloudProvider {
if cloudProvider != c.Spec.KubeControllerManager.CloudProvider && c.Spec.KubeControllerManager.CloudProvider != "external" {
return field.Invalid(fieldSpec.Child("KubeControllerManager", "CloudProvider"), c.Spec.KubeControllerManager.CloudProvider, "Did not match cluster CloudProvider")
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/model/components/kubecontrollermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (b *KubeControllerManagerOptionsBuilder) BuildOptions(o interface{}) error
kcm.CloudProvider = "gce"
kcm.ClusterName = gce.SafeClusterName(b.Context.ClusterName)

case kops.CloudProviderDO:
kcm.CloudProvider = "external"

case kops.CloudProviderVSphere:
kcm.CloudProvider = "vsphere"

Expand Down
4 changes: 4 additions & 0 deletions pkg/model/components/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec.Kubelet.HostnameOverride = "@aws"
}

if cloudProvider == kops.CloudProviderDO {
clusterSpec.Kubelet.CloudProvider = "external"
}

if cloudProvider == kops.CloudProviderGCE {
clusterSpec.Kubelet.CloudProvider = "gce"
clusterSpec.Kubelet.HairpinMode = "promiscuous-bridge"
Expand Down
8 changes: 8 additions & 0 deletions pkg/model/master_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ func (b *MasterVolumeBuilder) addAWSVolume(c *fi.ModelBuilderContext, name strin
}

func (b *MasterVolumeBuilder) addDOVolume(c *fi.ModelBuilderContext, name string, volumeSize int32, subnet *kops.ClusterSubnetSpec, etcd *kops.EtcdClusterSpec, m *kops.EtcdMemberSpec, allMembers []string) {
// required that names start with a lower case and only contains letters, numbers and hyphens
name = "kops-" + strings.Replace(name, ".", "-", -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea to check for a length limit as well - that's the other one that is pretty common. We have this code for ELBs: https://github.com/kubernetes/kops/blob/master/pkg/model/context.go#L75-L91 .


// DO has a 64 character limit for volume names
if len(name) >= 64 {
name = name[:64]
}

t := &dotasks.Volume{
Name: s(name),
Lifecycle: b.Lifecycle,
Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (c *ClusterResources) ListResources() (map[string]*ResourceTracker, error)
switch c.Cloud.ProviderID() {
case kops.CloudProviderAWS:
return c.listResourcesAWS()
case kops.CloudProviderDO:
return c.listResourcesDO()
case kops.CloudProviderGCE:
return c.listResourcesGCE()
case kops.CloudProviderVSphere:
Expand Down
21 changes: 21 additions & 0 deletions pkg/resources/do.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2016 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 resources

func (c *ClusterResources) listResourcesDO() (map[string]*ResourceTracker, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary, only to get cluster state creation working, going to work on a refactor to make this work better

return nil, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
KubeAPIServer:
CloudProvider: external
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to move this logic to https://github.com/kubernetes/kops/blob/master/pkg/model/components/apiserver.go
This does rely on the do tag, which I do see you define later, but soon we hope to have fully moved the tag / options logic to code (it is much easier to understand, IMO)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. It was really difficult trying to figure out who to change the CloudProvider flag for kube-apiserver, I'll follow up with this in another PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue to clean this up for all clouds #3253

4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ func (c *ApplyClusterCmd) Run() error {
return fmt.Errorf("DigitalOcean support is currently (very) alpha and is feature-gated. export KOPS_FEATURE_FLAGS=AlphaAllowDO to enable it")
}

// this is a no-op for now, add tasks to this list as more DO support is added
l.AddTypes(map[string]interface{}{
"volume": &dotasks.Volume{},
})
Expand Down Expand Up @@ -649,7 +648,8 @@ func (c *ApplyClusterCmd) Run() error {
BootstrapScript: bootstrapScriptBuilder,
Lifecycle: clusterLifecycle,
})

case kops.CloudProviderDO:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to have a // Digital Ocean tasks will go here comment here, just so we don't think this is a fall-through

// DigitalOcean tasks will go here
case kops.CloudProviderGCE:
{
gceModelContext := &gcemodel.GCEModelContext{
Expand Down
21 changes: 20 additions & 1 deletion upup/pkg/fi/cloudup/populate_instancegroup_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ import (
const (
defaultNodeMachineTypeGCE = "n1-standard-2"
defaultNodeMachineTypeVSphere = "vsphere_node"
defaultNodeMachineTypeDO = "2gb"

defaultBastionMachineTypeGCE = "f1-micro"
defaultBastionMachineTypeVSphere = "vsphere_bastion"

defaultMasterMachineTypeGCE = "n1-standard-1"
defaultMasterMachineTypeVSphere = "vsphere_master"
defaultMasterMachineTypeDO = "2gb"

defaultVSphereNodeImage = "kops_ubuntu_16_04.ova"
defaultDONodeImage = "coreos-stable"
)

var awsDedicatedInstanceExceptions = map[string]bool{
Expand Down Expand Up @@ -177,6 +180,16 @@ func defaultMachineType(cluster *kops.Cluster, ig *kops.InstanceGroup) (string,
return defaultBastionMachineTypeGCE, nil
}

case kops.CloudProviderDO:
switch ig.Spec.Role {
case kops.InstanceGroupRoleMaster:
return defaultMasterMachineTypeDO, nil

case kops.InstanceGroupRoleNode:
return defaultNodeMachineTypeDO, nil

}

case kops.CloudProviderVSphere:
switch ig.Spec.Role {
case kops.InstanceGroupRoleMaster:
Expand Down Expand Up @@ -211,9 +224,15 @@ func defaultImage(cluster *kops.Cluster, channel *kops.Channel) string {
return image.Name
}
}
} else if kops.CloudProviderID(cluster.Spec.CloudProvider) == kops.CloudProviderVSphere {
}

switch kops.CloudProviderID(cluster.Spec.CloudProvider) {
case kops.CloudProviderDO:
return defaultDONodeImage
case kops.CloudProviderVSphere:
return defaultVSphereNodeImage
}

glog.Infof("Cannot set default Image for CloudProvider=%q", cluster.Spec.CloudProvider)
return ""
}
7 changes: 7 additions & 0 deletions upup/pkg/fi/cloudup/tagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func buildCloudupTags(cluster *api.Cluster) (sets.String, error) {
{
tags.Insert("_aws")
}
case "digitalocean":
{
tags.Insert("_do")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully we'll be rid of these tags soon, but I agree that for now we should add them - more logically coherent to be consistent with the other providers, doesn't create a lot more work

}
case "vsphere":
{
tags.Insert("_vsphere")
Expand Down Expand Up @@ -147,6 +151,9 @@ func buildNodeupTags(role api.InstanceGroupRole, cluster *api.Cluster, clusterTa
if clusterTags.Has("_aws") {
tags.Insert("_aws")
}
if clusterTags.Has("_do") {
tags.Insert("_do")
}

return tags, nil
}
4 changes: 4 additions & 0 deletions upup/pkg/fi/cloudup/template_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (tf *TemplateFunctions) DnsControllerArgv() ([]string, error) {
}
case kops.CloudProviderGCE:
argv = append(argv, "--dns=google-clouddns")
case kops.CloudProviderDO:
// this is not supported yet, here so we can successfully create clusters
// this will be supported for digitalocean in the future
argv = append(argv, "--dns=digitalocean")
case kops.CloudProviderVSphere:
argv = append(argv, "--dns=coredns")
argv = append(argv, "--dns-server="+*tf.cluster.Spec.CloudConfig.VSphereCoreDNSServer)
Expand Down