Skip to content

Commit 1f6d296

Browse files
Christoph Glaubitzpierreprinetti
authored andcommitted
Tagging of created network resources (openshift#178)
Tagged resouces networks, subnet and router with `cluster-api-provider-openstack` and the cluster name in form of `<namespace>/<name>`.
1 parent e8dbbc5 commit 1f6d296

File tree

7 files changed

+244
-9
lines changed

7 files changed

+244
-9
lines changed

Gopkg.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloud/openstack/clients/networkservice.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222

2323
"github.com/gophercloud/gophercloud"
24+
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
2425
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
2526
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
2627
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
@@ -54,7 +55,7 @@ func (s *NetworkService) Reconcile(clusterName string, desired openstackconfigv1
5455
return nil
5556
}
5657
networkName := fmt.Sprintf("%s-cluster-%s", networkPrefix, clusterName)
57-
network, err := s.reconcileNetwork(networkName, desired)
58+
network, err := s.reconcileNetwork(clusterName, networkName, desired)
5859
if err != nil {
5960
return err
6061
}
@@ -65,7 +66,7 @@ func (s *NetworkService) Reconcile(clusterName string, desired openstackconfigv1
6566
}
6667
status.Network = &network
6768

68-
observedSubnet, err := s.reconcileSubnets(networkName, desired, network)
69+
observedSubnet, err := s.reconcileSubnets(clusterName, networkName, desired, network)
6970
if err != nil {
7071
return err
7172
}
@@ -76,7 +77,7 @@ func (s *NetworkService) Reconcile(clusterName string, desired openstackconfigv1
7677
}
7778
network.Subnet = &observedSubnet
7879

79-
observerdRouter, err := s.reconcileRouter(networkName, desired, network)
80+
observerdRouter, err := s.reconcileRouter(clusterName, networkName, desired, network)
8081
if err != nil {
8182
return err
8283
}
@@ -90,7 +91,7 @@ func (s *NetworkService) Reconcile(clusterName string, desired openstackconfigv1
9091
return nil
9192
}
9293

93-
func (s *NetworkService) reconcileNetwork(networkName string, desired openstackconfigv1.OpenstackClusterProviderSpec) (openstackconfigv1.Network, error) {
94+
func (s *NetworkService) reconcileNetwork(clusterName, networkName string, desired openstackconfigv1.OpenstackClusterProviderSpec) (openstackconfigv1.Network, error) {
9495
klog.Infof("Reconciling network %s", networkName)
9596
emptyNetwork := openstackconfigv1.Network{}
9697
res, err := s.getNetworkByName(networkName)
@@ -115,13 +116,22 @@ func (s *NetworkService) reconcileNetwork(networkName string, desired openstackc
115116
return emptyNetwork, err
116117
}
117118

119+
_, err = attributestags.ReplaceAll(s.client, "networks", network.ID, attributestags.ReplaceAllOpts{
120+
Tags: []string{
121+
"cluster-api-provider-openstack",
122+
clusterName,
123+
}}).Extract()
124+
if err != nil {
125+
return emptyNetwork, err
126+
}
127+
118128
return openstackconfigv1.Network{
119129
ID: network.ID,
120130
Name: network.Name,
121131
}, nil
122132
}
123133

124-
func (s *NetworkService) reconcileSubnets(name string, desired openstackconfigv1.OpenstackClusterProviderSpec, network openstackconfigv1.Network) (openstackconfigv1.Subnet, error) {
134+
func (s *NetworkService) reconcileSubnets(clusterName, name string, desired openstackconfigv1.OpenstackClusterProviderSpec, network openstackconfigv1.Network) (openstackconfigv1.Subnet, error) {
125135
klog.Infof("Reconciling subnet %s", name)
126136
emptySubnet := openstackconfigv1.Subnet{}
127137
allPages, err := subnets.List(s.client, subnets.ListOpts{
@@ -169,10 +179,19 @@ func (s *NetworkService) reconcileSubnets(name string, desired openstackconfigv1
169179
}
170180
}
171181

182+
_, err = attributestags.ReplaceAll(s.client, "subnets", observedSubnet.ID, attributestags.ReplaceAllOpts{
183+
Tags: []string{
184+
"cluster-api-provider-openstack",
185+
clusterName,
186+
}}).Extract()
187+
if err != nil {
188+
return emptySubnet, err
189+
}
190+
172191
return observedSubnet, nil
173192
}
174193

175-
func (s *NetworkService) reconcileRouter(name string, desired openstackconfigv1.OpenstackClusterProviderSpec, network openstackconfigv1.Network) (openstackconfigv1.Router, error) {
194+
func (s *NetworkService) reconcileRouter(clusterName, name string, desired openstackconfigv1.OpenstackClusterProviderSpec, network openstackconfigv1.Network) (openstackconfigv1.Router, error) {
176195
klog.Infof("Reconciling router %s", name)
177196
emptyRouter := openstackconfigv1.Router{}
178197
if network.ID == "" {
@@ -249,6 +268,15 @@ INTERFACE_LOOP:
249268
klog.V(4).Infof("Created RouterInterface: %v", iface)
250269
}
251270

271+
_, err = attributestags.ReplaceAll(s.client, "routers", observedRouter.ID, attributestags.ReplaceAllOpts{
272+
Tags: []string{
273+
"cluster-api-provider-openstack",
274+
clusterName,
275+
}}).Extract()
276+
if err != nil {
277+
return emptyRouter, err
278+
}
279+
252280
return observedRouter, nil
253281
}
254282

pkg/cloud/openstack/cluster/actuator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (a *Actuator) Reconcile(cluster *clusterv1.Cluster) error {
5151
return errors.Errorf("failed to load cluster provider status: %v", err)
5252
}
5353

54-
err = networkService.Reconcile(fmt.Sprintf("%s-%s", cluster.ObjectMeta.Namespace, cluster.Name), *desired, status)
54+
err = networkService.Reconcile(fmt.Sprintf("%s/%s", cluster.ObjectMeta.Namespace, cluster.Name), *desired, status)
5555
if err != nil {
5656
return errors.Errorf("failed to reconcile network: %v", err)
5757
}

vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags/doc.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags/requests.go

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags/results.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags/urls.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)