Skip to content

Commit

Permalink
Merge pull request #1793 from justaugustus/backoff
Browse files Browse the repository at this point in the history
pkg/cip: Use cenkalti/backoff/v4 to remove dep on k8s.io/apimachinery
  • Loading branch information
k8s-ci-robot authored Nov 27, 2020
2 parents 9498a98 + dd3c33d commit 403156f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 84 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cloud.google.com/go/storage v1.12.0
github.com/GoogleCloudPlatform/testgrid v0.0.30
github.com/blang/semver v3.5.1+incompatible
github.com/cenkalti/backoff/v4 v4.1.0
github.com/containers/image/v5 v5.7.0
github.com/go-git/go-git/v5 v5.2.0
github.com/golang/protobuf v1.4.3
Expand Down Expand Up @@ -38,7 +39,6 @@ require (
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.3.0
k8s.io/apimachinery v0.19.2
k8s.io/klog/v2 v2.4.0
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
sigs.k8s.io/mdtoc v1.0.1
Expand Down
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bombsimon/wsl/v2 v2.0.0/go.mod h1:mf25kr/SqFEPhhcxW1+7pxzGlW+hIl/hYTKY95VwV8U=
github.com/bombsimon/wsl/v3 v3.0.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/checkpoint-restore/go-criu/v4 v4.0.2/go.mod h1:xUQBLp4RLc5zJtWY++yjOoMoB5lihDt7fai+75m+rGw=
Expand Down Expand Up @@ -190,7 +192,6 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
Expand All @@ -205,7 +206,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
Expand Down Expand Up @@ -373,7 +373,6 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.2.2/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
Expand Down Expand Up @@ -436,7 +435,6 @@ github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBv
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
Expand All @@ -460,7 +458,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
Expand Down Expand Up @@ -939,7 +936,6 @@ golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1203,8 +1199,6 @@ k8s.io/api v0.17.4/go.mod h1:5qxx6vjmwUVG2nHQTKGlLts8Tbok8PzHl4vHtVFuZCA=
k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY=
k8s.io/apimachinery v0.17.4/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
k8s.io/apimachinery v0.19.2 h1:5Gy9vQpAGTKHPVOh5c4plE274X8D/6cuEiTO2zve7tc=
k8s.io/apimachinery v0.19.2/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/apiserver v0.17.4/go.mod h1:5ZDQ6Xr5MNBxyi3iUZXS84QOhZl+W7Oq2us/29c0j9I=
k8s.io/client-go v0.17.4/go.mod h1:ouF6o5pz3is8qU0/qYL2RnoxOPqgfuidYLowytyLJmc=
k8s.io/client-go v0.18.8/go.mod h1:HqFqMllQ5NnQJNwjro9k5zMyfhZlOwpuTLVrxjkYSxU=
Expand All @@ -1214,18 +1208,15 @@ k8s.io/component-base v0.17.4/go.mod h1:5BRqHMbbQPm2kKu35v3G+CpVq4K0RJKC7TRioF0I
k8s.io/csi-translation-lib v0.17.4/go.mod h1:CsxmjwxEI0tTNMzffIAcgR9lX4wOh6AKHdxQrT7L0oo=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20190822140433-26a664648505/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ=
k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H64/qeyjQoUZhGpeFDVdxjTeEVN2o=
k8s.io/legacy-cloud-providers v0.17.4/go.mod h1:FikRNoD64ECjkxO36gkDgJeiQWwyZTuBkhu+yxOc1Js=
k8s.io/release v0.3.2-0.20200513161026-05b87eb96960/go.mod h1:fcMNfhJFSHSBFv4BSrzJV2mesdz3yJeEqsqKs8cxjGU=
k8s.io/release v0.4.2/go.mod h1:Kuj+iBm1aa/xxVyK8SVHrmxXn3g1IZUlB3ekJwx+NTw=
Expand All @@ -1252,7 +1243,6 @@ sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:w
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06/go.mod h1:/ULNhyfzRopfcjskuui0cTITekDduZ7ycKN3oUT9R18=
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
Expand Down
119 changes: 56 additions & 63 deletions pkg/cip/dockerregistry/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ import (
"sort"
"strings"
"sync"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/google/go-containerregistry/pkg/crane"
ggcrV1 "github.com/google/go-containerregistry/pkg/v1"
ggcrV1Google "github.com/google/go-containerregistry/pkg/v1/google"
ggcrV1Types "github.com/google/go-containerregistry/pkg/v1/types"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/release/pkg/cip/gcloud"
cipJson "k8s.io/release/pkg/cip/json"
Expand Down Expand Up @@ -971,31 +973,28 @@ func (riid *RegInvImageDigest) PrettyValue() string {
return b.String()
}

func getRegistryTagsWrapper(req stream.ExternalRequest,
func getRegistryTagsWrapper(
req stream.ExternalRequest,
) (*ggcrV1Google.Tags, error) {
var googleTags *ggcrV1Google.Tags

var getRegistryTagsCondition wait.ConditionFunc = func() (bool, error) {
var err error
retryFn := func() error {
var retryErr error

googleTags, err = getRegistryTagsFrom(req)
googleTags, retryErr = getRegistryTagsFrom(req)

// We never return an error (err) in the second part of our return
// argument, because we don't want to prematurely stop the
// ExponentialBackoff() loop; we want it to continue looping until
// either we get a well-formed tags value, or until it hits
// ErrWaitTimeout. This is how ExponentialBackoff() uses the
// ConditionFunc type.
if err == nil && googleTags != nil && len(googleTags.Name) > 0 {
return true, nil
}
return retryErr
}

return false, nil
b := stream.BackoffDefault()
notify := func(err error, t time.Duration) {
logrus.Errorf("error: %v happened at time: %v", err, t)
}

err := wait.ExponentialBackoff(
stream.BackoffDefault,
getRegistryTagsCondition,
err := backoff.RetryNotify(
retryFn,
b,
notify,
)
if err != nil {
klog.Error(err)
Expand Down Expand Up @@ -1028,38 +1027,28 @@ func getRegistryTagsFrom(req stream.ExternalRequest,
return tags, nil
}

func getGCRManifestListWrapper(req stream.ExternalRequest) (*ggcrV1.IndexManifest, error) {
func getGCRManifestListWrapper(
req stream.ExternalRequest,
) (*ggcrV1.IndexManifest, error) {
var gcrManifestList *ggcrV1.IndexManifest

var getGCRManifestListCondition wait.ConditionFunc = func() (bool, error) {
var err error

gcrManifestList, err = getGCRManifestListFrom(req)
retryFn := func() error {
var retryErr error

// We never return an error (err) in the second part of our return
// argument, because we don't want to prematurely stop the
// ExponentialBackoff() loop; we want it to continue looping until
// either we get a well-formed value, or until it hits
// ErrWaitTimeout. This is how ExponentialBackoff() uses the
// ConditionFunc type.
if err == nil &&
gcrManifestList != nil &&
len(gcrManifestList.Manifests) > 0 {
return true, nil
}
gcrManifestList, retryErr = getGCRManifestListFrom(req)

klog.Errorf(
"invalid gcrManifestList state: %v for request %s",
gcrManifestList,
req,
)
return retryErr
}

return false, nil
b := stream.BackoffDefault()
notify := func(err error, t time.Duration) {
logrus.Errorf("error: %v happened at time: %v", err, t)
}

err := wait.ExponentialBackoff(
stream.BackoffDefault,
getGCRManifestListCondition,
err := backoff.RetryNotify(
retryFn,
b,
notify,
)
if err != nil {
klog.Error(err)
Expand Down Expand Up @@ -1091,12 +1080,12 @@ func getGCRManifestListFrom(req stream.ExternalRequest) (*ggcrV1.IndexManifest,

func getJSONSFromProcess(req stream.ExternalRequest) (cipJson.Objects, Errors) {
var jsons cipJson.Objects
errors := make(Errors, 0)
streamErrs := make(Errors, 0)

stdoutReader, stderrReader, err := req.StreamProducer.Produce()
if err != nil {
errors = append(
errors,
streamErrs = append(
streamErrs,
Error{
Context: "running process",
Error: err,
Expand All @@ -1106,8 +1095,8 @@ func getJSONSFromProcess(req stream.ExternalRequest) (cipJson.Objects, Errors) {

jsons, err = cipJson.Consume(stdoutReader)
if err != nil {
errors = append(
errors,
streamErrs = append(
streamErrs,
Error{
Context: "parsing JSON",
Error: err,
Expand All @@ -1117,8 +1106,8 @@ func getJSONSFromProcess(req stream.ExternalRequest) (cipJson.Objects, Errors) {

be, err := ioutil.ReadAll(stderrReader)
if err != nil {
errors = append(
errors,
streamErrs = append(
streamErrs,
Error{
Context: "reading process stderr",
Error: err,
Expand All @@ -1127,8 +1116,8 @@ func getJSONSFromProcess(req stream.ExternalRequest) (cipJson.Objects, Errors) {
}

if len(be) > 0 {
errors = append(
errors,
streamErrs = append(
streamErrs,
Error{
Context: "process had stderr",
Error: fmt.Errorf("%v", string(be)),
Expand All @@ -1138,16 +1127,16 @@ func getJSONSFromProcess(req stream.ExternalRequest) (cipJson.Objects, Errors) {

err = req.StreamProducer.Close()
if err != nil {
errors = append(
errors,
streamErrs = append(
streamErrs,
Error{
Context: "closing process",
Error: err,
},
)
}

return jsons, errors
return jsons, streamErrs
}

// IgnoreFromPromotion works by building up a new Inv type of those images that
Expand Down Expand Up @@ -1316,7 +1305,9 @@ func (sc *SyncContext) ReadRegistries(
reqRes.Errors = Errors{
Error{
Context: "getRegistryTagsWrapper",
Error: err}}
Error: err,
},
}
requestResults <- reqRes

// Invalidate promotion conservatively for the subset of images
Expand Down Expand Up @@ -1432,8 +1423,8 @@ func (sc *SyncContext) ReadGCRManifestLists(
var populateRequests PopulateRequests = func(
sc *SyncContext,
reqs chan<- stream.ExternalRequest,
wg *sync.WaitGroup) {

wg *sync.WaitGroup,
) {
// Find all images that are of ggcrV1Types.MediaType == DockerManifestList; these
// images will be queried.
for registryName, rii := range sc.Inv {
Expand Down Expand Up @@ -1488,7 +1479,9 @@ func (sc *SyncContext) ReadGCRManifestLists(
reqRes.Errors = Errors{
Error{
Context: "getGCRManifestListWrapper",
Error: err}}
Error: err,
},
}
requestResults <- reqRes
continue
}
Expand Down Expand Up @@ -2033,18 +2026,18 @@ func MKPopulateRequestsForPromotionEdges(

// RunChecks runs defined PreChecks in order to check the promotion.
func (sc *SyncContext) RunChecks(preChecks []PreCheck) error {
var errors []error
var preCheckErrs []error
for _, preCheck := range preChecks {
err := preCheck.Run()
if err != nil {
klog.Error(err)
errors = append(errors, err)
preCheckErrs = append(preCheckErrs, err)
}
}

if errors != nil {
if preCheckErrs != nil {
return fmt.Errorf("%v error(s) encountered during the prechecks",
len(errors))
len(preCheckErrs))
}
return nil
}
Expand Down
23 changes: 15 additions & 8 deletions pkg/cip/stream/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"io"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"github.com/cenkalti/backoff/v4"
)

// Producer is an interface for anything that can generate an io.Reader from
Expand Down Expand Up @@ -49,11 +49,18 @@ type ExternalRequest struct {

// BackoffDefault is the default Backoff behavior for network call retries.
//
// nolint[gomnd]
var BackoffDefault = wait.Backoff{
Duration: time.Second,
Factor: 2,
Jitter: 0.1,
Steps: 45,
Cap: time.Second * 60,
// Previous values from k8s.io/apimachinery/pkg/util/wait.`Backoff`:
// - Duration: time.Second
// - Factor: 2
// - Jitter: 0.1
// - Steps: 45
// - Cap: time.Second * 60
func BackoffDefault() *backoff.ExponentialBackOff {
b := backoff.NewExponentialBackOff()
b.InitialInterval = time.Second
b.Multiplier = 2
b.RandomizationFactor = 0.1
b.MaxElapsedTime = time.Second * 60

return b
}

0 comments on commit 403156f

Please sign in to comment.