Skip to content

Commit

Permalink
Update log format while checking the state of a resource (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 authored Jun 3, 2024
1 parent 0d8b651 commit d697b15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
3 changes: 3 additions & 0 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ var (
// VPCLoadBalancerStateCreatePending is the string representing the load balancer in a queued state.
VPCLoadBalancerStateCreatePending = VPCLoadBalancerState("create_pending")

// VPCLoadBalancerStateUpdatePending is the string representing the load balancer in updating state.
VPCLoadBalancerStateUpdatePending = VPCLoadBalancerState("update_pending")

// VPCLoadBalancerStateDeletePending is the string representing the load balancer in deleting state.
VPCLoadBalancerStateDeletePending = VPCLoadBalancerState("delete_pending")
)
Expand Down
45 changes: 24 additions & 21 deletions cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func (s *PowerVSClusterScope) ReconcilePowerVSServiceInstance() (bool, error) {
return false, fmt.Errorf("failed to get PowerVS service instance with ID %s", serviceInstanceID)
}

requeue, err := s.checkServiceInstanceState(serviceInstance.State)
requeue, err := s.checkServiceInstanceState(*serviceInstance)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -716,9 +716,9 @@ func (s *PowerVSClusterScope) ReconcilePowerVSServiceInstance() (bool, error) {
// checkServiceInstanceState checks the state of a PowerVS service instance.
// If state is provisioning, true is returned indicating a requeue for reconciliation.
// In all other cases, it returns false.
func (s *PowerVSClusterScope) checkServiceInstanceState(state *string) (bool, error) {
s.V(3).Info("Checking the state of PowerVS service instance")
switch *state {
func (s *PowerVSClusterScope) checkServiceInstanceState(instance resourcecontrollerv2.ResourceInstance) (bool, error) {
s.V(3).Info("Checking the state of PowerVS service instance", "name", *instance.Name)
switch *instance.State {
case string(infrav1beta2.ServiceInstanceStateActive):
s.V(3).Info("PowerVS service instance is in active state")
return false, nil
Expand All @@ -745,7 +745,7 @@ func (s *PowerVSClusterScope) isServiceInstanceExists() (string, bool, error) {
return "", false, nil
}

requeue, err := s.checkServiceInstanceState(serviceInstance.State)
requeue, err := s.checkServiceInstanceState(*serviceInstance)
if err != nil {
return "", false, err
}
Expand Down Expand Up @@ -879,7 +879,7 @@ func (s *PowerVSClusterScope) isDHCPServerActive() (bool, error) {
return false, err
}

requeue, err := s.checkDHCPServerStatus(dhcpServer.Status)
requeue, err := s.checkDHCPServerStatus(*dhcpServer)
if err != nil {
return false, err
}
Expand All @@ -889,9 +889,9 @@ func (s *PowerVSClusterScope) isDHCPServerActive() (bool, error) {
// checkDHCPServerStatus checks the state of a DHCP server.
// If state is BUILD, true is returned indicating a requeue for reconciliation.
// In all other cases, it returns false.
func (s *PowerVSClusterScope) checkDHCPServerStatus(status *string) (bool, error) {
s.V(3).Info("Checking the status of DHCP server")
switch *status {
func (s *PowerVSClusterScope) checkDHCPServerStatus(dhcpServer models.DHCPServerDetail) (bool, error) {
s.V(3).Info("Checking the status of DHCP server", "id", *dhcpServer.ID)
switch *dhcpServer.Status {
case string(infrav1beta2.DHCPServerStateActive):
s.V(3).Info("DHCP server is in active state")
return false, nil
Expand Down Expand Up @@ -1664,7 +1664,7 @@ func (s *PowerVSClusterScope) checkTransitGateway(transitGatewayID *string) (boo
// If state is pending, true is returned indicating a requeue for reconciliation.
// In all other cases, it returns false.
func (s *PowerVSClusterScope) checkTransitGatewayStatus(tg *tgapiv1.TransitGateway) (bool, error) {
s.V(3).Info("Checking the status of transit gateway")
s.V(3).Info("Checking the status of transit gateway", "name", *tg.Name)
switch *tg.Status {
case string(infrav1beta2.TransitGatewayStateAvailable):
s.V(3).Info("Transit gateway is in available state")
Expand Down Expand Up @@ -1704,7 +1704,7 @@ func (s *PowerVSClusterScope) checkTransitGatewayConnections(id *string) (bool,
var powerVSAttached, vpcAttached bool
for _, conn := range tgConnections.Connections {
if *conn.NetworkType == string(vpcNetworkConnectionType) && *conn.NetworkID == *vpcCRN {
if requeue, err := s.checkTransitGatewayConnectionStatus(conn.Status); err != nil {
if requeue, err := s.checkTransitGatewayConnectionStatus(conn); err != nil {
return requeue, err
} else if requeue {
return requeue, nil
Expand All @@ -1713,7 +1713,7 @@ func (s *PowerVSClusterScope) checkTransitGatewayConnections(id *string) (bool,
vpcAttached = true
}
if *conn.NetworkType == string(powervsNetworkConnectionType) && *conn.NetworkID == *pvsServiceInstanceCRN {
if requeue, err := s.checkTransitGatewayConnectionStatus(conn.Status); err != nil {
if requeue, err := s.checkTransitGatewayConnectionStatus(conn); err != nil {
return requeue, err
} else if requeue {
return requeue, nil
Expand All @@ -1731,14 +1731,14 @@ func (s *PowerVSClusterScope) checkTransitGatewayConnections(id *string) (bool,
// checkTransitGatewayConnectionStatus checks the state of a transit gateway connection.
// If state is pending, true is returned indicating a requeue for reconciliation.
// In all other cases, it returns false.
func (s *PowerVSClusterScope) checkTransitGatewayConnectionStatus(status *string) (bool, error) {
s.V(3).Info("Checking the status of transit gateway connection")
switch *status {
func (s *PowerVSClusterScope) checkTransitGatewayConnectionStatus(con tgapiv1.TransitGatewayConnectionCust) (bool, error) {
s.V(3).Info("Checking the status of transit gateway connection", "name", *con.Name)
switch *con.Status {
case string(infrav1beta2.TransitGatewayConnectionStateAttached):
s.V(3).Info("Transit gateway connection is in attached state")
return false, nil
case string(infrav1beta2.TransitGatewayConnectionStateFailed):
return false, fmt.Errorf("failed to attach connection to transit gateway, current status: %s", *status)
return false, fmt.Errorf("failed to attach connection to transit gateway, current status: %s", *con.Status)
case string(infrav1beta2.TransitGatewayConnectionStatePending):
s.V(3).Info("Transit gateway connection is in pending state")
return true, nil
Expand Down Expand Up @@ -1846,7 +1846,7 @@ func (s *PowerVSClusterScope) ReconcileLoadBalancers() (bool, error) {
return false, err
}

if requeue := s.checkLoadBalancerStatus(loadBalancer.ProvisioningStatus); requeue {
if requeue := s.checkLoadBalancerStatus(*loadBalancer); requeue {
return requeue, nil
}

Expand Down Expand Up @@ -1883,14 +1883,17 @@ func (s *PowerVSClusterScope) ReconcileLoadBalancers() (bool, error) {
// checkLoadBalancerStatus checks the state of a VPC load balancer.
// If state is pending, true is returned indicating a requeue for reconciliation.
// In all other cases, it returns false.
func (s *PowerVSClusterScope) checkLoadBalancerStatus(status *string) bool {
s.V(3).Info("Checking the status of VPC load balancer")
switch *status {
func (s *PowerVSClusterScope) checkLoadBalancerStatus(lb vpcv1.LoadBalancer) bool {
s.V(3).Info("Checking the status of VPC load balancer", "name", *lb.Name)
switch *lb.ProvisioningStatus {
case string(infrav1beta2.VPCLoadBalancerStateActive):
s.V(3).Info("VPC load balancer is in active state")
case string(infrav1beta2.VPCLoadBalancerStateCreatePending):
s.V(3).Info("VPC load balancer creation is in pending state")
return true
case string(infrav1beta2.VPCLoadBalancerStateUpdatePending):
s.V(3).Info("VPC load balancer is in updating state")
return true
}
return false
}
Expand Down Expand Up @@ -2540,7 +2543,7 @@ func (s *PowerVSClusterScope) DeleteServiceInstance() (bool, error) {
return false, err
}
s.Info("PowerVS service instance successfully deleted")
return false, nil
return true, nil
}

// DeleteCOSInstance deletes COS instance.
Expand Down

0 comments on commit d697b15

Please sign in to comment.