Skip to content

Commit 40b4f9e

Browse files
authored
Merge pull request #141 from fluxcd/fix-source-404
Fix status reporting when the source is not found
2 parents 41796c0 + 4fc1466 commit 40b4f9e

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
IMG ?= fluxcd/kustomize-controller:latest
33
# Produce CRDs that work back to Kubernetes 1.16
44
CRD_OPTIONS ?= crd:crdVersions=v1
5-
SOURCE_VER ?= v0.1.0
5+
SOURCE_VER ?= v0.1.1
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))

config/default/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ resources:
55
- ../crd
66
- ../rbac
77
- ../manager
8-
- github.com/fluxcd/source-controller/config//crd?ref=v0.1.0
9-
- github.com/fluxcd/source-controller/config//manager?ref=v0.1.0
8+
- github.com/fluxcd/source-controller/config//crd?ref=v0.1.1
9+
- github.com/fluxcd/source-controller/config//manager?ref=v0.1.1
1010
- namespace.yaml

controllers/kustomization_controller.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/go-logr/logr"
3333
corev1 "k8s.io/api/core/v1"
34+
apierrors "k8s.io/apimachinery/pkg/api/errors"
3435
"k8s.io/apimachinery/pkg/runtime"
3536
"k8s.io/apimachinery/pkg/types"
3637
kuberecorder "k8s.io/client-go/tools/record"
@@ -148,19 +149,33 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
148149
// resolve source reference
149150
source, err := r.getSource(ctx, kustomization)
150151
if err != nil {
151-
return ctrl.Result{}, err
152+
if apierrors.IsNotFound(err) {
153+
msg := "Source not found"
154+
kustomization = kustomizev1.KustomizationNotReady(kustomization, "", kustomizev1.ArtifactFailedReason, msg)
155+
if err := r.Status().Update(ctx, &kustomization); err != nil {
156+
log.Error(err, "unable to update status")
157+
return ctrl.Result{Requeue: true}, err
158+
}
159+
r.recordReadiness(kustomization, false)
160+
log.Info(msg)
161+
// do not requeue, when the source is created the watcher should trigger a reconciliation
162+
return ctrl.Result{}, nil
163+
} else {
164+
// retry on transient errors
165+
return ctrl.Result{Requeue: true}, err
166+
}
152167
}
153168

154-
// check source readiness
155169
if source.GetArtifact() == nil {
156-
msg := "Source is not ready"
170+
msg := "Source is not ready, artifact not found"
157171
kustomization = kustomizev1.KustomizationNotReady(kustomization, "", kustomizev1.ArtifactFailedReason, msg)
158172
if err := r.Status().Update(ctx, &kustomization); err != nil {
159173
log.Error(err, "unable to update status")
160174
return ctrl.Result{Requeue: true}, err
161175
}
162176
r.recordReadiness(kustomization, false)
163177
log.Info(msg)
178+
// do not requeue, when the artifact is created the watcher should trigger a reconciliation
164179
return ctrl.Result{}, nil
165180
}
166181

@@ -397,14 +412,20 @@ func (r *KustomizationReconciler) getSource(ctx context.Context, kustomization k
397412
var repository sourcev1.GitRepository
398413
err := r.Client.Get(ctx, namespacedName, &repository)
399414
if err != nil {
400-
return source, fmt.Errorf("source '%s' not found: %w", namespacedName, err)
415+
if apierrors.IsNotFound(err) {
416+
return source, err
417+
}
418+
return source, fmt.Errorf("unable to get source '%s': %w", namespacedName, err)
401419
}
402420
source = &repository
403421
case sourcev1.BucketKind:
404422
var bucket sourcev1.Bucket
405423
err := r.Client.Get(ctx, namespacedName, &bucket)
406424
if err != nil {
407-
return source, fmt.Errorf("source '%s' not found: %w", namespacedName, err)
425+
if apierrors.IsNotFound(err) {
426+
return source, err
427+
}
428+
return source, fmt.Errorf("unable to get source '%s': %w", namespacedName, err)
408429
}
409430
source = &bucket
410431
default:

0 commit comments

Comments
 (0)