Skip to content

Commit

Permalink
feat: refactor proxy to include better logging & send notification if…
Browse files Browse the repository at this point in the history
… iteration is already maxed

Signed-off-by: Zufar Dhiyaullhaq <[email protected]>
  • Loading branch information
zufardhiyaulhaq committed Sep 29, 2024
1 parent 3fff999 commit 5e86290
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions services/upgrader/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ func (upgrader *ProxyUpgrader) Upgrade(ctx context.Context) error {

err := upgrader.NotificationService.Send(ctx, notification)
if err != nil {
log.Println("failed to send 1 day upgrade notification")
return err
}
}

if currentDate == upgradeConfig.RolloutRestartDate || currentDate.After(upgradeConfig.RolloutRestartDate) && upgradeConfig.Iteration <= upgrader.Settings.MaximumIteration {
upgradedDeployments, err := upgrader.calculatedUpgradedIstioDeployments(ctx, upgradeConfig)
if err != nil {
log.Println("failed to calculated upgraded istio deployments")
return err
}

upgradedStatefulSets, err := upgrader.calculatedUpgradedIstioStatefulSets(ctx, upgradeConfig)
if err != nil {
log.Println("failed to calculated upgraded istio statefulsets")
return err
}

Expand All @@ -119,6 +122,7 @@ func (upgrader *ProxyUpgrader) Upgrade(ctx context.Context) error {

err = upgrader.NotificationService.Send(ctx, preUpgradeNotification)
if err != nil {
log.Println("failed to send upgrade notification")
return err
}

Expand All @@ -133,6 +137,7 @@ func (upgrader *ProxyUpgrader) Upgrade(ctx context.Context) error {

err = upgrader.NotificationService.Send(ctx, postUpgradeNotification)
if err != nil {
log.Println("failed to send post upgrade notification")
return err
}

Expand All @@ -141,6 +146,39 @@ func (upgrader *ProxyUpgrader) Upgrade(ctx context.Context) error {
log.Println("failed to increase the iteration: ", err)
return err
}
} else {
if currentDate.Before(upgradeConfig.RolloutRestartDate) {
log.Println("skip rollout restart since it's before the rollout restart date")
}

if upgradeConfig.Iteration > upgrader.Settings.MaximumIteration {
log.Println("skip rollout restart since iteration is already more than maximum iteration configured")

upgradedDeployments, err := upgrader.calculatedUpgradedIstioDeployments(ctx, upgradeConfig)
if err != nil {
log.Println("failed to calculated upgraded istio deployments")
return err
}

upgradedStatefulSets, err := upgrader.calculatedUpgradedIstioStatefulSets(ctx, upgradeConfig)
if err != nil {
log.Println("failed to calculated upgraded istio statefulsets")
return err
}

if len(upgradedDeployments)+len(upgradedStatefulSets) > 0 {
iterationBreachUpgradeNotification := types.Notification{
Title: fmt.Sprintf("[Upgrade Notification] Cluster %s Istio service mesh still have old version of istio!\n", upgradeConfig.ClusterName),
Message: fmt.Sprintf("%d of deployments and %d of statefulsets across namespaces still use old version and cannot be upgraded because already breach the maximum iteration!", len(upgradedDeployments), len(upgradedStatefulSets)),
}

err = upgrader.NotificationService.Send(ctx, iterationBreachUpgradeNotification)
if err != nil {
log.Println("failed to send iteration breach upgrade notification")
return err
}
}
}
}

return nil
Expand Down

0 comments on commit 5e86290

Please sign in to comment.