Skip to content

Commit 4304943

Browse files
committed
managedStatus -> manageStatus, not runtime configurable
1 parent 58e2a5f commit 4304943

File tree

9 files changed

+27
-54
lines changed

9 files changed

+27
-54
lines changed

commands/operator-sdk/cmd/up/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func upLocalAnsible() {
161161
}
162162

163163
// start the operator
164-
go ansibleOperator.Run(done, mgr, "./"+ansibleScaffold.WatchesYamlFile, time.Minute, true)
164+
go ansibleOperator.Run(done, mgr, "./"+ansibleScaffold.WatchesYamlFile, time.Minute)
165165

166166
// wait for either to finish
167167
err = <-done

pkg/ansible/controller/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Options struct {
4242
Runner runner.Runner
4343
GVK schema.GroupVersionKind
4444
ReconcilePeriod time.Duration
45-
ManagedStatus bool
45+
ManageStatus bool
4646
}
4747

4848
// Add - Creates a new ansible operator controller and adds it to the manager
@@ -59,7 +59,7 @@ func Add(mgr manager.Manager, options Options) {
5959
Runner: options.Runner,
6060
EventHandlers: eventHandlers,
6161
ReconcilePeriod: options.ReconcilePeriod,
62-
ManagedStatus: options.ManagedStatus,
62+
ManageStatus: options.ManageStatus,
6363
}
6464

6565
// Register the GVK with the schema

pkg/ansible/controller/reconcile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type AnsibleOperatorReconciler struct {
5454
Client client.Client
5555
EventHandlers []events.EventHandler
5656
ReconcilePeriod time.Duration
57-
ManagedStatus bool
57+
ManageStatus bool
5858
}
5959

6060
// Reconcile - handle the event.
@@ -114,7 +114,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
114114
}
115115
}
116116

117-
if r.ManagedStatus {
117+
if r.ManageStatus {
118118
err = r.markRunning(u)
119119
if err != nil {
120120
return reconcileResult, err
@@ -187,7 +187,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(request reconcile.Request) (reconc
187187
return reconcileResult, err
188188
}
189189
}
190-
if r.ManagedStatus {
190+
if r.ManageStatus {
191191
err = r.markDone(u, statusEvent, failureMessages)
192192
}
193193
return reconcileResult, err

pkg/ansible/controller/reconcile_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestReconcile(t *testing.T) {
4646
Name string
4747
GVK schema.GroupVersionKind
4848
ReconcilePeriod time.Duration
49-
ManagedStatus bool
49+
ManageStatus bool
5050
Runner runner.Runner
5151
EventHandlers []events.EventHandler
5252
Client client.Client
@@ -75,7 +75,7 @@ func TestReconcile(t *testing.T) {
7575
Name: "completed reconcile",
7676
GVK: gvk,
7777
ReconcilePeriod: 5 * time.Second,
78-
ManagedStatus: true,
78+
ManageStatus: true,
7979
Runner: &fake.Runner{
8080
JobEvents: []eventapi.JobEvent{
8181
eventapi.JobEvent{
@@ -136,7 +136,7 @@ func TestReconcile(t *testing.T) {
136136
Name: "Failure message reconcile",
137137
GVK: gvk,
138138
ReconcilePeriod: 5 * time.Second,
139-
ManagedStatus: true,
139+
ManageStatus: true,
140140
Runner: &fake.Runner{
141141
JobEvents: []eventapi.JobEvent{
142142
eventapi.JobEvent{
@@ -213,7 +213,7 @@ func TestReconcile(t *testing.T) {
213213
Name: "Finalizer successful reconcile",
214214
GVK: gvk,
215215
ReconcilePeriod: 5 * time.Second,
216-
ManagedStatus: true,
216+
ManageStatus: true,
217217
Runner: &fake.Runner{
218218
JobEvents: []eventapi.JobEvent{
219219
eventapi.JobEvent{
@@ -321,7 +321,7 @@ func TestReconcile(t *testing.T) {
321321
Name: "Finalizer successful reconcile",
322322
GVK: gvk,
323323
ReconcilePeriod: 5 * time.Second,
324-
ManagedStatus: true,
324+
ManageStatus: true,
325325
Runner: &fake.Runner{
326326
JobEvents: []eventapi.JobEvent{
327327
eventapi.JobEvent{
@@ -421,7 +421,7 @@ func TestReconcile(t *testing.T) {
421421
Name: "no manage status",
422422
GVK: gvk,
423423
ReconcilePeriod: 5 * time.Second,
424-
ManagedStatus: false,
424+
ManageStatus: false,
425425
Runner: &fake.Runner{
426426
JobEvents: []eventapi.JobEvent{
427427
eventapi.JobEvent{
@@ -472,7 +472,7 @@ func TestReconcile(t *testing.T) {
472472
Client: tc.Client,
473473
EventHandlers: tc.EventHandlers,
474474
ReconcilePeriod: tc.ReconcilePeriod,
475-
ManagedStatus: tc.ManagedStatus,
475+
ManageStatus: tc.ManageStatus,
476476
}
477477
result, err := aor.Reconcile(tc.Request)
478478
if err != nil && !tc.ShouldError {

pkg/ansible/operator/operator.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// Run - A blocking function which starts a controller-runtime manager
3030
// It starts an Operator by reading in the values in `./watches.yaml`, adds a controller
3131
// to the manager, and finally running the manager.
32-
func Run(done chan error, mgr manager.Manager, watchesPath string, reconcilePeriod time.Duration, managedStatus bool) {
32+
func Run(done chan error, mgr manager.Manager, watchesPath string, reconcilePeriod time.Duration) {
3333
watches, err := runner.NewFromWatches(watchesPath)
3434
if err != nil {
3535
logf.Log.WithName("manager").Error(err, "failed to get watches")
@@ -44,16 +44,11 @@ func Run(done chan error, mgr manager.Manager, watchesPath string, reconcilePeri
4444
GVK: gvk,
4545
Runner: runner,
4646
ReconcilePeriod: reconcilePeriod,
47-
ManagedStatus: managedStatus,
4847
}
4948
d, ok := runner.GetReconcilePeriod()
5049
if ok {
5150
o.ReconcilePeriod = d
5251
}
53-
s, ok := runner.GetManagedStatus()
54-
if ok {
55-
o.ManagedStatus = s
56-
}
5752
controller.Add(mgr, o)
5853
}
5954
done <- mgr.Start(c)

pkg/ansible/runner/fake/runner.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
type Runner struct {
2828
Finalizer string
2929
ReconcilePeriod time.Duration
30-
ManagedStatus bool
30+
ManageStatus bool
3131
// Used to send error if Run should fail.
3232
Error error
3333
// Job Events that will be sent back from the runs channel
@@ -72,11 +72,6 @@ func (r *Runner) GetReconcilePeriod() (time.Duration, bool) {
7272
return r.ReconcilePeriod, r.ReconcilePeriod != time.Duration(0)
7373
}
7474

75-
// GetManagedStatus - return fake status
76-
func (r *Runner) GetManagedStatus() (bool, bool) {
77-
return r.ManagedStatus, true
78-
}
79-
8075
// GetFinalizer - gets the fake finalizer.
8176
func (r *Runner) GetFinalizer() (string, bool) {
8277
return r.Finalizer, r.Finalizer != ""

pkg/ansible/runner/runner.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type Runner interface {
4343
Run(string, *unstructured.Unstructured, string) (RunResult, error)
4444
GetFinalizer() (string, bool)
4545
GetReconcilePeriod() (time.Duration, bool)
46-
GetManagedStatus() (bool, bool)
4746
}
4847

4948
// watch holds data used to create a mapping of GVK to ansible playbook or role.
@@ -55,7 +54,7 @@ type watch struct {
5554
Playbook string `yaml:"playbook"`
5655
Role string `yaml:"role"`
5756
ReconcilePeriod string `yaml:"reconcilePeriod"`
58-
ManagedStatus *bool `yaml:"manageStatus"`
57+
ManageStatus bool `yaml:"manageStatus"`
5958
Finalizer *Finalizer `yaml:"finalizer"`
6059
}
6160

@@ -74,7 +73,7 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
7473
log.Error(err, "failed to get config file")
7574
return nil, err
7675
}
77-
watches := []watch{}
76+
watches := []watch{watch{ManageStatus: true}}
7877
err = yaml.Unmarshal(b, &watches)
7978
if err != nil {
8079
log.Error(err, "failed to unmarshal config")
@@ -96,24 +95,20 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
9695
}
9796
reconcilePeriod = &d
9897
}
99-
var managedStatus *bool
100-
if w.ManagedStatus != nil {
101-
managedStatus = w.ManagedStatus
102-
}
10398

10499
// Check if schema is a duplicate
105100
if _, ok := m[s]; ok {
106101
return nil, fmt.Errorf("duplicate GVK: %v", s.String())
107102
}
108103
switch {
109104
case w.Playbook != "":
110-
r, err := NewForPlaybook(w.Playbook, s, w.Finalizer, reconcilePeriod, managedStatus)
105+
r, err := NewForPlaybook(w.Playbook, s, w.Finalizer, reconcilePeriod)
111106
if err != nil {
112107
return nil, err
113108
}
114109
m[s] = r
115110
case w.Role != "":
116-
r, err := NewForRole(w.Role, s, w.Finalizer, reconcilePeriod, managedStatus)
111+
r, err := NewForRole(w.Role, s, w.Finalizer, reconcilePeriod)
117112
if err != nil {
118113
return nil, err
119114
}
@@ -126,7 +121,7 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
126121
}
127122

128123
// NewForPlaybook returns a new Runner based on the path to an ansible playbook.
129-
func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration, managedStatus *bool) (Runner, error) {
124+
func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration) (Runner, error) {
130125
if !filepath.IsAbs(path) {
131126
return nil, fmt.Errorf("playbook path must be absolute for %v", gvk)
132127
}
@@ -140,7 +135,6 @@ func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finaliz
140135
return exec.Command("ansible-runner", "-vv", "-p", path, "-i", ident, "run", inputDirPath)
141136
},
142137
reconcilePeriod: reconcilePeriod,
143-
managedStatus: managedStatus,
144138
}
145139
err := r.addFinalizer(finalizer)
146140
if err != nil {
@@ -150,7 +144,7 @@ func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finaliz
150144
}
151145

152146
// NewForRole returns a new Runner based on the path to an ansible role.
153-
func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration, managedStatus *bool) (Runner, error) {
147+
func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration) (Runner, error) {
154148
if !filepath.IsAbs(path) {
155149
return nil, fmt.Errorf("role path must be absolute for %v", gvk)
156150
}
@@ -166,7 +160,6 @@ func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer,
166160
return exec.Command("ansible-runner", "-vv", "--role", roleName, "--roles-path", rolePath, "--hosts", "localhost", "-i", ident, "run", inputDirPath)
167161
},
168162
reconcilePeriod: reconcilePeriod,
169-
managedStatus: managedStatus,
170163
}
171164
err := r.addFinalizer(finalizer)
172165
if err != nil {
@@ -183,7 +176,7 @@ type runner struct {
183176
cmdFunc func(ident, inputDirPath string) *exec.Cmd // returns a Cmd that runs ansible-runner
184177
finalizerCmdFunc func(ident, inputDirPath string) *exec.Cmd
185178
reconcilePeriod *time.Duration
186-
managedStatus *bool
179+
manageStatus bool
187180
}
188181

189182
func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig string) (RunResult, error) {
@@ -266,14 +259,6 @@ func (r *runner) GetReconcilePeriod() (time.Duration, bool) {
266259
return *r.reconcilePeriod, true
267260
}
268261

269-
// GetManagedStatus - return runner's managedStatus if defined
270-
func (r *runner) GetManagedStatus() (bool, bool) {
271-
if r.managedStatus == nil {
272-
return false, false
273-
}
274-
return *r.managedStatus, true
275-
}
276-
277262
func (r *runner) GetFinalizer() (string, bool) {
278263
if r.Finalizer != nil {
279264
return r.Finalizer.Name, true

pkg/ansible/runner/runner_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ func TestNewFromWatches(t *testing.T) {
5555

5656
zeroSeconds := time.Duration(0)
5757
twoSeconds := time.Second * 2
58-
noManagedStatus := false
59-
managedStatus := true
6058
testCases := []struct {
6159
name string
6260
path string
@@ -165,8 +163,8 @@ func TestNewFromWatches(t *testing.T) {
165163
Group: "app.example.com",
166164
Kind: "DisableStatus",
167165
},
168-
Path: validTemplate.ValidPlaybook,
169-
managedStatus: &noManagedStatus,
166+
Path: validTemplate.ValidPlaybook,
167+
manageStatus: false,
170168
},
171169
schema.GroupVersionKind{
172170
Version: "v1alpha1",
@@ -178,8 +176,8 @@ func TestNewFromWatches(t *testing.T) {
178176
Group: "app.example.com",
179177
Kind: "EnableStatus",
180178
},
181-
Path: validTemplate.ValidPlaybook,
182-
managedStatus: &managedStatus,
179+
Path: validTemplate.ValidPlaybook,
180+
manageStatus: true,
183181
},
184182
schema.GroupVersionKind{
185183
Version: "v1alpha1",

test/ansible-operator/cmd/ansible-operator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func main() {
6767
}
6868

6969
// start the operator
70-
go operator.Run(done, mgr, "/opt/ansible/watches.yaml", time.Minute, true)
70+
go operator.Run(done, mgr, "/opt/ansible/watches.yaml", time.Minute)
7171

7272
// wait for either to finish
7373
err = <-done

0 commit comments

Comments
 (0)