Skip to content

Commit 8e3dae3

Browse files
committed
fix(artifact): remove configMapKey, add configMap Indexer, restore artifact constants and types
Signed-off-by: cannarelladev <cannarella.dev@gmail.com>
1 parent fa7d354 commit 8e3dae3

File tree

23 files changed

+422
-391
lines changed

23 files changed

+422
-391
lines changed

api/artifact/v1alpha1/rulesfile_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2025 The Falco Authors
1+
// Copyright (C) 2026 The Falco Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

api/common/v1alpha1/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2025 The Falco Authors
1+
// Copyright (C) 2026 The Falco Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -39,6 +39,11 @@ const (
3939
ConditionReconciled ConditionType = "ConditionReconciled"
4040
)
4141

42+
const (
43+
// ConfigMapRulesKey is the standard key used for rules data in ConfigMaps.
44+
ConfigMapRulesKey = "rules.yaml"
45+
)
46+
4247
// OCIArtifact defines the structure for specifying an OCI artifact reference.
4348
// +kubebuilder:object:generate=true
4449
type OCIArtifact struct {
@@ -72,8 +77,4 @@ type ConfigMapRef struct {
7277
// Name is the name of the ConfigMap.
7378
// +kubebuilder:validation:Required
7479
Name string `json:"name"`
75-
76-
// Key is the key in the ConfigMap to select.
77-
// +kubebuilder:validation:Required
78-
Key string `json:"key"`
7980
}

config/crd/bases/artifact.falcosecurity.dev_rulesfiles.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ spec:
4343
description: ConfigMapRef specifies a reference to a ConfigMap containing
4444
the rules.
4545
properties:
46-
key:
47-
description: Key is the key in the ConfigMap to select.
48-
type: string
4946
name:
5047
description: Name is the name of the ConfigMap.
5148
type: string
5249
required:
53-
- key
5450
- name
5551
type: object
5652
inlineRules:

config/samples/artifact_v1alpha1_rulesfile_configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ data:
3737
3838
---
3939
# Example Rulesfile using ConfigMap reference
40+
# Note: The ConfigMap must have a key named "rules.yaml" containing the rules content
4041
apiVersion: artifact.falcosecurity.dev/v1alpha1
4142
kind: Rulesfile
4243
metadata:
@@ -48,6 +49,5 @@ metadata:
4849
spec:
4950
configMapRef:
5051
name: custom-falco-rules
51-
key: rules.yaml
5252
priority: 60
5353

controllers/artifact/config/controller.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2025 The Falco Authors
1+
// Copyright (C) 2026 The Falco Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,8 +14,6 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17-
// Package controller defines controllers' logic.
18-
1917
package config
2018

2119
import (

controllers/artifact/config/controller_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2025 The Falco Authors
1+
// Copyright (C) 2026 The Falco Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,8 +14,6 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17-
// Package controller defines controllers' logic.
18-
1917
package config
2018

2119
import (

controllers/artifact/config/suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2025 The Falco Authors
1+
// Copyright (C) 2026 The Falco Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,8 +14,6 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17-
// Package controller defines controllers' logic.
18-
1917
package config
2018

2119
import (
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright (C) 2026 The Falco Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
package plugin
18+
19+
import (
20+
"gopkg.in/yaml.v3"
21+
22+
artifactv1alpha1 "github.com/falcosecurity/falco-operator/api/artifact/v1alpha1"
23+
"github.com/falcosecurity/falco-operator/internal/pkg/artifact"
24+
"github.com/falcosecurity/falco-operator/internal/pkg/priority"
25+
)
26+
27+
// PluginConfig is the configuration for a plugin.
28+
type PluginConfig struct {
29+
InitConfig map[string]string `yaml:"init_config,omitempty"`
30+
LibraryPath string `yaml:"library_path"`
31+
Name string `yaml:"name"`
32+
OpenParams string `yaml:"open_params,omitempty"`
33+
}
34+
35+
func (p *PluginConfig) isSame(other *PluginConfig) bool {
36+
if p.Name != other.Name {
37+
return false
38+
}
39+
// Check if the maps are equal.
40+
if len(p.InitConfig) != len(other.InitConfig) {
41+
return false
42+
}
43+
// Check if the keys and values are equal.
44+
for key, value := range p.InitConfig {
45+
if otherValue, ok := other.InitConfig[key]; !ok || value != otherValue {
46+
return false
47+
}
48+
}
49+
if p.LibraryPath != other.LibraryPath {
50+
return false
51+
}
52+
if p.OpenParams != other.OpenParams {
53+
return false
54+
}
55+
return true
56+
}
57+
58+
// PluginsConfig is the configuration for the plugins.
59+
type PluginsConfig struct {
60+
Configs []PluginConfig `yaml:"plugins"`
61+
LoadPlugins []string `yaml:"load_plugins,omitempty"`
62+
}
63+
64+
func (pc *PluginsConfig) addConfig(plugin *artifactv1alpha1.Plugin) {
65+
config := PluginConfig{
66+
LibraryPath: artifact.Path(plugin.Name, priority.DefaultPriority, artifact.MediumOCI, artifact.TypePlugin),
67+
Name: plugin.Name,
68+
}
69+
70+
// If not nil, set the values that are not empty.
71+
if plugin.Spec.Config != nil {
72+
if plugin.Spec.Config.InitConfig != nil {
73+
config.InitConfig = plugin.Spec.Config.InitConfig
74+
}
75+
if plugin.Spec.Config.LibraryPath != "" {
76+
config.LibraryPath = plugin.Spec.Config.LibraryPath
77+
}
78+
if plugin.Spec.Config.Name != "" {
79+
config.Name = plugin.Spec.Config.Name
80+
}
81+
if plugin.Spec.Config.OpenParams != "" {
82+
config.OpenParams = plugin.Spec.Config.OpenParams
83+
}
84+
}
85+
86+
// Check if the pluginConfig already exists in the list.
87+
for i, c := range pc.Configs {
88+
if c.isSame(&config) {
89+
// Remove the plugin from the list and add the current plugin.
90+
pc.Configs = append(pc.Configs[:i], pc.Configs[i+1:]...)
91+
break
92+
}
93+
}
94+
95+
// Add the plugin to the list if it doesn't exist.
96+
if len(pc.Configs) == 0 {
97+
pc.Configs = append(pc.Configs, config)
98+
} else {
99+
found := false
100+
for _, c := range pc.Configs {
101+
if c.Name == plugin.Name {
102+
found = true
103+
break
104+
}
105+
}
106+
if !found {
107+
pc.Configs = append(pc.Configs, config)
108+
}
109+
}
110+
111+
// Check if the plugin is already in the list.
112+
for _, c := range pc.LoadPlugins {
113+
if c == plugin.Name {
114+
return
115+
}
116+
}
117+
pc.LoadPlugins = append(pc.LoadPlugins, plugin.Name)
118+
}
119+
120+
func (pc *PluginsConfig) removeConfig(plugin *artifactv1alpha1.Plugin) {
121+
// Check if the pluginConfig already exists in the list.
122+
for i, c := range pc.Configs {
123+
if c.Name == plugin.Name {
124+
// Remove the plugin from the list.
125+
pc.Configs = append(pc.Configs[:i], pc.Configs[i+1:]...)
126+
break
127+
}
128+
}
129+
130+
// Check if the plugin is already in the list.
131+
for i, c := range pc.LoadPlugins {
132+
if c == plugin.Name {
133+
// Remove the plugin from the list.
134+
pc.LoadPlugins = append(pc.LoadPlugins[:i], pc.LoadPlugins[i+1:]...)
135+
break
136+
}
137+
}
138+
}
139+
140+
func (pc *PluginsConfig) toString() (string, error) {
141+
// Convert the struct to YAML.
142+
data, err := yaml.Marshal(pc)
143+
if err != nil {
144+
return "", err
145+
}
146+
return string(data), nil
147+
}
148+
149+
func (pc *PluginsConfig) isEmpty() bool {
150+
return len(pc.Configs) == 0 && len(pc.LoadPlugins) == 0
151+
}

0 commit comments

Comments
 (0)