Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: create a common label function #379

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/common/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,15 @@ func MapCopy(src map[string]string, dst map[string]string) map[string]string {
}
return dst
}

func CRLabels(instanceName string, instanceKey string, component string) map[string]string {
return map[string]string{
FalconInstanceNameKey: instanceName,
FalconInstanceKey: instanceKey,
FalconComponentKey: component,
FalconManagedByKey: FalconManagedByValue,
FalconProviderKey: FalconProviderValue,
FalconPartOfKey: FalconPartOfValue,
FalconCreatedKey: FalconCreatedValue,
}
}
10 changes: 1 addition & 9 deletions pkg/node/assets/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ func DaemonsetConfigMap(dsname string, nsname string, config *node.ConfigCache)
ObjectMeta: metav1.ObjectMeta{
Name: dsname,
Namespace: nsname,
Labels: map[string]string{
common.FalconInstanceNameKey: "configmap",
common.FalconInstanceKey: dsname,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("configmap", dsname, common.FalconKernelSensor),
},
Data: config.SensorEnvVars(),
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/node/assets/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ func TestDaemonsetConfigMap(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: cfgName,
Namespace: cfgName,
Labels: map[string]string{
common.FalconInstanceNameKey: "configmap",
common.FalconInstanceKey: cfgName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("configmap", cfgName, common.FalconKernelSensor),
},
Data: map[string]string{
"FALCONCTL_OPT_CID": "1234567890ABCDEF1234567890ABCDEF-12",
Expand Down
60 changes: 6 additions & 54 deletions pkg/node/assets/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,16 @@ func Daemonset(dsName, image, serviceAccount string, node *falconv1alpha1.Falcon
ObjectMeta: metav1.ObjectMeta{
Name: dsName,
Namespace: node.TargetNs(),
Labels: map[string]string{
common.FalconInstanceNameKey: "daemonset",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("daemonset", dsName, common.FalconKernelSensor),
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
common.FalconInstanceNameKey: "daemonset",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
MatchLabels: common.CRLabels("daemonset", dsName, common.FalconKernelSensor),
},
UpdateStrategy: dsUpdateStrategy(node),
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
common.FalconInstanceNameKey: "daemonset",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("daemonset", dsName, common.FalconKernelSensor),
Annotations: map[string]string{
common.FalconContainerInjection: "disabled",
},
Expand Down Expand Up @@ -211,39 +187,15 @@ func RemoveNodeDirDaemonset(dsName, image, serviceAccount string, node *falconv1
ObjectMeta: metav1.ObjectMeta{
Name: dsName,
Namespace: node.TargetNs(),
Labels: map[string]string{
common.FalconInstanceNameKey: "cleanup",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("cleanup", dsName, common.FalconKernelSensor),
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
common.FalconInstanceNameKey: "cleanup",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
MatchLabels: common.CRLabels("cleanup", dsName, common.FalconKernelSensor),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
common.FalconInstanceNameKey: "cleanup",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("cleanup", dsName, common.FalconKernelSensor),
Annotations: map[string]string{
common.FalconContainerInjection: "disabled",
},
Expand Down
62 changes: 7 additions & 55 deletions pkg/node/assets/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,16 @@ func TestDaemonset(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: dsName,
Namespace: falconNode.Namespace,
Labels: map[string]string{
common.FalconInstanceNameKey: "daemonset",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("daemonset", dsName, common.FalconKernelSensor),
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
common.FalconInstanceNameKey: "daemonset",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
MatchLabels: common.CRLabels("daemonset", dsName, common.FalconKernelSensor),
},
UpdateStrategy: dsUpdateStrategy(&falconNode),
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
common.FalconInstanceNameKey: "daemonset",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("daemonset", dsName, common.FalconKernelSensor),
Annotations: map[string]string{"sensor.falcon-system.crowdstrike.com/injection": "disabled"},
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -288,40 +264,16 @@ func TestRemoveNodeDirDaemonset(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: dsName,
Namespace: falconNode.Namespace,
Labels: map[string]string{
common.FalconInstanceNameKey: "cleanup",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Labels: common.CRLabels("cleanup", dsName, common.FalconKernelSensor),
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
common.FalconInstanceNameKey: "cleanup",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
MatchLabels: common.CRLabels("cleanup", dsName, common.FalconKernelSensor),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
common.FalconInstanceNameKey: "cleanup",
common.FalconInstanceKey: dsName,
common.FalconComponentKey: common.FalconKernelSensor,
common.FalconManagedByKey: common.FalconManagedByValue,
common.FalconProviderKey: common.FalconProviderValue,
common.FalconPartOfKey: common.FalconPartOfValue,
common.FalconCreatedKey: common.FalconCreatedValue,
},
Annotations: map[string]string{"sensor.falcon-system.crowdstrike.com/injection": "disabled"},
Labels: common.CRLabels("cleanup", dsName, common.FalconKernelSensor),
Annotations: map[string]string{common.FalconContainerInjection: "disabled"},
},
Spec: corev1.PodSpec{
// NodeSelector is set to linux until windows containers are supported for the Falcon sensor
Expand Down