Skip to content

Commit 4e7e0fe

Browse files
committed
structured logging migration of securitygroups.go, instance.go, service.go, and floatingip.go (rebase)
1 parent 9e06dc2 commit 4e7e0fe

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pkg/cloud/services/compute/instance.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (s *Service) normalizePortTarget(port *infrav1.PortOpts, openStackCluster *
7373
// No network, but fixed IPs are defined(we handled the no fixed
7474
// IPs case above): try to infer network from a subnet
7575
if noNetwork {
76-
s.scope.Logger().V(4).Info("No network defined for port %d, attempting to infer from subnet", portIdx)
76+
s.scope.Logger().V(4).Info("No network defined for port, attempting to infer from subnet", "port", portIdx)
7777

7878
// Look for a unique subnet defined in FixedIPs. If we find one
7979
// we can use it to infer the network ID. We don't need to worry
@@ -95,7 +95,7 @@ func (s *Service) normalizePortTarget(port *infrav1.PortOpts, openStackCluster *
9595
if err != nil {
9696
// Multiple matches might be ok later when we restrict matches to a single network
9797
if errors.Is(err, networking.ErrMultipleMatches) {
98-
s.scope.Logger().V(4).Info("Can't infer network from subnet %d: %s", i, err)
98+
s.scope.Logger().V(4).Info("Couldn't infer network from subnet", "subnetIndex", i, "err", err)
9999
continue
100100
}
101101

@@ -433,7 +433,7 @@ func (s *Service) getOrCreateRootVolume(eventObject runtime.Object, instanceSpec
433433
return nil, fmt.Errorf("exected to find volume %s with size %d; found size %d", name, size, volume.Size)
434434
}
435435

436-
s.scope.Logger().Info("using existing root volume %s", name)
436+
s.scope.Logger().V(3).Info("Using existing root volume", "name", name)
437437
return volume, nil
438438
}
439439

@@ -580,7 +580,7 @@ func (s *Service) DeleteInstance(eventObject runtime.Object, instanceStatus *Ins
580580
return nil
581581
}
582582

583-
s.scope.Logger().Info("deleting dangling root volume %s(%s)", volume.Name, volume.ID)
583+
s.scope.Logger().V(2).Info("Deleting dangling root volume", "name", volume.Name, "ID", volume.ID)
584584
return s.getVolumeClient().DeleteVolume(volume.ID, volumes.DeleteOpts{})
585585
}
586586

pkg/cloud/services/networking/floatingip.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ var backoff = wait.Backoff{
121121
}
122122

123123
func (s *Service) AssociateFloatingIP(eventObject runtime.Object, fp *floatingips.FloatingIP, portID string) error {
124-
s.scope.Logger().Info("Associating floating IP", "id", fp.ID, "ip", fp.FloatingIP)
124+
s.scope.Logger().Info("Associating floating IP", "ID", fp.ID, "IP", fp.FloatingIP)
125125

126126
if fp.PortID == portID {
127-
s.scope.Logger().Info("Floating IP already associated:", "id", fp.ID, "ip", fp.FloatingIP)
127+
s.scope.Logger().Info("Floating IP already associated:", "ID", fp.ID, "IP", fp.FloatingIP)
128128
return nil
129129
}
130130

@@ -153,11 +153,11 @@ func (s *Service) DisassociateFloatingIP(eventObject runtime.Object, ip string)
153153
return err
154154
}
155155
if fip == nil || fip.FloatingIP == "" {
156-
s.scope.Logger().Info("Floating IP not associated", "ip", ip)
156+
s.scope.Logger().Info("Floating IP not associated", "IP", ip)
157157
return nil
158158
}
159159

160-
s.scope.Logger().Info("Disassociating floating IP", "id", fip.ID, "ip", fip.FloatingIP)
160+
s.scope.Logger().Info("Disassociating floating IP", "ID", fip.ID, "IP", fip.FloatingIP)
161161

162162
fpUpdateOpts := &floatingips.UpdateOpts{
163163
PortID: nil,
@@ -179,7 +179,7 @@ func (s *Service) DisassociateFloatingIP(eventObject runtime.Object, ip string)
179179
}
180180

181181
func (s *Service) waitForFloatingIP(id, target string) error {
182-
s.scope.Logger().Info("Waiting for floating IP", "id", id, "targetStatus", target)
182+
s.scope.Logger().Info("Waiting for floating IP", "ID", id, "status", target)
183183
return wait.ExponentialBackoff(backoff, func() (bool, error) {
184184
fip, err := s.client.GetFloatingIP(id)
185185
if err != nil {

pkg/cloud/services/networking/securitygroups.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const (
3737

3838
// ReconcileSecurityGroups reconcile the security groups.
3939
func (s *Service) ReconcileSecurityGroups(openStackCluster *infrav1.OpenStackCluster, clusterName string) error {
40-
s.scope.Logger().Info("Reconciling security groups", "cluster", clusterName)
40+
s.scope.Logger().Info("Reconciling security groups")
4141
if !openStackCluster.Spec.ManagedSecurityGroups {
42-
s.scope.Logger().V(4).Info("No need to reconcile security groups", "cluster", clusterName)
42+
s.scope.Logger().V(4).Info("No need to reconcile security groups")
4343
return nil
4444
}
4545

@@ -290,7 +290,7 @@ func (s *Service) reconcileGroupRules(desired, observed infrav1.SecurityGroup) (
290290

291291
s.scope.Logger().V(4).Info("Deleting rules not needed anymore for group", "name", observed.Name, "amount", len(rulesToDelete))
292292
for _, rule := range rulesToDelete {
293-
s.scope.Logger().V(6).Info("Deleting rule", "ruleID", rule.ID, "groupName", observed.Name)
293+
s.scope.Logger().V(6).Info("Deleting rule", "ID", rule.ID, "name", observed.Name)
294294
err := s.client.DeleteSecGroupRule(rule.ID)
295295
if err != nil {
296296
return infrav1.SecurityGroup{}, err
@@ -321,7 +321,7 @@ func (s *Service) createSecurityGroupIfNotExists(openStackCluster *infrav1.OpenS
321321
return err
322322
}
323323
if secGroup == nil || secGroup.ID == "" {
324-
s.scope.Logger().V(6).Info("Group doesn't exist, creating it.", "name", groupName)
324+
s.scope.Logger().V(6).Info("Group doesn't exist, creating it", "name", groupName)
325325

326326
createOpts := groups.CreateOpts{
327327
Name: groupName,
@@ -391,7 +391,7 @@ func (s *Service) createRule(r infrav1.SecurityGroupRule) (infrav1.SecurityGroup
391391
RemoteIPPrefix: r.RemoteIPPrefix,
392392
SecGroupID: r.SecurityGroupID,
393393
}
394-
s.scope.Logger().V(6).Info("Creating rule", "Description", r.Description, "Direction", dir, "PortRangeMin", r.PortRangeMin, "PortRangeMax", r.PortRangeMax, "Proto", proto, "etherType", etherType, "RemoteGroupID", r.RemoteGroupID, "RemoteIPPrefix", r.RemoteIPPrefix, "SecurityGroupID", r.SecurityGroupID)
394+
s.scope.Logger().V(6).Info("Creating rule", "description", r.Description, "direction", dir, "portRangeMin", r.PortRangeMin, "portRangeMax", r.PortRangeMax, "proto", proto, "etherType", etherType, "remoteGroupID", r.RemoteGroupID, "remoteIPPrefix", r.RemoteIPPrefix, "securityGroupID", r.SecurityGroupID)
395395
rule, err := s.client.CreateSecGroupRule(createOpts)
396396
if err != nil {
397397
return infrav1.SecurityGroupRule{}, err

pkg/cloud/services/networking/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewService(scope scope.Scope) (*Service, error) {
5858
// the value of resourceType must match one of the allowed constants: trunkResource or portResource.
5959
func (s *Service) replaceAllAttributesTags(eventObject runtime.Object, resourceType string, resourceID string, tags []string) error {
6060
if len(tags) == 0 {
61-
s.scope.Logger().Info("no tags provided to ReplaceAllAttributesTags", "resourceType", resourceType, "resourceID", resourceID)
61+
s.scope.Logger().Info("No tags provided to replaceAllAttributesTags", "resource", resourceType, "ID", resourceID)
6262
return nil
6363
}
6464
if resourceType != trunkResource && resourceType != portResource {

0 commit comments

Comments
 (0)