Skip to content

Commit 67b49c0

Browse files
authored
Merge pull request #596 from jichenjc/bug/543
Remove Tag creation for ports and add description for it
2 parents 5100d59 + e58572d commit 67b49c0

File tree

8 files changed

+24
-44
lines changed

8 files changed

+24
-44
lines changed

api/v1alpha3/openstackcluster_types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ type OpenStackClusterSpec struct {
9999
// Tags for all resources in cluster
100100
Tags []string `json:"tags,omitempty"`
101101

102-
// Default: True. In case of server tag errors, set to False
103-
DisableServerTags bool `json:"disableServerTags,omitempty"`
104-
105102
// CAKeyPair is the key pair for ca certs.
106103
CAKeyPair KeyPair `json:"caKeyPair,omitempty"`
107104

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ spec:
127127
network created for the Kubernetes cluster, which also disables
128128
SecurityGroups
129129
type: boolean
130-
disableServerTags:
131-
description: 'Default: True. In case of server tag errors, set to
132-
False'
133-
type: boolean
134130
dnsNameservers:
135131
description: DNSNameservers is the list of nameservers for OpenStack
136132
Subnet being created. Set this value when you need create a new

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ spec:
173173
174174
## Tagging
175175
176-
By default, all resources will be tagged with the values: `clusterName` and `cluster-api-provider-openstack`. The minimum microversion of the nova api that you need to support server tagging is 2.52. If your cluster does not support this, then disable tagging servers by setting `disableServerTags: true` in `cluster.yaml`. By default, this value is false. If your cluster supports tagging servers, you have the ability to tag all resources created by the cluster in the `cluster.yaml` file. Here is an example how to configure tagging:
176+
If your cluster supports tagging servers, you have the ability to tag all resources created by the cluster in the `cluster.yaml` file. Here is an example how to configure tagging:
177177

178178
```yaml
179179
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3

pkg/cloud/services/compute/instance.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
7878
}
7979
}
8080

81-
// Set default Tags
82-
machineTags := []string{
83-
"cluster-api-provider-openstack",
84-
clusterName,
85-
}
81+
machineTags := []string{}
8682

8783
// Append machine specific tags
8884
machineTags = append(machineTags, openStackMachine.Spec.Tags...)
@@ -150,19 +146,14 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
150146
var port ports.Port
151147
if len(portList) == 0 {
152148
// create server port
153-
port, err = createPort(s, openStackMachine.Name, net, &securityGroups)
149+
port, err = createPort(s, clusterName, openStackMachine.Name, net, &securityGroups)
154150
if err != nil {
155151
return nil, fmt.Errorf("failed to create port err: %v", err)
156152
}
157153
} else {
158154
port = portList[0]
159155
}
160156

161-
_, err = attributestags.ReplaceAll(s.networkClient, "ports", port.ID, attributestags.ReplaceAllOpts{
162-
Tags: machineTags}).Extract()
163-
if err != nil {
164-
return nil, fmt.Errorf("tagging port for server err: %v", err)
165-
}
166157
portsList = append(portsList, servers.Network{
167158
Port: port.ID,
168159
})
@@ -204,7 +195,7 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
204195
}
205196

206197
var serverTags []string
207-
if !openStackCluster.Spec.DisableServerTags {
198+
if len(machineTags) > 0 {
208199
serverTags = machineTags
209200
// NOTE(flaper87): This is the minimum required version
210201
// to use tags.
@@ -389,11 +380,12 @@ func isDuplicate(list []string, name string) bool {
389380
return false
390381
}
391382

392-
func createPort(is *Service, name string, net ServerNetwork, securityGroups *[]string) (ports.Port, error) {
383+
func createPort(is *Service, clusterName string, name string, net ServerNetwork, securityGroups *[]string) (ports.Port, error) {
393384
portCreateOpts := ports.CreateOpts{
394385
Name: name,
395386
NetworkID: net.networkID,
396387
SecurityGroups: securityGroups,
388+
Description: fmt.Sprintf("Created by cluster-api-provider-openstack cluster %s", clusterName),
397389
}
398390
if net.subnetID != "" {
399391
portCreateOpts.FixedIPs = []ports.IP{{SubnetID: net.subnetID}}

pkg/cloud/services/networking/network.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,12 @@ func (s *Service) ReconcileNetwork(clusterName string, openStackCluster *infrav1
128128
}
129129
record.Eventf(openStackCluster, "SuccessfulCreateNetwork", "Created network %s with id %s", networkName, network.ID)
130130

131-
_, err = attributestags.ReplaceAll(s.client, "networks", network.ID, attributestags.ReplaceAllOpts{
132-
Tags: []string{
133-
"cluster-api-provider-openstack",
134-
clusterName,
135-
}}).Extract()
136-
if err != nil {
137-
return err
131+
if len(openStackCluster.Spec.Tags) > 0 {
132+
_, err = attributestags.ReplaceAll(s.client, "networks", network.ID, attributestags.ReplaceAllOpts{
133+
Tags: openStackCluster.Spec.Tags}).Extract()
134+
if err != nil {
135+
return err
136+
}
138137
}
139138

140139
openStackCluster.Status.Network = &infrav1.Network{
@@ -221,13 +220,12 @@ func (s *Service) ReconcileSubnet(clusterName string, openStackCluster *infrav1.
221220
}
222221
}
223222

224-
_, err = attributestags.ReplaceAll(s.client, "subnets", observedSubnet.ID, attributestags.ReplaceAllOpts{
225-
Tags: []string{
226-
"cluster-api-provider-openstack",
227-
clusterName,
228-
}}).Extract()
229-
if err != nil {
230-
return err
223+
if len(openStackCluster.Spec.Tags) > 0 {
224+
_, err = attributestags.ReplaceAll(s.client, "subnets", observedSubnet.ID, attributestags.ReplaceAllOpts{
225+
Tags: openStackCluster.Spec.Tags}).Extract()
226+
if err != nil {
227+
return err
228+
}
231229
}
232230

233231
openStackCluster.Status.Network.Subnet = &observedSubnet

pkg/cloud/services/networking/router.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,12 @@ INTERFACE_LOOP:
153153
s.logger.V(4).Info("Created RouterInterface", "id", routerInterface.ID)
154154
}
155155

156-
_, err = attributestags.ReplaceAll(s.client, "routers", observedRouter.ID, attributestags.ReplaceAllOpts{
157-
Tags: []string{
158-
"cluster-api-provider-openstack",
159-
clusterName,
160-
}}).Extract()
161-
if err != nil {
162-
return err
156+
if len(openStackCluster.Spec.Tags) > 0 {
157+
_, err = attributestags.ReplaceAll(s.client, "routers", observedRouter.ID, attributestags.ReplaceAllOpts{
158+
Tags: openStackCluster.Spec.Tags}).Extract()
159+
if err != nil {
160+
return err
161+
}
163162
}
164163

165164
if observedRouter.ID != "" {

templates/cluster-template-without-lb.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ spec:
3030
dnsNameservers:
3131
- ${OPENSTACK_DNS_NAMESERVERS}
3232
disablePortSecurity: true
33-
disableServerTags: true
3433
useOctavia: false
3534
---
3635
kind: KubeadmControlPlane

templates/cluster-template.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ spec:
3232
dnsNameservers:
3333
- ${OPENSTACK_DNS_NAMESERVERS}
3434
disablePortSecurity: false
35-
disableServerTags: true
3635
useOctavia: true
3736
---
3837
kind: KubeadmControlPlane

0 commit comments

Comments
 (0)