Skip to content

Commit 7bc0860

Browse files
committed
chore(cmd/driver): do not exit with error when engine.kind is set to a non-driver driven kind.
Instead, print a warning. Signed-off-by: Federico Di Pierro <[email protected]>
1 parent 3c64d7b commit 7bc0860

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

cmd/driver/config/config.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (o *driverConfigOptions) RunDriverConfig(ctx context.Context, cmd *cobra.Co
165165
o.Printer.Logger.Info("Running falcoctl driver config", loggerArgs)
166166

167167
if o.Update {
168-
err = commit(ctx, dType, driverCfg.HostRoot, o.Namespace, o.KubeConfig)
168+
err = o.commit(ctx, dType, driverCfg.HostRoot)
169169
if err != nil {
170170
return err
171171
}
@@ -184,7 +184,7 @@ func checkFalcoRunsWithDrivers(engineKind string) error {
184184
return nil
185185
}
186186

187-
func replaceDriverTypeInFalcoConfig(hostRoot string, driverType drivertype.DriverType) error {
187+
func (o *driverConfigOptions) replaceDriverTypeInFalcoConfig(hostRoot string, driverType drivertype.DriverType) error {
188188
falcoCfgFile := filepath.Join(hostRoot, "etc", "falco", "falco.yaml")
189189
type engineCfg struct {
190190
Kind string `yaml:"kind"`
@@ -201,20 +201,22 @@ func replaceDriverTypeInFalcoConfig(hostRoot string, driverType drivertype.Drive
201201
return err
202202
}
203203
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
205207
}
206208
const configKindKey = "kind: "
207209
return utils.ReplaceTextInFile(falcoCfgFile, configKindKey+cfg.Engine.Kind, configKindKey+driverType.String(), 1)
208210
}
209211

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 {
211213
var (
212214
err error
213215
cfg *rest.Config
214216
)
215217

216-
if kubeconfig != "" {
217-
cfg, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
218+
if o.KubeConfig != "" {
219+
cfg, err = clientcmd.BuildConfigFromFlags("", o.KubeConfig)
218220
} else {
219221
cfg, err = rest.InClusterConfig()
220222
}
@@ -227,7 +229,7 @@ func replaceDriverTypeInK8SConfigMap(ctx context.Context, namespace, kubeconfig
227229
return err
228230
}
229231

230-
configMapList, err := cl.CoreV1().ConfigMaps(namespace).List(ctx, metav1.ListOptions{
232+
configMapList, err := cl.CoreV1().ConfigMaps(o.Namespace).List(ctx, metav1.ListOptions{
231233
LabelSelector: "app.kubernetes.io/instance: falco",
232234
})
233235
if err != nil {
@@ -253,6 +255,8 @@ func replaceDriverTypeInK8SConfigMap(ctx context.Context, namespace, kubeconfig
253255
configMap := configMapList.Items[i]
254256
currEngineKind := configMap.Data[configMapEngineKindKey]
255257
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))
256260
continue
257261
}
258262
// Patch the configMap
@@ -266,10 +270,10 @@ func replaceDriverTypeInK8SConfigMap(ctx context.Context, namespace, kubeconfig
266270

267271
// commit saves the updated driver type to Falco config,
268272
// 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 != "" {
271275
// Ok we are on k8s
272-
return replaceDriverTypeInK8SConfigMap(ctx, namespace, kubeconfig, driverType)
276+
return o.replaceDriverTypeInK8SConfigMap(ctx, driverType)
273277
}
274-
return replaceDriverTypeInFalcoConfig(hostroot, driverType)
278+
return o.replaceDriverTypeInFalcoConfig(hostroot, driverType)
275279
}

0 commit comments

Comments
 (0)