@@ -165,7 +165,7 @@ func (o *driverConfigOptions) RunDriverConfig(ctx context.Context, cmd *cobra.Co
165
165
o .Printer .Logger .Info ("Running falcoctl driver config" , loggerArgs )
166
166
167
167
if o .Update {
168
- err = commit (ctx , dType , driverCfg .HostRoot , o . Namespace , o . KubeConfig )
168
+ err = o . commit (ctx , dType , driverCfg .HostRoot )
169
169
if err != nil {
170
170
return err
171
171
}
@@ -184,7 +184,7 @@ func checkFalcoRunsWithDrivers(engineKind string) error {
184
184
return nil
185
185
}
186
186
187
- func replaceDriverTypeInFalcoConfig (hostRoot string , driverType drivertype.DriverType ) error {
187
+ func ( o * driverConfigOptions ) replaceDriverTypeInFalcoConfig (hostRoot string , driverType drivertype.DriverType ) error {
188
188
falcoCfgFile := filepath .Join (hostRoot , "etc" , "falco" , "falco.yaml" )
189
189
type engineCfg struct {
190
190
Kind string `yaml:"kind"`
@@ -201,20 +201,22 @@ func replaceDriverTypeInFalcoConfig(hostRoot string, driverType drivertype.Drive
201
201
return err
202
202
}
203
203
if err = checkFalcoRunsWithDrivers (cfg .Engine .Kind ); err != nil {
204
- return err
204
+ o .Printer .Logger .Warn ("Avoid updating Falco configuration" ,
205
+ o .Printer .Logger .Args ("config" , falcoCfgFile , "reason" , err ))
206
+ return nil
205
207
}
206
208
const configKindKey = "kind: "
207
209
return utils .ReplaceTextInFile (falcoCfgFile , configKindKey + cfg .Engine .Kind , configKindKey + driverType .String (), 1 )
208
210
}
209
211
210
- func replaceDriverTypeInK8SConfigMap (ctx context.Context , namespace , kubeconfig string , driverType drivertype.DriverType ) error {
212
+ func ( o * driverConfigOptions ) replaceDriverTypeInK8SConfigMap (ctx context.Context , driverType drivertype.DriverType ) error {
211
213
var (
212
214
err error
213
215
cfg * rest.Config
214
216
)
215
217
216
- if kubeconfig != "" {
217
- cfg , err = clientcmd .BuildConfigFromFlags ("" , kubeconfig )
218
+ if o . KubeConfig != "" {
219
+ cfg , err = clientcmd .BuildConfigFromFlags ("" , o . KubeConfig )
218
220
} else {
219
221
cfg , err = rest .InClusterConfig ()
220
222
}
@@ -227,7 +229,7 @@ func replaceDriverTypeInK8SConfigMap(ctx context.Context, namespace, kubeconfig
227
229
return err
228
230
}
229
231
230
- configMapList , err := cl .CoreV1 ().ConfigMaps (namespace ).List (ctx , metav1.ListOptions {
232
+ configMapList , err := cl .CoreV1 ().ConfigMaps (o . Namespace ).List (ctx , metav1.ListOptions {
231
233
LabelSelector : "app.kubernetes.io/instance: falco" ,
232
234
})
233
235
if err != nil {
@@ -253,6 +255,8 @@ func replaceDriverTypeInK8SConfigMap(ctx context.Context, namespace, kubeconfig
253
255
configMap := configMapList .Items [i ]
254
256
currEngineKind := configMap .Data [configMapEngineKindKey ]
255
257
if err = checkFalcoRunsWithDrivers (currEngineKind ); err != nil {
258
+ o .Printer .Logger .Warn ("Avoid updating Falco configMap" ,
259
+ o .Printer .Logger .Args ("configMap" , configMap .Name , "reason" , err ))
256
260
continue
257
261
}
258
262
// Patch the configMap
@@ -266,10 +270,10 @@ func replaceDriverTypeInK8SConfigMap(ctx context.Context, namespace, kubeconfig
266
270
267
271
// commit saves the updated driver type to Falco config,
268
272
// either to the local falco.yaml or updating the deployment configmap.
269
- func commit (ctx context.Context , driverType drivertype.DriverType , hostroot , namespace , kubeconfig string ) error {
270
- if namespace != "" {
273
+ func ( o * driverConfigOptions ) commit (ctx context.Context , driverType drivertype.DriverType , hostroot string ) error {
274
+ if o . Namespace != "" {
271
275
// Ok we are on k8s
272
- return replaceDriverTypeInK8SConfigMap (ctx , namespace , kubeconfig , driverType )
276
+ return o . replaceDriverTypeInK8SConfigMap (ctx , driverType )
273
277
}
274
- return replaceDriverTypeInFalcoConfig (hostroot , driverType )
278
+ return o . replaceDriverTypeInFalcoConfig (hostroot , driverType )
275
279
}
0 commit comments