Skip to content

Commit 55ec7fa

Browse files
authored
Add description to resource capi created (#870)
* Add description to resource capi created
1 parent e08cf62 commit 55ec7fa

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

pkg/cloud/services/compute/instance.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
4848
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
4949
capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors"
50+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/names"
5051
)
5152

5253
const (
@@ -161,7 +162,7 @@ func (s *Service) createInstance(eventObject runtime.Object, clusterName string,
161162
}
162163

163164
if i.Trunk {
164-
trunk, err := s.getOrCreateTrunk(eventObject, i.Name, port.ID)
165+
trunk, err := s.getOrCreateTrunk(eventObject, clusterName, i.Name, port.ID)
165166
if err != nil {
166167
return nil, err
167168
}
@@ -395,7 +396,7 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
395396
Name: portName,
396397
NetworkID: net.ID,
397398
SecurityGroups: securityGroups,
398-
Description: fmt.Sprintf("Created by cluster-api-provider-openstack cluster %s", clusterName),
399+
Description: names.GetDescription(clusterName),
399400
}
400401
if net.Subnet.ID != "" {
401402
portCreateOpts.FixedIPs = []ports.IP{{SubnetID: net.Subnet.ID}}
@@ -410,7 +411,7 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
410411
return port, nil
411412
}
412413

413-
func (s *Service) getOrCreateTrunk(eventObject runtime.Object, trunkName, portID string) (*trunks.Trunk, error) {
414+
func (s *Service) getOrCreateTrunk(eventObject runtime.Object, clusterName, trunkName, portID string) (*trunks.Trunk, error) {
414415
allPages, err := trunks.List(s.networkClient, trunks.ListOpts{
415416
Name: trunkName,
416417
PortID: portID,
@@ -428,8 +429,9 @@ func (s *Service) getOrCreateTrunk(eventObject runtime.Object, trunkName, portID
428429
}
429430

430431
trunkCreateOpts := trunks.CreateOpts{
431-
Name: trunkName,
432-
PortID: portID,
432+
Name: trunkName,
433+
PortID: portID,
434+
Description: names.GetDescription(clusterName),
433435
}
434436
trunk, err := trunks.Create(s.networkClient, trunkCreateOpts).Extract()
435437
if err != nil {

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
3333
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
34+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/names"
3435
)
3536

3637
const (
@@ -52,6 +53,7 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
5253
lbCreateOpts := loadbalancers.CreateOpts{
5354
Name: loadBalancerName,
5455
VipSubnetID: openStackCluster.Status.Network.Subnet.ID,
56+
Description: names.GetDescription(clusterName),
5557
}
5658

5759
lb, err = loadbalancers.Create(s.loadbalancerClient, lbCreateOpts).Extract()

pkg/cloud/services/networking/network.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
3030
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
31+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/names"
3132
)
3233

3334
type createOpts struct {
@@ -194,7 +195,7 @@ func (s *Service) ReconcileSubnet(openStackCluster *infrav1.OpenStackCluster, cl
194195
var subnet *subnets.Subnet
195196
if len(subnetList) == 0 {
196197
var err error
197-
subnet, err = s.createSubnet(openStackCluster, subnetName)
198+
subnet, err = s.createSubnet(openStackCluster, clusterName, subnetName)
198199
if err != nil {
199200
return err
200201
}
@@ -212,13 +213,14 @@ func (s *Service) ReconcileSubnet(openStackCluster *infrav1.OpenStackCluster, cl
212213
return nil
213214
}
214215

215-
func (s *Service) createSubnet(openStackCluster *infrav1.OpenStackCluster, name string) (*subnets.Subnet, error) {
216+
func (s *Service) createSubnet(openStackCluster *infrav1.OpenStackCluster, clusterName string, name string) (*subnets.Subnet, error) {
216217
opts := subnets.CreateOpts{
217218
NetworkID: openStackCluster.Status.Network.ID,
218219
Name: name,
219220
IPVersion: 4,
220221
CIDR: openStackCluster.Spec.NodeCIDR,
221222
DNSNameservers: openStackCluster.Spec.DNSNameservers,
223+
Description: names.GetDescription(clusterName),
222224
}
223225
subnet, err := subnets.Create(s.client, opts).Extract()
224226
if err != nil {

pkg/cloud/services/networking/router.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
2828
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
2929
capoerrors "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/errors"
30+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/names"
3031
)
3132

3233
func (s *Service) ReconcileRouter(openStackCluster *infrav1.OpenStackCluster, clusterName string) error {
@@ -65,7 +66,7 @@ func (s *Service) ReconcileRouter(openStackCluster *infrav1.OpenStackCluster, cl
6566
var router *routers.Router
6667
if len(routerList) == 0 {
6768
var err error
68-
router, err = s.createRouter(openStackCluster, routerName)
69+
router, err = s.createRouter(openStackCluster, clusterName, routerName)
6970
if err != nil {
7071
return err
7172
}
@@ -117,9 +118,10 @@ INTERFACE_LOOP:
117118
return nil
118119
}
119120

120-
func (s *Service) createRouter(openStackCluster *infrav1.OpenStackCluster, name string) (*routers.Router, error) {
121+
func (s *Service) createRouter(openStackCluster *infrav1.OpenStackCluster, clusterName, name string) (*routers.Router, error) {
121122
opts := routers.CreateOpts{
122-
Name: name,
123+
Description: names.GetDescription(clusterName),
124+
Name: name,
123125
}
124126
// only set the GatewayInfo right now when no externalIPs
125127
// should be configured because at least in our environment

pkg/utils/names/names.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package names
18+
19+
import (
20+
"fmt"
21+
)
22+
23+
func GetDescription(clusterName string) string {
24+
return fmt.Sprintf("Created by cluster-api-provider-openstack cluster %s", clusterName)
25+
}

0 commit comments

Comments
 (0)