Skip to content

Commit

Permalink
ansible: support disabling reconciliation
Browse files Browse the repository at this point in the history
- Enforce the "default" reconcilePeriod to be > 0
- Enforce reconcilePeriod for a particular GVK to be >= 0
  • Loading branch information
djzager committed Nov 13, 2018
1 parent fa72147 commit 3cbe89d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
3 changes: 0 additions & 3 deletions pkg/ansible/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func Add(mgr manager.Manager, options Options) {
options.EventHandlers = []events.EventHandler{}
}
eventHandlers := append(options.EventHandlers, events.NewLoggingEventHandler(options.LoggingLevel))
if options.ReconcilePeriod == time.Duration(0) {
options.ReconcilePeriod = time.Minute
}

aor := &AnsibleOperatorReconciler{
Client: mgr.GetClient(),
Expand Down
3 changes: 3 additions & 0 deletions pkg/ansible/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func Run(done chan error, mgr manager.Manager, watchesPath string, reconcilePeri
done <- err
return
}
if reconcilePeriod <= time.Duration(0) {
reconcilePeriod = time.Minute
}
rand.Seed(time.Now().Unix())
c := signals.SetupSignalHandler()

Expand Down
2 changes: 1 addition & 1 deletion pkg/ansible/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig stri

// GetReconcilePeriod - new reconcile period.
func (r *runner) GetReconcilePeriod() (time.Duration, bool) {
if r.reconcilePeriod == time.Duration(0) {
if r.reconcilePeriod < time.Duration(0) {
return r.reconcilePeriod, false
}
return r.reconcilePeriod, true
Expand Down
18 changes: 18 additions & 0 deletions pkg/ansible/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func TestNewFromWatches(t *testing.T) {
path: "testdata/invalid_duration.yaml",
shouldError: true,
},
{
name: "error negative duration",
path: "testdata/negative_duration.yaml",
shouldError: true,
},
{
name: "valid watches file",
path: "testdata/valid.yaml",
Expand Down Expand Up @@ -133,6 +138,19 @@ func TestNewFromWatches(t *testing.T) {
Vars: map[string]interface{}{"sentinel": "finalizer_running"},
},
},
schema.GroupVersionKind{
Version: "v1alpha1",
Group: "app.example.com",
Kind: "NoReconcile",
}: runner{
GVK: schema.GroupVersionKind{
Version: "v1alpha1",
Group: "app.example.com",
Kind: "NoReconcile",
},
Path: validTemplate.ValidPlaybook,
reconcilePeriod: time.Duration(0),
},
schema.GroupVersionKind{
Version: "v1alpha1",
Group: "app.example.com",
Expand Down
6 changes: 6 additions & 0 deletions pkg/ansible/runner/testdata/negative_duration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- version: v1alpha1
group: app.example.com
kind: NegativeReconcile
playbook: /opt/ansible/playbook.yaml
reconcilePeriod: -2s
5 changes: 5 additions & 0 deletions pkg/ansible/runner/testdata/valid.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
role: {{ .ValidRole }}
vars:
sentinel: finalizer_running
- version: v1alpha1
group: app.example.com
kind: NoReconcile
playbook: {{ .ValidPlaybook }}
reconcilePeriod: 0s
- version: v1alpha1
group: app.example.com
kind: Role
Expand Down

0 comments on commit 3cbe89d

Please sign in to comment.