Skip to content

Commit

Permalink
feat: refactor proxy to include better logging
Browse files Browse the repository at this point in the history
Signed-off-by: Zufar Dhiyaullhaq <[email protected]>
  • Loading branch information
zufardhiyaulhaq committed Sep 29, 2024
1 parent 03e1360 commit 89cfc55
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions services/upgrader/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (upgrader *ProxyUpgrader) calculatedUpgradedIstioDeployments(ctx context.Co
deployments, err := upgrader.getUpgradedIstioDeployments(ctx, upgradeConfig)
if err != nil {
log.Println("failed to get upgraded istio deployment: ", err)
return upgradedDeployments, nil
return upgradedDeployments, err
}

totalDeplopymentsIteration := upgrader.getNumberOfRestartedByIteration(upgradeConfig.Iteration, len(deployments))
Expand All @@ -225,7 +225,7 @@ func (upgrader *ProxyUpgrader) calculatedUpgradedIstioStatefulSets(ctx context.C
statefulsets, err := upgrader.getUpgradedIstioStatefulSets(ctx, upgradeConfig)
if err != nil {
log.Println("failed to get upgraded istio statefulset: ", err)
return upgradedStatefulSets, nil
return upgradedStatefulSets, err
}

totalStatefulSetsIteration := upgrader.getNumberOfRestartedByIteration(upgradeConfig.Iteration, len(statefulsets))
Expand All @@ -250,7 +250,7 @@ func (upgrader *ProxyUpgrader) Restart(ctx context.Context, upgradedDeployments

for _, deployment := range upgradedDeployments {
if err := upgrader.DeploymentService.RolloutRestart(ctx, deployment.namespace, deployment.name); err != nil {
log.Printf("failed to rollout restart deployment: %s in namespace: %s reason: %s", deployment.namespace, deployment.name, err.Error())
log.Printf("failed to rollout restart deployment: %s in namespace: %s reason: %s\n", deployment.namespace, deployment.name, err.Error())
failedDeployments = append(failedDeployments, deployment)
continue
}
Expand All @@ -260,7 +260,7 @@ func (upgrader *ProxyUpgrader) Restart(ctx context.Context, upgradedDeployments

for _, statefulSet := range upgradedStatefulSets {
if err := upgrader.StatefulsetService.RolloutRestart(ctx, statefulSet.namespace, statefulSet.name); err != nil {
log.Printf("failed to rollout restart statefulSet: %s in namespace: %s reason: %s", statefulSet.namespace, statefulSet.name, err.Error())
log.Printf("failed to rollout restart statefulSet: %s in namespace: %s reason: %s\n", statefulSet.namespace, statefulSet.name, err.Error())
failedStatefulSets = append(failedStatefulSets, statefulSet)
continue
}
Expand All @@ -274,7 +274,7 @@ func (upgrader *ProxyUpgrader) Restart(ctx context.Context, upgradedDeployments
func (upgrader *ProxyUpgrader) getUpgradeConfig(ctx context.Context) (types.UpgradeProxyConfig, error) {
upgradeConfigMap, err := upgrader.ConfigMapService.Get(ctx, upgrader.Settings.StorageConfigMapNameSpace, upgrader.Settings.StorageConfigMapName)
if err != nil {
log.Printf("failed getting configmap %s on namespace %s", upgrader.Settings.StorageConfigMapNameSpace, upgrader.Settings.StorageConfigMapName)
log.Printf("failed getting configmap %s on namespace %s\n", upgrader.Settings.StorageConfigMapNameSpace, upgrader.Settings.StorageConfigMapName)
return types.UpgradeProxyConfig{}, err
}

Expand Down Expand Up @@ -340,7 +340,7 @@ func (upgrader *ProxyUpgrader) getUpgradeConfig(ctx context.Context) (types.Upgr
func (upgrader *ProxyUpgrader) increaseIteration(ctx context.Context, upgradeConfig types.UpgradeProxyConfig) error {
upgradeConfigMap, err := upgrader.ConfigMapService.Get(ctx, upgrader.Settings.StorageConfigMapNameSpace, upgrader.Settings.StorageConfigMapName)
if err != nil {
log.Printf("failed getting configmap %s on namespace %s", upgrader.Settings.StorageConfigMapNameSpace, upgrader.Settings.StorageConfigMapName)
log.Printf("failed getting configmap %s on namespace %s\n", upgrader.Settings.StorageConfigMapNameSpace, upgrader.Settings.StorageConfigMapName)
return err
}

Expand Down Expand Up @@ -398,7 +398,7 @@ func (upgrader *ProxyUpgrader) getUpgradedIstioDeployments(ctx context.Context,
for _, namespace := range namespaces {
deployments, err := upgrader.DeploymentService.FindByNamespace(ctx, namespace.Name)
if err != nil {
log.Println("failed to get deployments by namespace %s: %v", namespace.Name, err.Error())
log.Println("failed to get deployments by namespace:", namespace.Name, err.Error())
return nil, err
}

Expand All @@ -420,7 +420,7 @@ func (upgrader *ProxyUpgrader) filterDeploymentsByProxyVersion(ctx context.Conte
if *deployment.Spec.Replicas > 0 {
pods, err := upgrader.PodService.FindByNamespaceAndLabels(ctx, namespace, deployment.Spec.Selector.MatchLabels)
if err != nil {
log.Printf("failed to find pods based on namespace and labels on the deployment %s namespace %s: %v", deployment.Name, deployment.Namespace, err)
log.Printf("failed to find pods based on namespace and labels on the deployment %s namespace %s: %v\n", deployment.Name, deployment.Namespace, err)
return nil, err
}

Expand All @@ -429,7 +429,7 @@ func (upgrader *ProxyUpgrader) filterDeploymentsByProxyVersion(ctx context.Conte
if istioProxyVersion != "" {
currentProxyVersion, err := version.NewVersion(istioProxyVersion)
if err != nil {
log.Println("failed to find parse istio proxy on deployment %s namespace %s pod %s: %v", deployment.Name, deployment.Namespace, pod.Name, err.Error())
log.Println("failed to find parse istio proxy on deployment", deployment.Name, "namespace", deployment.Namespace, "pod", pod.Name, ":", err.Error())
return nil, err
}

Expand All @@ -455,7 +455,7 @@ func (upgrader *ProxyUpgrader) getUpgradedIstioStatefulSets(ctx context.Context,
for _, namespace := range namespaces {
statefulsets, err := upgrader.StatefulsetService.FindByNamespace(ctx, namespace.Name)
if err != nil {
log.Println("failed to get deployments by namespace %s: %v", namespace.Name, err.Error())
log.Printf("failed to get deployments by namespace %s: %v\n", namespace.Name, err.Error())
return nil, err
}

Expand All @@ -477,7 +477,7 @@ func (upgrader *ProxyUpgrader) filterStatefulSetsByProxyVersion(ctx context.Cont
if *statefulset.Spec.Replicas > 0 {
pods, err := upgrader.PodService.FindByNamespaceAndLabels(ctx, namespace, statefulset.Spec.Selector.MatchLabels)
if err != nil {
log.Printf("failed to find pods based on namespace and labels on the statefulset %s namespace %s: %v", statefulset.Name, statefulset.Namespace, err)
log.Printf("failed to find pods based on namespace and labels on the statefulset %s namespace %s: %v\n", statefulset.Name, statefulset.Namespace, err)
return nil, err
}

Expand All @@ -486,7 +486,7 @@ func (upgrader *ProxyUpgrader) filterStatefulSetsByProxyVersion(ctx context.Cont
if istioProxyVersion != "" {
currentProxyVersion, err := version.NewVersion(istioProxyVersion)
if err != nil {
log.Println("failed to find parse istio proxy on statefulset %s namespace %s pod %s: %v", statefulset.Name, statefulset.Namespace, pod.Name, err.Error())
log.Printf("failed to find parse istio proxy on statefulset %s namespace %s pod %s: %v\n", statefulset.Name, statefulset.Namespace, pod.Name, err.Error())
return nil, err
}

Expand Down

0 comments on commit 89cfc55

Please sign in to comment.