Skip to content

Commit

Permalink
update scalesetVMSS conditions check for restart at RP predeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeepc2792 committed Jun 14, 2023
1 parent b24b077 commit 4ff4541
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions pkg/deploy/predeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ import (
"github.com/Azure/ARO-RP/pkg/util/keyvault"
)

// Rotate the secret on every deploy of the RP if the most recent
// secret is greater than 7 days old
const rotateSecretAfter = time.Hour * 168
const (
// Rotate the secret on every deploy of the RP if the most recent
// secret is greater than 7 days old
rotateSecretAfter = time.Hour * 168
rpRestartScript = "systemctl restart aro-rp"
gatewayRestartScript = "systemctl restart aro-gateway"
)

// PreDeploy deploys managed identity, NSGs and keyvaults, needed for main
// deployment
Expand Down Expand Up @@ -393,11 +397,11 @@ func (d *deployer) configureServiceSecrets(ctx context.Context) error {
}

if isRotated {
err = d.restartOldScalesets(ctx, "systemctl restart aro-gateway", d.config.GatewayResourceGroupName)
err = d.restartOldScalesets(ctx, d.config.GatewayResourceGroupName)
if err != nil {
return err
}
err = d.restartOldScalesets(ctx, "systemctl restart aro-rp", d.config.RPResourceGroupName)
err = d.restartOldScalesets(ctx, d.config.RPResourceGroupName)
if err != nil {
return err
}
Expand Down Expand Up @@ -482,15 +486,15 @@ func (d *deployer) ensureSecretKey(ctx context.Context, kv keyvault.Manager, sec
})
}

func (d *deployer) restartOldScalesets(ctx context.Context, script string, resourceGroupName string) error {
func (d *deployer) restartOldScalesets(ctx context.Context, resourceGroupName string) error {
d.log.Print("restarting old scalesets")
scalesets, err := d.vmss.List(ctx, resourceGroupName)
if err != nil {
return err
}

for _, vmss := range scalesets {
err = d.restartOldScaleset(ctx, *vmss.Name, script, resourceGroupName)
err = d.restartOldScaleset(ctx, *vmss.Name, resourceGroupName)
if err != nil {
return err
}
Expand All @@ -499,7 +503,17 @@ func (d *deployer) restartOldScalesets(ctx context.Context, script string, resou
return nil
}

func (d *deployer) restartOldScaleset(ctx context.Context, vmssName string, script string, resourceGroupName string) error {
func (d *deployer) restartOldScaleset(ctx context.Context, vmssName string, resourceGroupName string) error {
var restartScript string
switch {
case strings.HasPrefix(vmssName, gatewayVMSSPrefix):
restartScript = gatewayRestartScript
case strings.HasPrefix(vmssName, rpVMSSPrefix):
restartScript = rpRestartScript
default:
return nil
}

scalesetVMs, err := d.vmssvms.List(ctx, resourceGroupName, vmssName, "", "", "")
if err != nil {
return err
Expand All @@ -511,7 +525,7 @@ func (d *deployer) restartOldScaleset(ctx context.Context, vmssName string, scri
go func(id string) {
errors <- d.vmssvms.RunCommandAndWait(ctx, resourceGroupName, vmssName, id, mgmtcompute.RunCommandInput{
CommandID: to.StringPtr("RunShellScript"),
Script: &[]string{script},
Script: &[]string{restartScript},
})
}(*vm.InstanceID)
}
Expand Down

0 comments on commit 4ff4541

Please sign in to comment.