Allow kustomize execution to be suspended
This commit is contained in:
parent
3f50c71af4
commit
a3b8bcb310
|
|
@ -56,6 +56,8 @@ jobs:
|
|||
kubectl apply -f ./config/samples
|
||||
kubectl -n kustomize-system rollout status deploy/kustomize-controller --timeout=1m
|
||||
kubectl wait kustomizations/podinfo-dev --for=condition=ready --timeout=1m
|
||||
kubectl wait kustomizations/podinfo-staging --for=condition=ready --timeout=1m
|
||||
kubectl wait kustomizations/podinfo-production --for=condition=ready --timeout=1m
|
||||
kubectl -n dev rollout status deploy/podinfo --timeout=1m
|
||||
kubectl -n kustomize-system logs deploy/kustomize-controller
|
||||
- name: Debug failure
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ Features:
|
|||
|
||||
## Kustomization API
|
||||
|
||||
A kustomization object defines the source of Kubernetes manifests by referencing a source
|
||||
(managed by [source-controller](https://github.com/fluxcd/source-controller)),
|
||||
A kustomization object defines the source of Kubernetes manifests by referencing an object
|
||||
managed by [source-controller](https://github.com/fluxcd/source-controller),
|
||||
the path to the kustomization file,
|
||||
and a label selector used for garbage collection of resources removed from the Git source.
|
||||
|
||||
|
|
@ -44,6 +44,11 @@ type KustomizationSpec struct {
|
|||
// +required
|
||||
SourceRef corev1.TypedLocalObjectReference `json:"sourceRef"`
|
||||
|
||||
// This flag tells the controller to suspend subsequent kustomize executions,
|
||||
// it does not apply to already started executions. Defaults to false.
|
||||
// +optional
|
||||
Suspend bool `json:"suspend,omitempty"`
|
||||
|
||||
// Validate the Kubernetes objects before applying them on the cluster.
|
||||
// The validation strategy can be 'client' (local dry-run) or 'server' (APIServer dry-run).
|
||||
// +kubebuilder:validation:Enum=client;server
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ const (
|
|||
// BuildFailedReason represents the fact that the kustomize build command failed.
|
||||
BuildFailedReason string = "BuildFailed"
|
||||
|
||||
// SuspendedReason represents the fact that the kustomization execution is suspended.
|
||||
SuspendedReason string = "Suspended"
|
||||
|
||||
// ValidationFailedReason represents the fact that the dry-run apply failed.
|
||||
ValidationFailedReason string = "ValidationFailed"
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ type KustomizationSpec struct {
|
|||
// +required
|
||||
SourceRef corev1.TypedLocalObjectReference `json:"sourceRef"`
|
||||
|
||||
// This flag tells the controller to suspend subsequent kustomize executions,
|
||||
// it does not apply to already started executions. Defaults to false.
|
||||
// +optional
|
||||
Suspend bool `json:"suspend,omitempty"`
|
||||
|
||||
// Validate the Kubernetes objects before applying them on the cluster.
|
||||
// The validation strategy can be 'client' (local dry-run) or 'server' (APIServer dry-run).
|
||||
// +kubebuilder:validation:Enum=client;server
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ spec:
|
|||
- kind
|
||||
- name
|
||||
type: object
|
||||
suspend:
|
||||
description: This flag tells the controller to suspend subsequent kustomize
|
||||
executions, it does not apply to already started executions. Defaults
|
||||
to false.
|
||||
type: boolean
|
||||
validation:
|
||||
description: Validate the Kubernetes objects before applying them on
|
||||
the cluster. The validation strategy can be 'client' (local dry-run)
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ spec:
|
|||
interval: 5m
|
||||
path: "./overlays/dev/"
|
||||
prune: "env=dev"
|
||||
suspend: false
|
||||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: podinfo
|
||||
validation: client
|
||||
---
|
||||
apiVersion: kustomize.fluxcd.io/v1alpha1
|
||||
kind: Kustomization
|
||||
|
|
|
|||
|
|
@ -58,6 +58,17 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
|||
|
||||
log := r.Log.WithValues(strings.ToLower(kustomization.Kind), req.NamespacedName)
|
||||
|
||||
if kustomization.Spec.Suspend {
|
||||
msg := "Kustomization is suspended, skipping execution"
|
||||
kustomization = kustomizev1.KustomizationNotReady(kustomization, kustomizev1.SuspendedReason, msg)
|
||||
if err := r.Status().Update(ctx, &kustomization); err != nil {
|
||||
log.Error(err, "unable to update Kustomization status")
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
log.Info(msg)
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
var source sourcev1.Source
|
||||
|
||||
// get artifact source from Git repository
|
||||
|
|
|
|||
Loading…
Reference in New Issue