Skip to content

Commit

Permalink
Merge pull request #9211 from mitch000001/9086-fix-openstack-metadata
Browse files Browse the repository at this point in the history
feat(openstack): propagate cloud labels to machines
  • Loading branch information
k8s-ci-robot authored Aug 19, 2020
2 parents 9be8d8f + df5cc6a commit fc198ff
Show file tree
Hide file tree
Showing 2 changed files with 527 additions and 258 deletions.
15 changes: 14 additions & 1 deletion pkg/model/openstackmodel/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package openstackmodel

import (
"fmt"
"regexp"
"strings"

"k8s.io/klog/v2"
Expand All @@ -38,6 +39,9 @@ type ServerGroupModelBuilder struct {

var _ fi.ModelBuilder = &ServerGroupModelBuilder{}

// See https://specs.openstack.org/openstack/nova-specs/specs/newton/approved/lowercase-metadata-keys.html for details
var instanceMetadataNotAllowedCharacters = regexp.MustCompile("[^a-zA-Z0-9-_:. ]")

func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *openstacktasks.ServerGroup, ig *kops.InstanceGroup) error {

sshKeyNameFull, err := b.SSHKeyName()
Expand All @@ -50,7 +54,16 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
clusterTag := "KubernetesCluster:" + strings.Replace(b.ClusterName(), ".", "-", -1)

igMeta := make(map[string]string)

cloudTags, err := b.KopsModelContext.CloudTagsForInstanceGroup(ig)
if err != nil {
return fmt.Errorf("could not get cloud tags for instance group %s: %v", ig.Name, err)
}
for label, labelVal := range cloudTags {
sanitizedLabel := strings.ToLower(
instanceMetadataNotAllowedCharacters.ReplaceAllLiteralString(label, "_"),
)
igMeta[sanitizedLabel] = labelVal
}
if ig.Spec.Role != kops.InstanceGroupRoleBastion {
// Bastion does not belong to the cluster and will not be running protokube.

Expand Down
Loading

0 comments on commit fc198ff

Please sign in to comment.