Skip to content

Commit

Permalink
remove waitForReplica
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Feb 7, 2024
1 parent 900735e commit f82c138
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
3 changes: 1 addition & 2 deletions mgradm/cmd/upgrade/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ func upgradeKubernetes(

//shared_kubernetes.WaitForDeployment(flags.Helm.Uyuni.Namespace, "uyuni", "uyuni")

cnx.WaitForServer()

shared_kubernetes.ReplicasTo(1)

return nil
}
63 changes: 31 additions & 32 deletions shared/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,40 +120,41 @@ func ReplicasTo(replica uint) error {
if err != nil {
return fmt.Errorf("Cannot run kubectl %s: %s", args, err)
}

err = waitForReplica(replica)
if err != nil {
return fmt.Errorf("Replica to %d failed: %s", replica, err)
}
//FIXME
//err = waitForReplica(replica)
//if err != nil {
// return fmt.Errorf("Replica to %d failed: %s", replica, err)
//}

return err
}

func waitForReplica(replica uint) error {
waitSeconds := 120

log.Debug().Msgf("Checking status for replica to %d. Waiting %d seconds", replica, waitSeconds)
args := []string{"get", "deployment", "uyuni", "-o=jsonpath={.status.availableReplicas"}

var err error

for i := 0; i < waitSeconds; i++ {
out, err := utils.RunCmdOutput(zerolog.DebugLevel, "kubectl", args...)
if err != nil {
return fmt.Errorf("Cannot execute %s: %s", strings.Join(args, string(" ")), err)
}
if string(out) == string(replica)+"\n" {
log.Debug().Msgf("Replica terminated. Now value is ", replica)
break
}
log.Debug().Msgf("Replica still %s, waiting to be %d", string(out), replica)
time.Sleep(1 * time.Second)
}
if err != nil {
return fmt.Errorf("Replica to %d did not finished in %d seconds", replica, waitSeconds)
}
return nil
}
//FIXME
//func waitForReplica(replica uint) error {
// waitSeconds := 120
//
// log.Debug().Msgf("Checking status for replica to %d. Waiting %d seconds", replica, waitSeconds)
// args := []string{"get", "deployment", "uyuni", "-o=jsonpath={.status.availableReplicas}"}
//
// var err error
//
// for i := 0; i < waitSeconds; i++ {
// out, err := utils.RunCmdOutput(zerolog.DebugLevel, "kubectl", args...)
// if err != nil {
// return fmt.Errorf("Cannot execute %s: %s", strings.Join(args, string(" ")), err)
// }
// if string(out) == string(replica)+"\n" {
// log.Debug().Msgf("Replica terminated. Now value is ", replica)
// break
// }
// log.Debug().Msgf("Replica still %s, waiting to be %d", string(out), replica)
// time.Sleep(1 * time.Second)
// }
// if err != nil {
// return fmt.Errorf("Replica to %d did not finished in %d seconds", replica, waitSeconds)
// }
// return nil
//}

func addNamespace(args []string, namespace string) []string {
if namespace != "" {
Expand Down Expand Up @@ -204,8 +205,6 @@ func deletePod(podname string) (string, error) {
if err != nil {
return "", fmt.Errorf("Cannot delete pod %s: %s", podname, err)
}
//FIXME probably we should wait delete is completed
time.Sleep(10 * time.Second)
return string(out), nil
}

Expand Down

0 comments on commit f82c138

Please sign in to comment.