Skip to content

Commit

Permalink
Use random instance names in OpenStack
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaab committed Jan 12, 2021
1 parent 06a533e commit 185ccba
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cloudmock/openstack/mockcompute/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (m *MockClient) listServers(w http.ResponseWriter, vals url.Values) {
serverName := strings.Trim(vals.Get("name"), "^$")
matched := make([]servers.Server, 0)
for _, server := range m.servers {
if server.Name == serverName {
if strings.HasPrefix(server.Name, serverName) {
matched = append(matched, server)
}
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/model/openstackmodel/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
securityGroups = append(securityGroups, b.LinkToSecurityGroup(b.Cluster.Spec.MasterPublicName))
}

r := strings.NewReplacer("_", "-", ".", "-")
groupName := r.Replace(strings.ToLower(ig.Name))
// In the future, OpenStack will use Machine API to manage groups,
// for now create d.InstanceGroups.Spec.MinSize amount of servers
for i := int32(0); i < *ig.Spec.MinSize; i++ {
Expand Down Expand Up @@ -141,8 +143,14 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
}
c.AddTask(portTask)

metaWithName := make(map[string]string)
for k, v := range igMeta {
metaWithName[k] = v
}
metaWithName[openstack.TagKopsName] = fi.StringValue(instanceName)
instanceTask := &openstacktasks.Instance{
Name: instanceName,
NamePrefix: s(groupName),
Region: fi.String(b.Cluster.Spec.Subnets[0].Region),
Flavor: fi.String(ig.Spec.MachineType),
Image: fi.String(ig.Spec.Image),
Expand All @@ -151,7 +159,7 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
Role: fi.String(string(ig.Spec.Role)),
Port: portTask,
UserData: startupScript,
Metadata: igMeta,
Metadata: metaWithName,
SecurityGroups: ig.Spec.AdditionalSecurityGroups,
AvailabilityZone: az,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Image: image-node
Lifecycle: null
Metadata:
KopsInstanceGroup: node
KopsName: node-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -20,6 +21,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node
Name: node-1-cluster
NamePrefix: node
Port:
AdditionalSecurityGroups:
- additional-sg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Image: image-node
Lifecycle: null
Metadata:
KopsInstanceGroup: node
KopsName: node-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -21,6 +22,7 @@ Metadata:
kops.k8s.io_instancegroup: node
some___:x: label
Name: node-1-cluster
NamePrefix: node
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Image: image-node
Lifecycle: null
Metadata:
KopsInstanceGroup: node
KopsName: node-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -21,6 +22,7 @@ Metadata:
kops.k8s.io_instancegroup: node
some___:x: label
Name: node-1-cluster
NamePrefix: node
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master
KopsName: master-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -71,6 +72,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master
Name: master-1-cluster
NamePrefix: master
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -135,6 +137,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master
KopsName: master-2-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -147,6 +150,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master
Name: master-2-cluster
NamePrefix: master
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -211,6 +215,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master
KopsName: master-3-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -223,6 +228,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master
Name: master-3-cluster
NamePrefix: master
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -287,6 +293,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node
KopsName: node-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -298,6 +305,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node
Name: node-1-cluster
NamePrefix: node
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -356,6 +364,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node
KopsName: node-2-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -367,6 +376,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node
Name: node-2-cluster
NamePrefix: node
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -425,6 +435,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node
KopsName: node-3-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -436,6 +447,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node
Name: node-3-cluster
NamePrefix: node
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master-a
KopsName: master-a-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -72,6 +73,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master-a
Name: master-a-1-cluster
NamePrefix: master-a
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -124,6 +126,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master-b
KopsName: master-b-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -136,6 +139,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master-b
Name: master-b-1-cluster
NamePrefix: master-b
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -188,6 +192,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master-c
KopsName: master-c-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -200,6 +205,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master-c
Name: master-c-1-cluster
NamePrefix: master-c
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -258,6 +264,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node-a
KopsName: node-a-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -269,6 +276,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node-a
Name: node-a-1-cluster
NamePrefix: node-a
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -327,6 +335,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node-b
KopsName: node-b-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -338,6 +347,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node-b
Name: node-b-1-cluster
NamePrefix: node-b
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -396,6 +406,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node-c
KopsName: node-c-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -407,6 +418,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node-c
Name: node-c-1-cluster
NamePrefix: node-c
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master-a
KopsName: master-a-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -79,6 +80,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master-a
Name: master-a-1-cluster
NamePrefix: master-a
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -143,6 +145,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master-b
KopsName: master-b-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -155,6 +158,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master-b
Name: master-b-1-cluster
NamePrefix: master-b
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -219,6 +223,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: master-c
KopsName: master-c-1-cluster
KopsNetwork: cluster
KopsRole: Master
KubernetesCluster: cluster
Expand All @@ -231,6 +236,7 @@ Metadata:
k8s.io_role_master: "1"
kops.k8s.io_instancegroup: master-c
Name: master-c-1-cluster
NamePrefix: master-c
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -295,6 +301,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node-a
KopsName: node-a-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -306,6 +313,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node-a
Name: node-a-1-cluster
NamePrefix: node-a
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -364,6 +372,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node-b
KopsName: node-b-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -375,6 +384,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node-b
Name: node-b-1-cluster
NamePrefix: node-b
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down Expand Up @@ -433,6 +443,7 @@ Image: image
Lifecycle: null
Metadata:
KopsInstanceGroup: node-c
KopsName: node-c-1-cluster
KopsNetwork: cluster
KopsRole: Node
KubernetesCluster: cluster
Expand All @@ -444,6 +455,7 @@ Metadata:
k8s.io_role_node: "1"
kops.k8s.io_instancegroup: node-c
Name: node-c-1-cluster
NamePrefix: node-c
Port:
AdditionalSecurityGroups: null
ID: null
Expand Down
Loading

0 comments on commit 185ccba

Please sign in to comment.