Skip to content

Commit

Permalink
fix: enhance the log messages of Gcp Nfs Volume/Backup/Restore (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
abalaie authored Feb 11, 2025
1 parent 277f5e4 commit 8db3748
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 33 deletions.
8 changes: 4 additions & 4 deletions pkg/kcp/provider/gcp/client/serviceUsageClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s serviceUsageClient) GetServiceUsageOperation(ctx context.Context, operat
operation, err := s.svcServiceUsage.Operations.Get(operationName).Do()
IncrementCallCounter("ServiceUsage", "Operations.Get", "", err)
if err != nil {
logger.V(4).Info("GetOperation", "err", err)
logger.Info("GetOperation", "err", err)
return nil, err
}
return operation, err
Expand All @@ -58,7 +58,7 @@ func (s serviceUsageClient) EnableService(ctx context.Context, projectId string,
operation, err := s.svcServiceUsage.Services.Enable(completeServiceName, enableServiceRequest).Do()
IncrementCallCounter("ServiceUsage", "Services.Enable", "", err)
if err != nil {
logger.V(4).Info("EnableService", "err", err)
logger.Info("EnableService", "err", err)
}
return operation, err
}
Expand All @@ -70,7 +70,7 @@ func (s serviceUsageClient) DisableService(ctx context.Context, projectId string
operation, err := s.svcServiceUsage.Services.Disable(completeServiceName, disableServiceRequest).Do()
IncrementCallCounter("ServiceUsage", "Services.Disable", "", err)
if err != nil {
logger.V(4).Info("DisableService", "err", err)
logger.Info("DisableService", "err", err)
}
return operation, err
}
Expand All @@ -81,7 +81,7 @@ func (s serviceUsageClient) IsServiceEnabled(ctx context.Context, projectId stri
service, err := s.svcServiceUsage.Services.Get(completeServiceName).Do()
IncrementCallCounter("ServiceUsage", "Services.Get", "", err)
if err != nil {
logger.V(4).Info("isServiceEnabled", "err", err)
logger.Info("isServiceEnabled", "err", err)
return false, err
}
return service.State == "ENABLED", nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/kcp/provider/gcp/iprange/client/computeClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *computeClient) GetIpRange(ctx context.Context, projectId, name string)
out, err := c.svcCompute.GlobalAddresses.Get(projectId, name).Do()
client.IncrementCallCounter("Compute", "GlobalAddresses.Get", "", err)
if err != nil {
logger.V(4).Info("GetIpRange", "err", err)
logger.Info("GetIpRange", "err", err)
}
return out, err
}
Expand All @@ -56,7 +56,7 @@ func (c *computeClient) DeleteIpRange(ctx context.Context, projectId, name strin
logger := composed.LoggerFromCtx(ctx)
operation, err := c.svcCompute.GlobalAddresses.Delete(projectId, name).Do()
client.IncrementCallCounter("Compute", "GlobalAddresses.Delete", "", err)
logger.V(4).Info("DeleteIpRange", "operation", operation, "err", err)
logger.Info("DeleteIpRange", "operation", operation, "err", err)
return operation, err
}

Expand All @@ -72,7 +72,7 @@ func (c *computeClient) CreatePscIpRange(ctx context.Context, projectId, vpcName
Purpose: string(client.IpRangePurposeVPCPeering),
}).Do()
client.IncrementCallCounter("Compute", "GlobalAddresses.Insert", "", err)
logger.V(4).Info("CreatePscIpRange", "operation", operation, "err", err)
logger.Info("CreatePscIpRange", "operation", operation, "err", err)
return operation, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *serviceNetworkingClient) PatchServiceConnection(ctx context.Context, pr
ReservedPeeringRanges: reservedIpRanges,
}).Force(true).Do()
client.IncrementCallCounter("ServiceNetworking", "Services.Connections.Patch", "", err)
logger.V(4).Info("PatchServiceConnection", "operation", operation, "err", err)
logger.Info("PatchServiceConnection", "operation", operation, "err", err)
return operation, err
}

Expand All @@ -75,7 +75,7 @@ func (c *serviceNetworkingClient) DeleteServiceConnection(ctx context.Context, p
ConsumerNetwork: network,
}).Do()
client.IncrementCallCounter("ServiceNetworking", "Services.Connections.DeleteConnection", "", err)
logger.V(4).Info("DeleteServiceConnection", "operation", operation, "err", err)
logger.Info("DeleteServiceConnection", "operation", operation, "err", err)
return operation, err
}

Expand All @@ -99,7 +99,7 @@ func (c *serviceNetworkingClient) CreateServiceConnection(ctx context.Context, p
ReservedPeeringRanges: reservedIpRanges,
}).Do()
client.IncrementCallCounter("ServiceNetworking", "Services.Connections.Create", "", err)
logger.V(4).Info("CreateServiceConnection", "operation", operation, "err", err)
logger.Info("CreateServiceConnection", "operation", operation, "err", err)
return operation, err
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C
ipRange.Status.OpIdentifier = ""
}
}

logger.Error(err, "Error getting Service Networking Operation from GCP")
return composed.PatchStatus(ipRange).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -48,7 +48,6 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error getting Service Networking Operation from GCP.").
Run(ctx, state)
}

Expand Down Expand Up @@ -80,6 +79,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C
project := state.Scope().Spec.Scope.Gcp.Project
op, err := state.computeClient.GetGlobalOperation(ctx, project, opName)
if err != nil {
logger.Error(err, "Error getting Compute Operation from GCP.")
return composed.PatchStatus(ipRange).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -88,7 +88,6 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error getting Compute Operation from GCP.").
Run(ctx, state)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/kcp/provider/gcp/iprange/v2/identifyPeeringIpRanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v2

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand Down Expand Up @@ -40,6 +39,7 @@ func identifyPeeringIpRanges(ctx context.Context, st composed.State) (error, con

list, err := state.computeClient.ListGlobalAddresses(ctx, project, vpc)
if err != nil {
logger.Error(err, "Error listing Global Addresses from GCP.")
return composed.PatchStatus(ipRange).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -48,7 +48,6 @@ func identifyPeeringIpRanges(ctx context.Context, st composed.State) (error, con
Message: "Error listing Global Addresses from GCP",
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error listing Global Addresses from GCP").
Run(ctx, state)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/kcp/provider/gcp/iprange/v2/loadPsaConnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v2

import (
"context"

"github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -30,6 +29,7 @@ func loadPsaConnection(ctx context.Context, st composed.State) (error, context.C
vpc := gcpScope.VpcNetwork
list, err := state.serviceNetworkingClient.ListServiceConnections(ctx, project, vpc)
if err != nil {
logger.Error(err, "Error listing Service Connections from GCP.")
return composed.PatchStatus(ipRange).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -38,7 +38,6 @@ func loadPsaConnection(ctx context.Context, st composed.State) (error, context.C
Message: "Error listing Service Connections from GCP",
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error listing Service Connections from GCP").
Run(ctx, state)
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package v2

import (
"context"
"fmt"

"github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client"
gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -41,6 +39,7 @@ func syncPsaConnection(ctx context.Context, st composed.State) (error, context.C
}

if err != nil {
logger.Error(err, "Error creating/deleting/patching Service Connection object in GCP")
return composed.PatchStatus(ipRange).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -49,7 +48,6 @@ func syncPsaConnection(ctx context.Context, st composed.State) (error, context.C
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)).
SuccessLogMsg(fmt.Sprintf("Error creating/deleting Service Connection object in GCP :%s", err)).
Run(ctx, state)
}
if operation != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/kcp/provider/gcp/nfsbackup/client/fileBackupClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (c *fileBackupClient) GetFileBackup(ctx context.Context, projectId, locatio
out, err := c.svcFile.Projects.Locations.Backups.Get(client.GetFileBackupPath(projectId, location, name)).Do()
client.IncrementCallCounter("File", "Backups.Get", location, err)
if err != nil {
logger.V(4).Info("GetFileBackup", "err", err)
logger.Info("GetFileBackup", "err", err)
return nil, err
}
return out, err
}
Expand All @@ -69,7 +70,7 @@ func (c *fileBackupClient) ListFilesBackups(ctx context.Context, projectId, filt
out, err := c.svcFile.Projects.Locations.Backups.List(client.GetFilestoreParentPath(projectId, "-")).Filter(filter).Do()
client.IncrementCallCounter("File", "Backups.List", "-", err)
if err != nil {
logger.V(4).Info("ListFilesBackups", "err", err)
logger.Info("ListFilesBackups", "err", err)
return nil, err
}
return out.Backups, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C
}
}

logger.Error(err, "Error getting File Operation from GCP.")
return composed.UpdateStatus(nfsInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -46,7 +47,6 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error getting File Operation from GCP.").
Run(ctx, state)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/kcp/provider/gcp/nfsinstance/client/filestoreClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (c *filestoreClient) GetFilestoreInstance(ctx context.Context, projectId, l
out, err := c.svcFilestore.Projects.Locations.Instances.Get(client.GetFilestoreInstancePath(projectId, location, instanceId)).Do()
client.IncrementCallCounter("File", "Instances.Get", location, err)
if err != nil {
logger.V(4).Info("GetFilestoreInstance", "err", err)
logger.Info("GetFilestoreInstance", "err", err)
return nil, err
}
return out, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kcp/provider/gcp/nfsinstance/loadNfsInstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func loadNfsInstance(ctx context.Context, st composed.State) (error, context.Con
return nil, nil
}
}
logger.Error(err, "Error getting Filestore Instance from GCP.")
return composed.UpdateStatus(nfsInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -44,7 +45,6 @@ func loadNfsInstance(ctx context.Context, st composed.State) (error, context.Con
Message: "Error getting Filestore Instance from GCP",
}).
SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)).
SuccessLogMsg("Error getting Filestore Instance from GCP").
Run(ctx, state)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/skr/backupschedule/loadBackups.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func loadBackups(ctx context.Context, st composed.State) (error, context.Context
)

if err != nil {
logger.Error(err, "Error listing backups.")
return composed.PatchStatus(schedule).
SetExclusiveConditions(metav1.Condition{
Type: cloudresourcesv1beta1.ConditionTypeError,
Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/backupschedule/loadSource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func loadSource(ctx context.Context, st composed.State) (error, context.Context)
sourceRef, err := getSourceRef(ctx, state)
if err != nil {
schedule.SetState(cloudresourcesv1beta1.StateError)
logger.Error(err, "Error getting SourceRef")
return composed.PatchStatus(schedule).
SetExclusiveConditions(metav1.Condition{
Type: cloudresourcesv1beta1.ConditionTypeError,
Expand All @@ -34,7 +35,6 @@ func loadSource(ctx context.Context, st composed.State) (error, context.Context)
Message: "Error loading SourceRef",
}).
SuccessError(composed.StopWithRequeueDelay(util.Timing.T10000ms())).
SuccessLogMsg("Error getting SourceRef").
Run(ctx, state)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/backupschedule/validateSchedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func validateSchedule(ctx context.Context, st composed.State) (error, context.Co
expr, err := cronexpr.Parse(sch)

if err != nil {
logger.Info("Invalid cron expression")
logger.Error(err, "Invalid cron expression")

schedule.SetState(cloudresourcesv1beta1.JobStateError)
return composed.PatchStatus(schedule).
Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/gcpnfsvolumebackup/checkBackupOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func checkBackupOperation(ctx context.Context, st composed.State) (error, contex
}
}
backup.Status.State = v1beta1.GcpNfsBackupError
logger.Error(err, "Error getting Filestore backup Operation from GCP.")
return composed.PatchStatus(backup).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -47,7 +48,6 @@ func checkBackupOperation(ctx context.Context, st composed.State) (error, contex
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error getting Filestore backup Operation from GCP.").
Run(ctx, state)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/skr/gcpnfsvolumebackup/createNfsBackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func createNfsBackup(ctx context.Context, st composed.State) (error, context.Con
if backup.Status.Id == "" {
location, err := getLocation(state, logger)
if err != nil {
logger.Error(err, "Error in automatically populating the location for the backup.")
return composed.PatchStatus(backup).
SetExclusiveConditions(metav1.Condition{
Type: cloudresourcesv1beta1.ConditionTypeError,
Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co
err := state.SkrCluster.K8sClient().Get(ctx, nfsVolumeKey, nfsVolume)
if err != nil {
backup.Status.State = cloudresourcesv1beta1.GcpNfsBackupError
logger.Error(err, "Error getting GcpNfsVolume.")
return composed.PatchStatus(backup).
SetExclusiveConditions(metav1.Condition{
Type: cloudresourcesv1beta1.ConditionTypeError,
Expand All @@ -42,7 +43,6 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co
Message: "Error loading GcpNfsVolume",
}).
SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)).
SuccessLogMsg("Error getting GcpNfsVolume").
Run(ctx, state)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/gcpnfsvolumerestore/checkRestoreOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func checkRestoreOperation(ctx context.Context, st composed.State) (error, conte
}
}
restore.Status.State = v1beta1.JobStateError
logger.Error(err, "Error getting Filestore restore Operation from GCP.")
return composed.PatchStatus(restore).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -48,7 +49,6 @@ func checkRestoreOperation(ctx context.Context, st composed.State) (error, conte
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeue).
SuccessLogMsg("Error getting Filestore restore Operation from GCP.").
Run(ctx, state)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/gcpnfsvolumerestore/findRestoreOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func findRestoreOperation(ctx context.Context, st composed.State) (error, contex
return nil, nil
}
restore.Status.State = v1beta1.JobStateError
logger.Error(err, "Error listing operations from GCP.")
return composed.PatchStatus(restore).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Expand All @@ -48,7 +49,6 @@ func findRestoreOperation(ctx context.Context, st composed.State) (error, contex
Message: err.Error(),
}).
SuccessError(composed.StopWithRequeueDelay(util.Timing.T100ms())).
SuccessLogMsg("Error listing operations from GCP.").
Run(ctx, state)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co
}
if err != nil {
restore.Status.State = cloudresourcesv1beta1.JobStateError
logger.Error(err, "Error getting GcpNfsVolume")
return composed.PatchStatus(restore).
SetExclusiveConditions(metav1.Condition{
Type: cloudresourcesv1beta1.ConditionTypeError,
Expand All @@ -36,7 +37,6 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co
Message: "Error loading GcpNfsVolume",
}).
SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)).
SuccessLogMsg("Error getting GcpNfsVolume").
Run(ctx, state)
}
//If deleting, we still need the gcpNfsVolume object for finding the restore operation if it exists.
Expand Down
2 changes: 1 addition & 1 deletion pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func loadGcpNfsVolumeBackup(ctx context.Context, st composed.State) (error, cont
}
if err != nil {
restore.Status.State = cloudresourcesv1beta1.JobStateError
logger.Error(err, "Error getting GcpNfsVolumeBackup")
return composed.PatchStatus(restore).
SetExclusiveConditions(metav1.Condition{
Type: cloudresourcesv1beta1.ConditionTypeError,
Expand All @@ -46,7 +47,6 @@ func loadGcpNfsVolumeBackup(ctx context.Context, st composed.State) (error, cont
Message: "Error loading GcpNfsVolumeBackup",
}).
SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)).
SuccessLogMsg("Error getting GcpNfsVolumeBackup").
Run(ctx, state)
}

Expand Down

0 comments on commit 8db3748

Please sign in to comment.