Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
IMG ?= fluxcd/kustomize-controller:latest
# Produce CRDs that work back to Kubernetes 1.16
CRD_OPTIONS ?= crd:crdVersions=v1
SOURCE_VER ?= v0.1.0
SOURCE_VER ?= v0.1.1

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
4 changes: 2 additions & 2 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ resources:
- ../crd
- ../rbac
- ../manager
- github.com/fluxcd/source-controller/config//crd?ref=v0.1.0
- github.com/fluxcd/source-controller/config//manager?ref=v0.1.0
- github.com/fluxcd/source-controller/config//crd?ref=v0.1.1
- github.com/fluxcd/source-controller/config//manager?ref=v0.1.1
- namespace.yaml
31 changes: 26 additions & 5 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
kuberecorder "k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -148,19 +149,33 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
// resolve source reference
source, err := r.getSource(ctx, kustomization)
if err != nil {
return ctrl.Result{}, err
if apierrors.IsNotFound(err) {
msg := "Source not found"
kustomization = kustomizev1.KustomizationNotReady(kustomization, "", kustomizev1.ArtifactFailedReason, msg)
if err := r.Status().Update(ctx, &kustomization); err != nil {
log.Error(err, "unable to update status")
return ctrl.Result{Requeue: true}, err
}
r.recordReadiness(kustomization, false)
log.Info(msg)
// do not requeue, when the source is created the watcher should trigger a reconciliation
return ctrl.Result{}, nil
} else {
// retry on transient errors
return ctrl.Result{Requeue: true}, err
}
}

// check source readiness
if source.GetArtifact() == nil {
msg := "Source is not ready"
msg := "Source is not ready, artifact not found"
kustomization = kustomizev1.KustomizationNotReady(kustomization, "", kustomizev1.ArtifactFailedReason, msg)
if err := r.Status().Update(ctx, &kustomization); err != nil {
log.Error(err, "unable to update status")
return ctrl.Result{Requeue: true}, err
}
r.recordReadiness(kustomization, false)
log.Info(msg)
// do not requeue, when the artifact is created the watcher should trigger a reconciliation
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -397,14 +412,20 @@ func (r *KustomizationReconciler) getSource(ctx context.Context, kustomization k
var repository sourcev1.GitRepository
err := r.Client.Get(ctx, namespacedName, &repository)
if err != nil {
return source, fmt.Errorf("source '%s' not found: %w", namespacedName, err)
if apierrors.IsNotFound(err) {
return source, err
}
return source, fmt.Errorf("unable to get source '%s': %w", namespacedName, err)
}
source = &repository
case sourcev1.BucketKind:
var bucket sourcev1.Bucket
err := r.Client.Get(ctx, namespacedName, &bucket)
if err != nil {
return source, fmt.Errorf("source '%s' not found: %w", namespacedName, err)
if apierrors.IsNotFound(err) {
return source, err
}
return source, fmt.Errorf("unable to get source '%s': %w", namespacedName, err)
}
source = &bucket
default:
Expand Down