@@ -110,18 +110,6 @@ func main() {
110
110
flag .Set ("logtostderr" , "true" )
111
111
flag .Set ("alsologtostderr" , "true" )
112
112
flag .Parse ()
113
-
114
- // klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
115
- // klog.InitFlags(klogFlags)
116
-
117
- // Sync the glog and klog flags.
118
- // flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
119
- // f2 := klogFlags.Lookup(f1.Name)
120
- // if f2 != nil {
121
- // value := f1.Value.String()
122
- // f2.Value.Set(value)
123
- // }
124
- // })
125
113
defer klog .Flush ()
126
114
127
115
if * commandName == "" {
@@ -138,7 +126,7 @@ func main() {
138
126
klog .V (1 ).Infof ("Command custom resource: namespace %q" , * commandNamespace )
139
127
klog .V (1 ).Infof ("Command custom resource: name %q" , * commandName )
140
128
141
- r , err := NewK8sRunner ()
129
+ r , err := NewRunner ()
142
130
if err != nil {
143
131
// This should lead to crashloopback if this
144
132
// is running from within a Kubernetes pod
@@ -153,18 +141,19 @@ func main() {
153
141
os .Exit (0 )
154
142
}
155
143
156
- // Runnable helps in executing the Kubernetes command resource.
157
- // It does so by executing the commands or scripts specified in
158
- // the resource and updating this resource post execution.
159
- type K8sRunnable struct {
144
+ // Runnable helps in executing the Kubernetes command
145
+ // resource. It does so by executing the commands or scripts
146
+ // specified in the resource and updating this resource post
147
+ // execution.
148
+ type Runnable struct {
160
149
Client dynamic.Interface
161
150
GVR schema.GroupVersionResource
162
151
163
152
commandStatus * pkg.CommandStatus
164
153
}
165
154
166
- // NewRunner returns a new instance of K8sRunnable
167
- func NewK8sRunner () (* K8sRunnable , error ) {
155
+ // NewRunner returns a new instance of Runnable
156
+ func NewRunner () (* Runnable , error ) {
168
157
var config * rest.Config
169
158
var err error
170
159
@@ -198,13 +187,13 @@ func NewK8sRunner() (*K8sRunnable, error) {
198
187
Resource : * commandResource ,
199
188
}
200
189
201
- return & K8sRunnable {
190
+ return & Runnable {
202
191
Client : client ,
203
192
GVR : gvr ,
204
193
}, nil
205
194
}
206
195
207
- func (a * K8sRunnable ) updateWithRetries () error {
196
+ func (a * Runnable ) updateWithRetries () error {
208
197
var statusNew interface {}
209
198
err := pkg .MarshalThenUnmarshal (a .commandStatus , & statusNew )
210
199
if err != nil {
@@ -216,10 +205,12 @@ func (a *K8sRunnable) updateWithRetries() error {
216
205
)
217
206
}
218
207
klog .V (1 ).Infof (
219
- "Command status: %s \n %s" ,
220
- pkg .NewJSON (a .commandStatus ).MustMarshal (),
208
+ "Command %q / %q: Status %s" ,
209
+ * commandNamespace ,
210
+ * commandName ,
221
211
pkg .NewJSON (statusNew ).MustMarshal (),
222
212
)
213
+
223
214
// Command is updated with latest labels
224
215
labels := map [string ]string {
225
216
// this label key is set with same value as that of status.phase
@@ -300,13 +291,12 @@ func (a *K8sRunnable) updateWithRetries() error {
300
291
UpdateStatus (cmd , v1.UpdateOptions {})
301
292
302
293
if err == nil {
294
+ // This is an extra check to detect type conversion issues
295
+ // if any during later stages
303
296
var c pkg.Command
304
297
tErr := pkg .ToTyped (cmdUpdatedStatus , & c )
305
298
klog .V (1 ).Infof (
306
- "IsError=%t: %v: \n %s" ,
307
- tErr != nil ,
308
- tErr ,
309
- pkg .NewJSON (c ).MustMarshal (),
299
+ "UnstructToTyped: IsError=%t: %v" , tErr != nil , tErr ,
310
300
)
311
301
}
312
302
// If update status resulted in an error it will be
@@ -331,7 +321,7 @@ func (a *K8sRunnable) updateWithRetries() error {
331
321
}
332
322
333
323
// Run executes the command resource
334
- func (a * K8sRunnable ) Run () error {
324
+ func (a * Runnable ) Run () error {
335
325
got , err := a .Client .
336
326
Resource (a .GVR ).
337
327
Namespace (* commandNamespace ).
0 commit comments