func iamRetry()

in pkg/berglas/iam_storage.go [200:221]


func iamRetry(ctx context.Context, f retry.RetryFunc) error {
	b := retry.WithMaxRetries(5, retry.NewFibonacci(250*time.Millisecond))

	return retry.Do(ctx, b, func(ctx context.Context) error {
		err := f(ctx)
		if err == nil {
			return nil
		}

		// IAM gRPC returns 10 on conflicts
		if terr, ok := grpcstatus.FromError(err); ok && terr.Code() == grpccodes.Aborted {
			return retry.RetryableError(err)
		}

		// IAM returns 412 while propagating, also retry on server errors
		if terr, ok := err.(*googleapi.Error); ok && (terr.Code == 412 || terr.Code >= 500) {
			return retry.RetryableError(err)
		}

		return err
	})
}