in custom-targets/infrastructure-manager/im-deployer/inframanager.go [40:72]
func pollDeploymentUntilTerminal(ctx context.Context, client *config.Client, deploymentName string, latestRevision string) (*configpb.Deployment, error) {
attempts := 0
dep, err := retry.DoWithData(
func() (*configpb.Deployment, error) {
attempts++
dep, err := getDeployment(ctx, client, deploymentName)
if err != nil {
return nil, err
}
if dep.LatestRevision != latestRevision {
return nil, fmt.Errorf("latest revision changed from %s to %s", latestRevision, dep.LatestRevision)
}
state := dep.State
fmt.Printf("Deployment %s state is %s\n", deploymentName, state.String())
if isSucceededDeployment(state) || isFailedDeployment(state) {
return dep, nil
} else if isInProgressDeployment(state) {
return nil, errors.New("deployment still in progress")
}
return nil, fmt.Errorf("unknown deployment state %s", state)
},
// Keep retrying only if Deployment was retrieved and is still in progress.
retry.RetryIf(func(err error) bool {
return err.Error() == "deployment still in progress"
}),
retry.Attempts(20),
retry.Delay(30*time.Second),
)
if err != nil {
return nil, fmt.Errorf("error polling deployment until terminal state after %d attempts: %v", attempts, err)
}
return dep, nil
}