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

fix hostnames in kops openstack #6442

Merged
merged 4 commits into from
Feb 18, 2019
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
10 changes: 5 additions & 5 deletions pkg/model/openstackmodel/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *

igMeta[openstack.TagClusterName] = b.ClusterName()
}
igMeta["k8s"] = b.ClusterName()

startupScript, err := b.BootstrapScript.ResourceNodeUp(ig, b.Cluster)
if err != nil {
Expand All @@ -79,11 +80,10 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
return fmt.Errorf("Failed to create UUID for instance: %v", err)
}
// FIXME: Must ensure 63 or less characters
instanceName := fi.String(
strings.ToLower(
fmt.Sprintf("%s-%d", *sg.Name, i+1),
),
)
// replace all dots with -, this is needed to get external cloudprovider working
iName := strings.ToLower(fmt.Sprintf("%s-%d.%s", ig.Name, i+1, b.ClusterName()))
instanceName := fi.String(strings.Replace(iName, ".", "-", -1))

securityGroupName := b.SecurityGroupName(ig.Spec.Role)
securityGroup := b.LinkToSecurityGroup(securityGroupName)

Expand Down
39 changes: 19 additions & 20 deletions pkg/resources/openstack/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,31 @@ const (

func (os *clusterDiscoveryOS) ListInstances() ([]*resources.Resource, error) {
var resourceTrackers []*resources.Resource
opt := servers.ListOpts{
Name: os.clusterName + "?",
}
instances, err := os.osCloud.ListInstances(opt)
instances, err := os.osCloud.ListInstances(servers.ListOpts{})
if err != nil {
return resourceTrackers, err
}

for _, instance := range instances {

// Clean up any bound floating IP's
floatingIPs, err := os.listFloatingIPs(instance.ID)
if err != nil {
return resourceTrackers, err
}
resourceTrackers = append(resourceTrackers, floatingIPs...)

resourceTracker := &resources.Resource{
Name: instance.Name,
ID: instance.ID,
Type: typeInstance,
Deleter: func(cloud fi.Cloud, r *resources.Resource) error {
return cloud.(openstack.OpenstackCloud).DeleteInstanceWithID(r.ID)
},
val, ok := instance.Metadata["k8s"]
Copy link
Member

Choose a reason for hiding this comment

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

FYI on AWS we use kubernetes.io/cluster/<cluster-name>=shared and kubernetes.io/cluster/<cluster-name>=owned. <cluster-name> can be anything but for kops we use the name of the cluster you create.

We originally had KubernetesCluster=<cluster-name> but this made it hard to have shared resources.

Copy link
Member

Choose a reason for hiding this comment

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

(and it looks like GCP is using kubernetes.io/cluster-id=<cluster-name>, but only in the description field for GCLBs https://github.com/kubernetes/kubernetes/blob/1c557b9ce866d67ec6088f37058e8594b89606ee/pkg/cloudprovider/providers/gce/gce_loadbalancer_external.go#L862

if ok && val == os.clusterName {
// Clean up any bound floating IP's
floatingIPs, err := os.listFloatingIPs(instance.ID)
if err != nil {
return resourceTrackers, err
}
resourceTrackers = append(resourceTrackers, floatingIPs...)

resourceTracker := &resources.Resource{
Name: instance.Name,
ID: instance.ID,
Type: typeInstance,
Deleter: func(cloud fi.Cloud, r *resources.Resource) error {
return cloud.(openstack.OpenstackCloud).DeleteInstanceWithID(r.ID)
},
}
resourceTrackers = append(resourceTrackers, resourceTracker)
}
resourceTrackers = append(resourceTrackers, resourceTracker)
}
return resourceTrackers, nil
}
3 changes: 2 additions & 1 deletion pkg/resources/openstack/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func (os *clusterDiscoveryOS) ListPorts() ([]*resources.Resource, error) {
}

for _, port := range ports {
if strings.Contains(port.Name, os.clusterName) {
clusteReplaced := strings.Replace(os.clusterName, ".", "-", -1)
if strings.HasSuffix(port.Name, clusteReplaced) {
resourceTracker := &resources.Resource{
Name: port.Name,
ID: port.ID,
Expand Down