Skip to content

Commit

Permalink
wait add more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi committed Mar 13, 2020
1 parent 4ec9b5a commit 1e0e90e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/phases/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func CreateCluster(data *clusterData, opt *createOptions) (*v1alpha1.OnecloudClu
return nil, errors.Wrap(err, "create cluster")
}
if opt.wait {
if err := ocutil.WaitOnecloudDeploymentUpdated(data.client, oc.GetName(), oc.GetNamespace(), 30*time.Minute); err != nil {
if err := ocutil.WaitOnecloudDeploymentUpdated(data.client, oc.GetName(), oc.GetNamespace(), 30*time.Minute, nil); err != nil {
return oc, errors.Wrap(err, "wait onecloud cluster services running")
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ func updateCluster(data *clusterData, opt *updateOptions) error {
return errors.Wrap(err, "update default onecloud cluster")
}
if opt.wait {
if err := ocutil.WaitOnecloudDeploymentUpdated(data.client, oc.GetName(), oc.GetNamespace(), 5*time.Minute); err != nil {
if err := ocutil.WaitOnecloudDeploymentUpdated(data.client, oc.GetName(), oc.GetNamespace(), 30*time.Minute, nil); err != nil {
return errors.Wrap(err, "wait onecloud cluster updated")
}
rollout, err := data.kubeClient.Rollout()
Expand Down
14 changes: 11 additions & 3 deletions pkg/util/onecloud/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,15 @@ var SpecsStatus []SpecStatusPair = []SpecStatusPair{
},
}

func IsClusterUpdated(oc *onecloud.OnecloudCluster) (bool, string) {
for _, ss := range SpecsStatus {
func IsClusterUpdated(oc *onecloud.OnecloudCluster, checkStatus []SpecStatusPair) (bool, string) {
ss := make([]SpecStatusPair, len(SpecsStatus))
for idx, s := range SpecsStatus {
ss[idx] = s
}
if checkStatus != nil {
ss = append(ss, checkStatus...)
}
for _, ss := range ss {
curSpec, curStatus := ss.Getter(oc)
if updated, reason := IsDeploymentUpdated(oc.Spec.ImageRepository, oc.Spec.Version, &curSpec, &curStatus); !updated {
return false, fmt.Sprintf("%s: %s", ss.Name, reason)
Expand All @@ -134,13 +141,14 @@ func WaitOnecloudDeploymentUpdated(
name string,
namespace string,
timeout time.Duration,
ss []SpecStatusPair,
) error {
return wait.PollImmediate(10*time.Second, timeout, func() (bool, error) {
oc, err := cli.OnecloudV1alpha1().OnecloudClusters(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return false, err
}
ok, reason := IsClusterUpdated(oc)
ok, reason := IsClusterUpdated(oc, ss)
if ok {
return true, nil
}
Expand Down

0 comments on commit 1e0e90e

Please sign in to comment.