mirror of https://github.com/kubernetes/kops.git
Add tags for droplets and volumes
This commit is contained in:
parent
1d05a4305e
commit
236521c29f
|
@ -393,10 +393,12 @@ func (b *EtcdManagerBuilder) buildPod(etcdCluster *kops.EtcdClusterSpec) (*v1.Po
|
|||
case kops.CloudProviderDO:
|
||||
config.VolumeProvider = "do"
|
||||
|
||||
// DO does not support . in tags / names
|
||||
safeClusterName := strings.Replace(b.Cluster.Name, ".", "-", -1)
|
||||
|
||||
config.VolumeTag = []string{
|
||||
fmt.Sprintf("kubernetes.io/cluster=%s", b.Cluster.Name),
|
||||
do.TagNameEtcdClusterPrefix + etcdCluster.Name,
|
||||
do.TagNameRolePrefix + "master=1",
|
||||
fmt.Sprintf("%s=%s", do.TagKubernetesClusterNamePrefix, safeClusterName),
|
||||
do.TagKubernetesClusterIndex,
|
||||
}
|
||||
config.VolumeNameTag = do.TagNameEtcdClusterPrefix + etcdCluster.Name
|
||||
|
||||
|
|
|
@ -17,11 +17,12 @@ limitations under the License.
|
|||
package domodel
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"strconv"
|
||||
"k8s.io/kops/pkg/model"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/do"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/dotasks"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DropletBuilder configures droplets for the cluster
|
||||
|
@ -44,7 +45,7 @@ func (d *DropletBuilder) Build(c *fi.ModelBuilderContext) error {
|
|||
sshKeyFingerPrint := splitSSHKeyName[len(splitSSHKeyName)-1]
|
||||
|
||||
// replace "." with "-" since DO API does not accept "."
|
||||
clusterTag := "KubernetesCluster:" + strings.Replace(d.ClusterName(), ".", "-", -1)
|
||||
clusterTag := do.TagKubernetesClusterNamePrefix + ":" + strings.Replace(d.ClusterName(), ".", "-", -1)
|
||||
|
||||
indexCount := 0
|
||||
// In the future, DigitalOcean will use Machine API to manage groups,
|
||||
|
@ -65,7 +66,7 @@ func (d *DropletBuilder) Build(c *fi.ModelBuilderContext) error {
|
|||
|
||||
if ig.IsMaster() {
|
||||
indexCount++
|
||||
clusterTagIndex := "K8S-INDEX:" + strconv.Itoa(indexCount)
|
||||
clusterTagIndex := do.TagKubernetesClusterIndex + ":" + strconv.Itoa(indexCount)
|
||||
droplet.Tags = []string{clusterTag, clusterTagIndex}
|
||||
} else {
|
||||
droplet.Tags = []string{clusterTag}
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/do"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/dotasks"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/do"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/gcetasks"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstacktasks"
|
||||
|
@ -187,17 +187,17 @@ func (b *MasterVolumeBuilder) addDOVolume(c *fi.ModelBuilderContext, name string
|
|||
|
||||
tags := make(map[string]string)
|
||||
tags[do.TagNameEtcdClusterPrefix+etcd.Name] = gce.SafeClusterName(m.Name)
|
||||
tags[do.TagKubernetesClusterIndex] = gce.SafeClusterName(m.Name)
|
||||
|
||||
// We always add an owned tags (these can't be shared)
|
||||
tags[do.TagKubernetesClusterNamePrefix] = gce.SafeClusterName(b.Cluster.ObjectMeta.Name)
|
||||
|
||||
|
||||
t := &dotasks.Volume{
|
||||
Name: s(name),
|
||||
Lifecycle: b.Lifecycle,
|
||||
SizeGB: fi.Int64(int64(volumeSize)),
|
||||
Region: s(zone),
|
||||
Tags: tags,
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
c.AddTask(t)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"k8s.io/kops/upup/pkg/fi"
|
||||
)
|
||||
|
||||
const TagKubernetesClusterIndex = "k8s-index"
|
||||
const TagNameEtcdClusterPrefix = "etcdCluster-"
|
||||
const TagNameRolePrefix = "k8s.io/role/"
|
||||
const TagKubernetesClusterNamePrefix = "KubernetesCluster"
|
||||
|
|
|
@ -143,13 +143,7 @@ func (_ *Droplet) RenderDO(t *do.DOAPITarget, a, e, changes *Droplet) error {
|
|||
newDropletCount = expectedCount - actualCount
|
||||
}
|
||||
|
||||
// var dropletTags []string
|
||||
// indexCount := 0
|
||||
for i := 0; i < newDropletCount; i++ {
|
||||
// indexCount++
|
||||
// clusterTagIndex := "k8s-index:" + strconv.Itoa(indexCount)
|
||||
// dropletTags = append(e.Tags, clusterTagIndex)
|
||||
|
||||
_, _, err = t.Cloud.Droplets().Create(context.TODO(), &godo.DropletCreateRequest{
|
||||
Name: fi.StringValue(e.Name),
|
||||
Region: fi.StringValue(e.Region),
|
||||
|
@ -162,7 +156,7 @@ func (_ *Droplet) RenderDO(t *do.DOAPITarget, a, e, changes *Droplet) error {
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf("Error creating droplet with Name=%s", fi.StringValue(e.Name))
|
||||
klog.Errorf("Error creating droplet with Name=%s", fi.StringValue(e.Name))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ package dotasks
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"github.com/digitalocean/godo"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kops/pkg/resources/digitalocean"
|
||||
|
@ -114,13 +114,13 @@ func (_ *Volume) RenderDO(t *do.DOAPITarget, a, e, changes *Volume) error {
|
|||
|
||||
klog.V(2).Info("Looping DO tag arrays")
|
||||
for k, v := range e.Tags {
|
||||
s := []string{k, v};
|
||||
s := []string{k, v}
|
||||
|
||||
// DO tags don't accept =. Separate the key and value with an ":"
|
||||
strJoin := strings.Join(s, ":")
|
||||
klog.V(2).Infof("DO - Join the volume tag - %s", strJoin)
|
||||
tagArray = append(tagArray, strJoin)
|
||||
}
|
||||
// DO tags don't accept =. Separate the key and value with an ":"
|
||||
strJoin := strings.Join(s, ":")
|
||||
klog.V(2).Infof("DO - Join the volume tag - %s", strJoin)
|
||||
tagArray = append(tagArray, strJoin)
|
||||
}
|
||||
|
||||
volService := t.Cloud.Volumes()
|
||||
_, _, err := volService.CreateVolume(context.TODO(), &godo.VolumeCreateRequest{
|
||||
|
|
Loading…
Reference in New Issue