Skip to content

Commit 8deb234

Browse files
committed
Log HTTP errors to provide faster feedback
This configures a logger on the archive fetcher, to make HTTP errors surface faster when it fails to retrieve the artifact of a source. Signed-off-by: Hidde Beydals <[email protected]>
1 parent 7381014 commit 8deb234

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/fluxcd/pkg/apis/event v0.6.0
2323
github.com/fluxcd/pkg/apis/kustomize v1.2.0
2424
github.com/fluxcd/pkg/apis/meta v1.2.0
25-
github.com/fluxcd/pkg/http/fetch v0.7.0
25+
github.com/fluxcd/pkg/http/fetch v0.8.0
2626
github.com/fluxcd/pkg/kustomize v1.5.0
2727
github.com/fluxcd/pkg/runtime v0.43.2
2828
github.com/fluxcd/pkg/ssa v0.35.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ github.com/fluxcd/pkg/apis/kustomize v1.2.0 h1:vkVs+OumxaWso0jNCqdgFFfMHdh+qtZhy
142142
github.com/fluxcd/pkg/apis/kustomize v1.2.0/go.mod h1:VF7tR/WuVFeum+HaMTHwp+eCtsHiiQlY6ihgqtAnW/M=
143143
github.com/fluxcd/pkg/apis/meta v1.2.0 h1:O766PzGAdMdQKybSflGL8oV0+GgCNIkdsxfalRyzeO8=
144144
github.com/fluxcd/pkg/apis/meta v1.2.0/go.mod h1:fU/Az9AoVyIxC0oI4ihG0NVMNnvrcCzdEym3wxjIQsc=
145-
github.com/fluxcd/pkg/http/fetch v0.7.0 h1:mfp3+UE8gsELRtcv5jYAu/LjOqHXWvm/HbgxdcGlcW4=
146-
github.com/fluxcd/pkg/http/fetch v0.7.0/go.mod h1:Us49hjAQ1br8iTPNufAgQgtReAaQZbBzNpbRY/8ryWI=
145+
github.com/fluxcd/pkg/http/fetch v0.8.0 h1:GWiX93y6JaoS0Bm2qy0fo2OeY3xTXP8dME/Ce1iEt8A=
146+
github.com/fluxcd/pkg/http/fetch v0.8.0/go.mod h1:Rj2b8OVDgbPzeLxt+goa9+qDJDAwC7+jNdgyXsaBglQ=
147147
github.com/fluxcd/pkg/kustomize v1.5.0 h1:Q2kynQzF4coKlOJq/XaLM+gVmVloaInkoa+vsor6Hho=
148148
github.com/fluxcd/pkg/kustomize v1.5.0/go.mod h1:QgFwpteTedb7oio5+yN+h+rhSgm253OIjmtoTow+a5c=
149149
github.com/fluxcd/pkg/runtime v0.43.2 h1:xH2BvttUqJ7wS0zjuBETr2pLXG62QY6f0mdxg5UQKio=

internal/controller/kustomization_controller.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ type KustomizationReconciler struct {
8383
kuberecorder.EventRecorder
8484
runtimeCtrl.Metrics
8585

86-
artifactFetcher *fetch.ArchiveFetcher
87-
requeueDependency time.Duration
86+
artifactFetchRetries int
87+
requeueDependency time.Duration
88+
8889
StatusPoller *polling.StatusPoller
8990
PollingOpts polling.Options
9091
ControllerName string
@@ -132,12 +133,7 @@ func (r *KustomizationReconciler) SetupWithManager(ctx context.Context, mgr ctrl
132133

133134
r.requeueDependency = opts.DependencyRequeueInterval
134135
r.statusManager = fmt.Sprintf("gotk-%s", r.ControllerName)
135-
r.artifactFetcher = fetch.NewArchiveFetcher(
136-
opts.HTTPRetry,
137-
tar.UnlimitedUntarSize,
138-
tar.UnlimitedUntarSize,
139-
os.Getenv("SOURCE_CONTROLLER_LOCALHOST"),
140-
)
136+
r.artifactFetchRetries = opts.HTTPRetry
141137

142138
return ctrl.NewControllerManagedBy(mgr).
143139
For(&kustomizev1.Kustomization{}, builder.WithPredicates(
@@ -322,8 +318,13 @@ func (r *KustomizationReconciler) reconcile(
322318
defer os.RemoveAll(tmpDir)
323319

324320
// Download artifact and extract files to the tmp dir.
325-
err = r.artifactFetcher.Fetch(src.GetArtifact().URL, src.GetArtifact().Digest, tmpDir)
326-
if err != nil {
321+
if err = fetch.NewArchiveFetcherWithLogger(
322+
r.artifactFetchRetries,
323+
tar.UnlimitedUntarSize,
324+
tar.UnlimitedUntarSize,
325+
os.Getenv("SOURCE_CONTROLLER_LOCALHOST"),
326+
ctrl.LoggerFrom(ctx),
327+
).Fetch(src.GetArtifact().URL, src.GetArtifact().Digest, tmpDir); err != nil {
327328
conditions.MarkFalse(obj, meta.ReadyCondition, kustomizev1.ArtifactFailedReason, err.Error())
328329
return err
329330
}

0 commit comments

Comments
 (0)