@@ -66,14 +66,26 @@ type Finalizer struct {
66
66
Vars map [string ]interface {} `yaml:"vars"`
67
67
}
68
68
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
+
69
81
// NewFromWatches reads the operator's config file at the provided path.
70
82
func NewFromWatches (path string ) (map [schema.GroupVersionKind ]Runner , error ) {
71
83
b , err := ioutil .ReadFile (path )
72
84
if err != nil {
73
85
log .Error (err , "failed to get config file" )
74
86
return nil , err
75
87
}
76
- watches := []watch {watch { ManageStatus : true } }
88
+ watches := []watch {}
77
89
err = yaml .Unmarshal (b , & watches )
78
90
if err != nil {
79
91
log .Error (err , "failed to unmarshal config" )
@@ -102,13 +114,13 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
102
114
}
103
115
switch {
104
116
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 )
106
118
if err != nil {
107
119
return nil , err
108
120
}
109
121
m [s ] = r
110
122
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 )
112
124
if err != nil {
113
125
return nil , err
114
126
}
@@ -121,7 +133,7 @@ func NewFromWatches(path string) (map[schema.GroupVersionKind]Runner, error) {
121
133
}
122
134
123
135
// 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 ) {
125
137
if ! filepath .IsAbs (path ) {
126
138
return nil , fmt .Errorf ("playbook path must be absolute for %v" , gvk )
127
139
}
@@ -135,6 +147,7 @@ func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finaliz
135
147
return exec .Command ("ansible-runner" , "-vv" , "-p" , path , "-i" , ident , "run" , inputDirPath )
136
148
},
137
149
reconcilePeriod : reconcilePeriod ,
150
+ manageStatus : manageStatus ,
138
151
}
139
152
err := r .addFinalizer (finalizer )
140
153
if err != nil {
@@ -144,7 +157,7 @@ func NewForPlaybook(path string, gvk schema.GroupVersionKind, finalizer *Finaliz
144
157
}
145
158
146
159
// 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 ) {
148
161
if ! filepath .IsAbs (path ) {
149
162
return nil , fmt .Errorf ("role path must be absolute for %v" , gvk )
150
163
}
@@ -160,6 +173,7 @@ func NewForRole(path string, gvk schema.GroupVersionKind, finalizer *Finalizer,
160
173
return exec .Command ("ansible-runner" , "-vv" , "--role" , roleName , "--roles-path" , rolePath , "--hosts" , "localhost" , "-i" , ident , "run" , inputDirPath )
161
174
},
162
175
reconcilePeriod : reconcilePeriod ,
176
+ manageStatus : manageStatus ,
163
177
}
164
178
err := r .addFinalizer (finalizer )
165
179
if err != nil {
0 commit comments