Skip to content

Commit

Permalink
Merge pull request #60 from fluxcd/reconcile-annotation
Browse files Browse the repository at this point in the history
Rename syncAt annotation to reconcileAt
  • Loading branch information
stefanprodan authored Jul 13, 2020
2 parents 57806b9 + f79ac6d commit 2fab4b5
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 25 deletions.
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.13
CRD_OPTIONS ?= crd
SOURCE_VER ?= v0.0.2
SOURCE_VER ?= v0.0.5

# 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ kubectl -n gitops-system wait gitrepository/podinfo --for=condition=ready
The source controller will check for new commits in the master branch every minute. You can force a git sync with:

```bash
kubectl -n gitops-system nnotate --overwrite gitrepository/podinfo source.fluxcd.io/syncAt="$(date +%s)"
kubectl -n gitops-system nnotate --overwrite gitrepository/podinfo fluxcd.io/reconcileAt="$(date +%s)"
```

### Define a kustomization
Expand Down Expand Up @@ -159,7 +159,7 @@ You can trigger a kustomization reconciliation any time with:

```bash
kubectl -n gitops-system annotate --overwrite kustomization/podinfo-dev \
kustomize.fluxcd.io/syncAt="$(date +%s)"
fluxcd.io/reconcileAt="$(date +%s)"
```

When the source controller pulls a new Git revision, the kustomize controller will detect that the
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/kustomization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ func (in *Kustomization) GetTimeout() time.Duration {
}

const (
// SyncAtAnnotation is the annotation used for triggering a
// sync outside of the specified schedule.
SyncAtAnnotation string = "kustomize.fluxcd.io/syncAt"
// ReconcileAtAnnotation is the annotation used for triggering a
// reconciliation outside of the defined schedule.
ReconcileAtAnnotation string = "fluxcd.io/reconcileAt"

// SourceIndexKey is the key used for indexing kustomizations
// based on their sources.
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.0.2
- github.com/fluxcd/source-controller/config//manager?ref=v0.0.2
- github.com/fluxcd/source-controller/config//crd?ref=v0.0.5
- github.com/fluxcd/source-controller/config//manager?ref=v0.0.5
- namespace.yaml
4 changes: 2 additions & 2 deletions controllers/gitrepository_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *GitRepositoryWatcher) SetupWithManager(mgr ctrl.Manager) error {
err := mgr.GetFieldIndexer().IndexField(context.TODO(), &kustomizev1.Kustomization{}, kustomizev1.SourceIndexKey,
func(rawObj runtime.Object) []string {
k := rawObj.(*kustomizev1.Kustomization)
if k.Spec.SourceRef.Kind == "GitRepository" {
if k.Spec.SourceRef.Kind == sourcev1.GitRepositoryKind {
return []string{k.Spec.SourceRef.Name}
}
return nil
Expand Down Expand Up @@ -120,7 +120,7 @@ func (r *GitRepositoryWatcher) requestReconciliation(kustomization kustomizev1.K
if kustomization.Annotations == nil {
kustomization.Annotations = make(map[string]string)
}
kustomization.Annotations[kustomizev1.SyncAtAnnotation] = metav1.Now().String()
kustomization.Annotations[kustomizev1.ReconcileAtAnnotation] = metav1.Now().String()
// Prevent strings can't be nil err as API package does not mark APIGroup with omitempty.
if kustomization.Spec.SourceRef.APIGroup == nil {
emptyAPIGroup := ""
Expand Down
2 changes: 1 addition & 1 deletion controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
var source sourcev1.Source

// get artifact source from Git repository
if kustomization.Spec.SourceRef.Kind == "GitRepository" {
if kustomization.Spec.SourceRef.Kind == sourcev1.GitRepositoryKind {
var repository sourcev1.GitRepository
repositoryName := types.NamespacedName{
Namespace: kustomization.GetNamespace(),
Expand Down
6 changes: 3 additions & 3 deletions controllers/kustomization_predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (KustomizationSyncAtPredicate) Update(e event.UpdateEvent) bool {
return true
}

// handle syncAt annotation
if val, ok := e.MetaNew.GetAnnotations()[kustomizev1.SyncAtAnnotation]; ok {
if valOld, okOld := e.MetaOld.GetAnnotations()[kustomizev1.SyncAtAnnotation]; okOld {
// handle reconcileAt annotation
if val, ok := e.MetaNew.GetAnnotations()[kustomizev1.ReconcileAtAnnotation]; ok {
if valOld, okOld := e.MetaOld.GetAnnotations()[kustomizev1.ReconcileAtAnnotation]; okOld {
if val != valOld {
return true
}
Expand Down
10 changes: 5 additions & 5 deletions docs/spec/v1alpha1/kustomization.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,21 @@ The interval time units are `s`, `m` and `h` e.g. `interval: 5m`, the minimum va

The kustomization execution can be suspended by setting `spec.susped` to `true`.

The controller can be told to execute the kustomization outside of the specified interval
The controller can be told to reconcile the kustomization outside of the specified interval
by annotating the kustomization object with:

```go
const (
// SyncAtAnnotation is the annotation used for triggering a
// sync outside of the specified schedule.
SyncAtAnnotation string = "kustomize.fluxcd.io/syncAt"
// ReconcileAtAnnotation is the annotation used for triggering a
// reconciliation outside of the defined schedule.
ReconcileAtAnnotation string = "fluxcd.io/reconcileAt"
)
```

On-demand execution example:

```bash
kubectl annotate --overwrite kustomization/podinfo kustomize.fluxcd.io/syncAt="$(date +%s)"
kubectl annotate --overwrite kustomization/podinfo fluxcd.io/reconcileAt="$(date +%s)"
```

## Garbage collection
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/fluxcd/pkg v0.0.3
github.com/fluxcd/source-controller v0.0.3
github.com/fluxcd/source-controller v0.0.5
github.com/go-logr/logr v0.1.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fluxcd/pkg v0.0.3 h1:yhjtpGtD9LxFo8JtwTuUxJyFcX2wSSb0TPptIEpGSmA=
github.com/fluxcd/pkg v0.0.3/go.mod h1:rtlppQU+9DNikyDZptLdOeTf+wBvQQiQQ/J113FPoeU=
github.com/fluxcd/source-controller v0.0.3 h1:CRk89b7+VPNcouqBdY6UHylMSn8dQEYSciqeci/T25A=
github.com/fluxcd/source-controller v0.0.3/go.mod h1:JQYoE8RuiUaQotUo5N/6l6YOp16EuSzZ8fV0r0ulv2Q=
github.com/fluxcd/source-controller v0.0.5 h1:flUhdZh00/+jzqf9/sSRUMrewp+VlNFDITnoQC7pO4A=
github.com/fluxcd/source-controller v0.0.5/go.mod h1:RhIhH7PE7jqPEaarhtMvCq9zKZp/qTslYtZsJuww9OI=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,24 @@ func main() {

if err = (&controllers.GitRepositoryWatcher{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("GitRepository"),
Log: ctrl.Log.WithName("controllers").WithName(sourcev1.GitRepositoryKind),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GitRepository")
os.Exit(1)
}

if err = (&controllers.KustomizationReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Kustomization"),
Log: ctrl.Log.WithName("controllers").WithName(kustomizev1.KustomizationKind),
Scheme: mgr.GetScheme(),
EventRecorder: mgr.GetEventRecorderFor("kustomize-controller"),
ExternalEventRecorder: eventRecorder,
}).SetupWithManager(mgr, controllers.KustomizationReconcilerOptions{
MaxConcurrentReconciles: concurrent,
DependencyRequeueInterval: requeueDependency,
}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Kustomization")
setupLog.Error(err, "unable to create controller", "controller", kustomizev1.KustomizationKind)
os.Exit(1)
}
// +kubebuilder:scaffold:builder
Expand Down

0 comments on commit 2fab4b5

Please sign in to comment.