Skip to content

Commit ec057ad

Browse files
authored
Merge pull request #3144 from pydctw/improve-logging
Make logging for creating/deleting AWS resources consistent
2 parents 9151d15 + e7f34bc commit ec057ad

File tree

8 files changed

+19
-15
lines changed

8 files changed

+19
-15
lines changed

pkg/cloud/services/ec2/bastion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *Service) ReconcileBastion() error {
8383
}
8484

8585
record.Eventf(s.scope.InfraCluster(), "SuccessfulCreateBastion", "Created bastion instance %q", instance.ID)
86-
s.scope.V(2).Info("Created new bastion host", "instance", instance)
86+
s.scope.Info("Created new bastion host", "id", instance.ID)
8787
} else if err != nil {
8888
return err
8989
}
@@ -123,6 +123,7 @@ func (s *Service) DeleteBastion() error {
123123

124124
conditions.MarkFalse(s.scope.InfraCluster(), infrav1.BastionHostReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "")
125125
record.Eventf(s.scope.InfraCluster(), "SuccessfulTerminateBastion", "Terminated bastion instance %q", instance.ID)
126+
s.scope.Info("Deleted bastion host", "id", instance.ID)
126127

127128
return nil
128129
}

pkg/cloud/services/elb/loadbalancer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (s *Service) deleteAPIServerELB() error {
179179
}
180180

181181
conditions.MarkFalse(s.scope.InfraCluster(), infrav1.LoadBalancerReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "")
182-
s.scope.V(2).Info("Deleting control plane load balancer completed successfully")
182+
s.scope.Info("Deleted control plane load balancer", "name", elbName)
183183
return nil
184184
}
185185

@@ -213,7 +213,6 @@ func (s *Service) deleteAWSCloudProviderELBs() error {
213213
return errors.Wrapf(err, "failed to wait for %q load balancer deletions", s.scope.Name())
214214
}
215215

216-
s.scope.V(2).Info("Deleting AWS cloud provider load balancer(s) completed successfully")
217216
return nil
218217
}
219218

@@ -539,7 +538,7 @@ func (s *Service) createClassicELB(spec *infrav1.ClassicELB) (*infrav1.ClassicEL
539538
}
540539
}
541540

542-
s.scope.V(2).Info("Created classic load balancer", "dns-name", *out.DNSName)
541+
s.scope.Info("Created classic load balancer", "dns-name", *out.DNSName)
543542

544543
res := spec.DeepCopy()
545544
res.DNSName = *out.DNSName
@@ -582,6 +581,8 @@ func (s *Service) deleteClassicELB(name string) error {
582581
if _, err := s.ELBClient.DeleteLoadBalancer(input); err != nil {
583582
return err
584583
}
584+
585+
s.scope.Info("Deleted AWS cloud provider load balancers")
585586
return nil
586587
}
587588

pkg/cloud/services/network/gateways.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (s *Service) deleteInternetGateways() error {
101101
}
102102

103103
record.Eventf(s.scope.InfraCluster(), "SuccessfulDetachInternetGateway", "Detached Internet Gateway %q from VPC %q", *ig.InternetGatewayId, s.scope.VPC().ID)
104-
s.scope.Info("Detached internet gateway from VPC", "internet-gateway-id", *ig.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
104+
s.scope.V(2).Info("Detached internet gateway from VPC", "internet-gateway-id", *ig.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
105105

106106
deleteReq := &ec2.DeleteInternetGatewayInput{
107107
InternetGatewayId: ig.InternetGatewayId,
@@ -113,7 +113,7 @@ func (s *Service) deleteInternetGateways() error {
113113
}
114114

115115
record.Eventf(s.scope.InfraCluster(), "SuccessfulDeleteInternetGateway", "Deleted Internet Gateway %q previously attached to VPC %q", *ig.InternetGatewayId, s.scope.VPC().ID)
116-
s.scope.Info("Deleted internet gateway in VPC", "internet-gateway-id", *ig.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
116+
s.scope.Info("Deleted Internet gateway in VPC", "internet-gateway-id", *ig.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
117117
}
118118

119119
return nil
@@ -130,7 +130,7 @@ func (s *Service) createInternetGateway() (*ec2.InternetGateway, error) {
130130
return nil, errors.Wrap(err, "failed to create internet gateway")
131131
}
132132
record.Eventf(s.scope.InfraCluster(), "SuccessfulCreateInternetGateway", "Created new managed Internet Gateway %q", *ig.InternetGateway.InternetGatewayId)
133-
s.scope.Info("Created internet gateway for VPC", "vpc-id", s.scope.VPC().ID)
133+
s.scope.Info("Created Internet gateway for VPC", "internet-gateway-id", *ig.InternetGateway.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
134134

135135
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
136136
if _, err := s.EC2Client.AttachInternetGateway(&ec2.AttachInternetGatewayInput{
@@ -145,7 +145,7 @@ func (s *Service) createInternetGateway() (*ec2.InternetGateway, error) {
145145
return nil, errors.Wrapf(err, "failed to attach internet gateway %q to vpc %q", *ig.InternetGateway.InternetGatewayId, s.scope.VPC().ID)
146146
}
147147
record.Eventf(s.scope.InfraCluster(), "SuccessfulAttachInternetGateway", "Internet Gateway %q attached to VPC %q", *ig.InternetGateway.InternetGatewayId, s.scope.VPC().ID)
148-
s.scope.Info("attached internet gateway to VPC", "internet-gateway-id", *ig.InternetGateway.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
148+
s.scope.V(2).Info("attached internet gateway to VPC", "internet-gateway-id", *ig.InternetGateway.InternetGatewayId, "vpc-id", s.scope.VPC().ID)
149149

150150
return ig.InternetGateway, nil
151151
}

pkg/cloud/services/network/natgateways.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (s *Service) createNatGateway(subnetID, ip string) (*ec2.NatGateway, error)
261261
return nil, errors.Wrapf(err, "failed to wait for nat gateway %q in subnet %q", *out.NatGateway.NatGatewayId, subnetID)
262262
}
263263

264-
s.scope.Info("NAT gateway for subnet is now available", "nat-gateway-id", *out.NatGateway.NatGatewayId, "subnet-id", subnetID)
264+
s.scope.Info("Created NAT gateway for subnet", "nat-gateway-id", *out.NatGateway.NatGatewayId, "subnet-id", subnetID)
265265
return out.NatGateway, nil
266266
}
267267

pkg/cloud/services/network/routetables.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (s *Service) deleteRouteTables() error {
192192
}
193193

194194
record.Eventf(s.scope.InfraCluster(), "SuccessfulDisassociateRouteTable", "Disassociated managed RouteTable %q from subnet %q", *rt.RouteTableId, *as.SubnetId)
195-
s.scope.Info("Deleted association between route table and subnet", "route-table-id", *rt.RouteTableId, "subnet-id", *as.SubnetId)
195+
s.scope.V(2).Info("Deleted association between route table and subnet", "route-table-id", *rt.RouteTableId, "subnet-id", *as.SubnetId)
196196
}
197197

198198
if _, err := s.EC2Client.DeleteRouteTable(&ec2.DeleteRouteTableInput{RouteTableId: rt.RouteTableId}); err != nil {
@@ -237,6 +237,7 @@ func (s *Service) createRouteTableWithRoutes(routes []*ec2.Route, isPublic bool,
237237
return nil, errors.Wrapf(err, "failed to create route table in vpc %q", s.scope.VPC().ID)
238238
}
239239
record.Eventf(s.scope.InfraCluster(), "SuccessfulCreateRouteTable", "Created managed RouteTable %q", *out.RouteTable.RouteTableId)
240+
s.scope.Info("Created route table", "route-table-id", *out.RouteTable.RouteTableId)
240241

241242
for i := range routes {
242243
route := routes[i]

pkg/cloud/services/network/subnets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ func (s *Service) createSubnet(sn *infrav1.SubnetSpec) (*infrav1.SubnetSpec, err
357357
return nil, errors.Wrap(err, "failed to create subnet")
358358
}
359359

360-
s.scope.Info("created subnet", "id", *out.Subnet.SubnetId, "public", sn.IsPublic, "az", sn.AvailabilityZone, "cidr", sn.CidrBlock)
361360
record.Eventf(s.scope.InfraCluster(), "SuccessfulCreateSubnet", "Created new managed Subnet %q", *out.Subnet.SubnetId)
361+
s.scope.Info("Created subnet", "id", *out.Subnet.SubnetId, "public", sn.IsPublic, "az", sn.AvailabilityZone, "cidr", sn.CidrBlock)
362362

363363
wReq := &ec2.DescribeSubnetsInput{SubnetIds: []*string{out.Subnet.SubnetId}}
364364
if err := s.EC2Client.WaitUntilSubnetAvailable(wReq); err != nil {
@@ -408,7 +408,7 @@ func (s *Service) deleteSubnet(id string) error {
408408
return errors.Wrapf(err, "failed to delete subnet %q", id)
409409
}
410410

411-
s.scope.V(2).Info("Deleted subnet in vpc", "subnet-id", id, "vpc-id", s.scope.VPC().ID)
411+
s.scope.Info("Deleted subnet", "subnet-id", id, "vpc-id", s.scope.VPC().ID)
412412
record.Eventf(s.scope.InfraCluster(), "SuccessfulDeleteSubnet", "Deleted managed Subnet %q", id)
413413
return nil
414414
}

pkg/cloud/services/network/vpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (s *Service) reconcileVPC() error {
8787
if err != nil {
8888
return errors.Wrap(err, "failed to create new vpc")
8989
}
90+
s.scope.Info("Created VPC", "vpc-id", vpc.ID)
9091

9192
s.scope.VPC().CidrBlock = vpc.CidrBlock
9293
s.scope.VPC().Tags = vpc.Tags
@@ -220,7 +221,7 @@ func (s *Service) deleteVPC() error {
220221
return errors.Wrapf(err, "failed to delete vpc %q", vpc.ID)
221222
}
222223

223-
s.scope.V(2).Info("Deleted VPC", "vpc-id", vpc.ID)
224+
s.scope.Info("Deleted VPC", "vpc-id", vpc.ID)
224225
record.Eventf(s.scope.InfraCluster(), "SuccessfulDeleteVPC", "Deleted managed VPC %q", vpc.ID)
225226
return nil
226227
}

pkg/cloud/services/securitygroup/securitygroups.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ func (s *Service) ReconcileSecurityGroups() error {
108108
ID: *sg.GroupId,
109109
Name: *sg.GroupName,
110110
}
111-
s.scope.V(2).Info("Created security group for role", "role", role, "security-group", s.scope.SecurityGroups()[role])
112111
continue
113112
}
114113

@@ -304,7 +303,7 @@ func (s *Service) deleteSecurityGroup(sg *infrav1.SecurityGroup, typ string) err
304303
}
305304

306305
record.Eventf(s.scope.InfraCluster(), "SuccessfulDeleteSecurityGroup", "Deleted %s SecurityGroup %q", typ, sg.ID)
307-
s.scope.V(2).Info("Deleted security group", "security-group-id", sg.ID, "kind", typ)
306+
s.scope.Info("Deleted security group", "security-group-id", sg.ID, "kind", typ)
308307

309308
return nil
310309
}
@@ -379,6 +378,7 @@ func (s *Service) createSecurityGroup(role infrav1.SecurityGroupRole, input *ec2
379378
}
380379

381380
record.Eventf(s.scope.InfraCluster(), "SuccessfulCreateSecurityGroup", "Created managed SecurityGroup %q for Role %q", aws.StringValue(out.GroupId), role)
381+
s.scope.Info("Created security group for role", "security-group", aws.StringValue(out.GroupId), "role", role)
382382

383383
// Set the group id.
384384
input.GroupId = out.GroupId

0 commit comments

Comments
 (0)