Skip to content

Commit 4c9c93c

Browse files
committed
Default manageStatus to true
1 parent cb5c263 commit 4c9c93c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/ansible/runner/runner.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,26 @@ type Finalizer struct {
6666
Vars map[string]interface{} `yaml:"vars"`
6767
}
6868

69+
// hide watch data in plain struct to prevent unmarshal from calling
70+
// UnmarshalYAML again
71+
type plain watch
72+
73+
// UnmarshalYaml - implements the yaml.Unmarshaler interface
74+
func (w *watch) UnmarshalYAML(unmarshal func(interface{}) error) error {
75+
// by default, the operator will manage status
76+
w.ManageStatus = true
77+
78+
return unmarshal((*plain)(w))
79+
}
80+
6981
// NewFromWatches reads the operator's config file at the provided path.
7082
func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
7183
b, err := ioutil.ReadFile(path)
7284
if err != nil {
7385
log.Error(err, "failed to get config file")
7486
return nil, err
7587
}
76-
watches := []watch{watch{ManageStatus: true}}
88+
watches := []watch{}
7789
err = yaml.Unmarshal(b, &watches)
7890
if err != nil {
7991
log.Error(err, "failed to unmarshal config")
@@ -102,13 +114,13 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
102114
}
103115
switch {
104116
case w.Playbook != "":
105-
r, err := NewForPlaybook(w.Playbook, s, w.Finalizer, reconcilePeriod)
117+
r, err := NewForPlaybook(w.Playbook, s, w.Finalizer, reconcilePeriod, w.ManageStatus)
106118
if err != nil {
107119
return nil, err
108120
}
109121
m[s] = r
110122
case w.Role != "":
111-
r, err := NewForRole(w.Role, s, w.Finalizer, reconcilePeriod)
123+
r, err := NewForRole(w.Role, s, w.Finalizer, reconcilePeriod, w.ManageStatus)
112124
if err != nil {
113125
return nil, err
114126
}
@@ -121,7 +133,7 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
121133
}
122134

123135
// NewForPlaybook returns a new Runner based on the path to an ansible playbook.
124-
func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration) (Runner, error) {
136+
func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration, manageStatus bool) (Runner, error) {
125137
if !filepath.IsAbs(path) {
126138
return nil, fmt.Errorf("playbook path must be absolute for %v", gvk)
127139
}
@@ -135,6 +147,7 @@ func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finaliz
135147
return exec.Command("ansible-runner", "-vv", "-p", path, "-i", ident, "run", inputDirPath)
136148
},
137149
reconcilePeriod: reconcilePeriod,
150+
manageStatus: manageStatus,
138151
}
139152
err := r.addFinalizer(finalizer)
140153
if err != nil {
@@ -144,7 +157,7 @@ func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finaliz
144157
}
145158

146159
// NewForRole returns a new Runner based on the path to an ansible role.
147-
func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration) (Runner, error) {
160+
func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer, reconcilePeriod *time.Duration, manageStatus bool) (Runner, error) {
148161
if !filepath.IsAbs(path) {
149162
return nil, fmt.Errorf("role path must be absolute for %v", gvk)
150163
}
@@ -160,6 +173,7 @@ func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer,
160173
return exec.Command("ansible-runner", "-vv", "--role", roleName, "--roles-path", rolePath, "--hosts", "localhost", "-i", ident, "run", inputDirPath)
161174
},
162175
reconcilePeriod: reconcilePeriod,
176+
manageStatus: manageStatus,
163177
}
164178
err := r.addFinalizer(finalizer)
165179
if err != nil {

0 commit comments

Comments
 (0)