Skip to content

Commit

Permalink
Merge pull request #1029 from fluxcd/backport-1028-to-release/v1.2.x
Browse files Browse the repository at this point in the history
[release/v1.2.x] Log HTTP errors to provide faster feedback
  • Loading branch information
hiddeco authored Dec 13, 2023
2 parents 234fa65 + e8034dc commit 89d74cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/fluxcd/pkg/apis/event v0.6.0
github.com/fluxcd/pkg/apis/kustomize v1.2.0
github.com/fluxcd/pkg/apis/meta v1.2.0
github.com/fluxcd/pkg/http/fetch v0.7.0
github.com/fluxcd/pkg/http/fetch v0.8.0
github.com/fluxcd/pkg/kustomize v1.5.0
github.com/fluxcd/pkg/runtime v0.43.2
github.com/fluxcd/pkg/ssa v0.35.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/fluxcd/pkg/apis/kustomize v1.2.0 h1:vkVs+OumxaWso0jNCqdgFFfMHdh+qtZhy
github.com/fluxcd/pkg/apis/kustomize v1.2.0/go.mod h1:VF7tR/WuVFeum+HaMTHwp+eCtsHiiQlY6ihgqtAnW/M=
github.com/fluxcd/pkg/apis/meta v1.2.0 h1:O766PzGAdMdQKybSflGL8oV0+GgCNIkdsxfalRyzeO8=
github.com/fluxcd/pkg/apis/meta v1.2.0/go.mod h1:fU/Az9AoVyIxC0oI4ihG0NVMNnvrcCzdEym3wxjIQsc=
github.com/fluxcd/pkg/http/fetch v0.7.0 h1:mfp3+UE8gsELRtcv5jYAu/LjOqHXWvm/HbgxdcGlcW4=
github.com/fluxcd/pkg/http/fetch v0.7.0/go.mod h1:Us49hjAQ1br8iTPNufAgQgtReAaQZbBzNpbRY/8ryWI=
github.com/fluxcd/pkg/http/fetch v0.8.0 h1:GWiX93y6JaoS0Bm2qy0fo2OeY3xTXP8dME/Ce1iEt8A=
github.com/fluxcd/pkg/http/fetch v0.8.0/go.mod h1:Rj2b8OVDgbPzeLxt+goa9+qDJDAwC7+jNdgyXsaBglQ=
github.com/fluxcd/pkg/kustomize v1.5.0 h1:Q2kynQzF4coKlOJq/XaLM+gVmVloaInkoa+vsor6Hho=
github.com/fluxcd/pkg/kustomize v1.5.0/go.mod h1:QgFwpteTedb7oio5+yN+h+rhSgm253OIjmtoTow+a5c=
github.com/fluxcd/pkg/runtime v0.43.2 h1:xH2BvttUqJ7wS0zjuBETr2pLXG62QY6f0mdxg5UQKio=
Expand Down
21 changes: 11 additions & 10 deletions internal/controller/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ type KustomizationReconciler struct {
kuberecorder.EventRecorder
runtimeCtrl.Metrics

artifactFetcher *fetch.ArchiveFetcher
requeueDependency time.Duration
artifactFetchRetries int
requeueDependency time.Duration

StatusPoller *polling.StatusPoller
PollingOpts polling.Options
ControllerName string
Expand Down Expand Up @@ -132,12 +133,7 @@ func (r *KustomizationReconciler) SetupWithManager(ctx context.Context, mgr ctrl

r.requeueDependency = opts.DependencyRequeueInterval
r.statusManager = fmt.Sprintf("gotk-%s", r.ControllerName)
r.artifactFetcher = fetch.NewArchiveFetcher(
opts.HTTPRetry,
tar.UnlimitedUntarSize,
tar.UnlimitedUntarSize,
os.Getenv("SOURCE_CONTROLLER_LOCALHOST"),
)
r.artifactFetchRetries = opts.HTTPRetry

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

// Download artifact and extract files to the tmp dir.
err = r.artifactFetcher.Fetch(src.GetArtifact().URL, src.GetArtifact().Digest, tmpDir)
if err != nil {
if err = fetch.NewArchiveFetcherWithLogger(
r.artifactFetchRetries,
tar.UnlimitedUntarSize,
tar.UnlimitedUntarSize,
os.Getenv("SOURCE_CONTROLLER_LOCALHOST"),
ctrl.LoggerFrom(ctx),
).Fetch(src.GetArtifact().URL, src.GetArtifact().Digest, tmpDir); err != nil {
conditions.MarkFalse(obj, meta.ReadyCondition, kustomizev1.ArtifactFailedReason, err.Error())
return err
}
Expand Down

0 comments on commit 89d74cc

Please sign in to comment.