Skip to content

Commit

Permalink
Merge pull request #3144 from pydctw/improve-logging
Browse files Browse the repository at this point in the history
Make logging for creating/deleting AWS resources consistent
  • Loading branch information
k8s-ci-robot committed Feb 4, 2022
2 parents 9151d15 + e7f34bc commit ec057ad
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion pkg/cloud/services/ec2/bastion.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *Service) ReconcileBastion() error {
}

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

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

return nil
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/cloud/services/elb/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (s *Service) deleteAPIServerELB() error {
}

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

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

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

Expand Down Expand Up @@ -539,7 +538,7 @@ func (s *Service) createClassicELB(spec *infrav1.ClassicELB) (*infrav1.ClassicEL
}
}

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

res := spec.DeepCopy()
res.DNSName = *out.DNSName
Expand Down Expand Up @@ -582,6 +581,8 @@ func (s *Service) deleteClassicELB(name string) error {
if _, err := s.ELBClient.DeleteLoadBalancer(input); err != nil {
return err
}

s.scope.Info("Deleted AWS cloud provider load balancers")
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/cloud/services/network/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *Service) deleteInternetGateways() error {
}

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

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

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

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

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

return ig.InternetGateway, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/services/network/natgateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (s *Service) createNatGateway(subnetID, ip string) (*ec2.NatGateway, error)
return nil, errors.Wrapf(err, "failed to wait for nat gateway %q in subnet %q", *out.NatGateway.NatGatewayId, subnetID)
}

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

Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/services/network/routetables.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *Service) deleteRouteTables() error {
}

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

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

for i := range routes {
route := routes[i]
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/services/network/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ func (s *Service) createSubnet(sn *infrav1.SubnetSpec) (*infrav1.SubnetSpec, err
return nil, errors.Wrap(err, "failed to create subnet")
}

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

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

s.scope.V(2).Info("Deleted subnet in vpc", "subnet-id", id, "vpc-id", s.scope.VPC().ID)
s.scope.Info("Deleted subnet", "subnet-id", id, "vpc-id", s.scope.VPC().ID)
record.Eventf(s.scope.InfraCluster(), "SuccessfulDeleteSubnet", "Deleted managed Subnet %q", id)
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/services/network/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s *Service) reconcileVPC() error {
if err != nil {
return errors.Wrap(err, "failed to create new vpc")
}
s.scope.Info("Created VPC", "vpc-id", vpc.ID)

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

s.scope.V(2).Info("Deleted VPC", "vpc-id", vpc.ID)
s.scope.Info("Deleted VPC", "vpc-id", vpc.ID)
record.Eventf(s.scope.InfraCluster(), "SuccessfulDeleteVPC", "Deleted managed VPC %q", vpc.ID)
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/services/securitygroup/securitygroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (s *Service) ReconcileSecurityGroups() error {
ID: *sg.GroupId,
Name: *sg.GroupName,
}
s.scope.V(2).Info("Created security group for role", "role", role, "security-group", s.scope.SecurityGroups()[role])
continue
}

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

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

return nil
}
Expand Down Expand Up @@ -379,6 +378,7 @@ func (s *Service) createSecurityGroup(role infrav1.SecurityGroupRole, input *ec2
}

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

// Set the group id.
input.GroupId = out.GroupId
Expand Down

0 comments on commit ec057ad

Please sign in to comment.