diff --git a/api/falcon/v1alpha1/falconnodesensor_types.go b/api/falcon/v1alpha1/falconnodesensor_types.go index 15790fe1..dbfe1523 100644 --- a/api/falcon/v1alpha1/falconnodesensor_types.go +++ b/api/falcon/v1alpha1/falconnodesensor_types.go @@ -99,17 +99,9 @@ type FalconNodeSensorConfig struct { } type PriorityClassConfig struct { - // Enables the operator to deploy a PriorityClass instead of rolling your own. Default is false. - // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Deploy Priority Class to cluster",order=2 - Deploy *bool `json:"deploy,omitempty"` - // Name of the priority class to use for the DaemonSet. - // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Name of the Priority Class to use",order=2 + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Name of the Priority Class to use",order=1 Name string `json:"name,omitempty"` - - // Value of the priority class to use for the DaemonSet. Requires the Deploy field to be set to true. - // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Priority Class Value",order=3 - Value *int32 `json:"value,omitempty"` } type Resources struct { diff --git a/api/falcon/v1alpha1/zz_generated.deepcopy.go b/api/falcon/v1alpha1/zz_generated.deepcopy.go index 53d869ed..b92ff6a7 100644 --- a/api/falcon/v1alpha1/zz_generated.deepcopy.go +++ b/api/falcon/v1alpha1/zz_generated.deepcopy.go @@ -806,7 +806,7 @@ func (in *FalconNodeSensorConfig) DeepCopyInto(out *FalconNodeSensorConfig) { } out.SensorResources = in.SensorResources in.GKE.DeepCopyInto(&out.GKE) - in.PriorityClass.DeepCopyInto(&out.PriorityClass) + out.PriorityClass = in.PriorityClass if in.Version != nil { in, out := &in.Version, &out.Version *out = new(string) @@ -981,16 +981,6 @@ func (in *FalconSensor) DeepCopy() *FalconSensor { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PriorityClassConfig) DeepCopyInto(out *PriorityClassConfig) { *out = *in - if in.Deploy != nil { - in, out := &in.Deploy, &out.Deploy - *out = new(bool) - **out = **in - } - if in.Value != nil { - in, out := &in.Value, &out.Value - *out = new(int32) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PriorityClassConfig. diff --git a/config/crd/bases/falcon.crowdstrike.com_falconnodesensors.yaml b/config/crd/bases/falcon.crowdstrike.com_falconnodesensors.yaml index ea9da505..a034f55a 100644 --- a/config/crd/bases/falcon.crowdstrike.com_falconnodesensors.yaml +++ b/config/crd/bases/falcon.crowdstrike.com_falconnodesensors.yaml @@ -390,18 +390,9 @@ spec: description: Enable priority class for the DaemonSet. This is useful for GKE Autopilot clusters, but can be set for any cluster. properties: - deploy: - description: Enables the operator to deploy a PriorityClass - instead of rolling your own. Default is false. - type: boolean name: description: Name of the priority class to use for the DaemonSet. type: string - value: - description: Value of the priority class to use for the DaemonSet. - Requires the Deploy field to be set to true. - format: int32 - type: integer type: object resources: description: Configure resource requests and limits for the DaemonSet diff --git a/deploy/falcon-operator.yaml b/deploy/falcon-operator.yaml index 1567f09b..9ae4f853 100644 --- a/deploy/falcon-operator.yaml +++ b/deploy/falcon-operator.yaml @@ -2957,18 +2957,9 @@ spec: description: Enable priority class for the DaemonSet. This is useful for GKE Autopilot clusters, but can be set for any cluster. properties: - deploy: - description: Enables the operator to deploy a PriorityClass - instead of rolling your own. Default is false. - type: boolean name: description: Name of the priority class to use for the DaemonSet. type: string - value: - description: Value of the priority class to use for the DaemonSet. - Requires the Deploy field to be set to true. - format: int32 - type: integer type: object resources: description: Configure resource requests and limits for the DaemonSet diff --git a/internal/controller/assets/priorityclass.go b/internal/controller/assets/priorityclass.go deleted file mode 100644 index 290b40f2..00000000 --- a/internal/controller/assets/priorityclass.go +++ /dev/null @@ -1,29 +0,0 @@ -package assets - -import ( - "github.com/crowdstrike/falcon-operator/pkg/common" - schedulingv1 "k8s.io/api/scheduling/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func PriorityClass(name string, value *int32) *schedulingv1.PriorityClass { - defaultValue := int32(1000000000) - labels := common.CRLabels("priorityclass", name, common.FalconKernelSensor) - - if value == nil { - value = &defaultValue - } - - return &schedulingv1.PriorityClass{ - TypeMeta: metav1.TypeMeta{ - APIVersion: schedulingv1.SchemeGroupVersion.String(), - Kind: "PriorityClass", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Labels: labels, - }, - Description: "This priority class would be used to deploy CrowdStrike Falcon node sensor", - Value: *value, - } -} diff --git a/internal/controller/assets/priorityclass_test.go b/internal/controller/assets/priorityclass_test.go deleted file mode 100644 index e012fa43..00000000 --- a/internal/controller/assets/priorityclass_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package assets - -import ( - "testing" - - "github.com/crowdstrike/falcon-operator/pkg/common" - "github.com/google/go-cmp/cmp" - schedulingv1 "k8s.io/api/scheduling/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// TestPriorityClass tests the PriorityClass function -func TestPriorityClass(t *testing.T) { - name := "test" - value := int32(1000000000) - want := &schedulingv1.PriorityClass{ - TypeMeta: metav1.TypeMeta{ - APIVersion: schedulingv1.SchemeGroupVersion.String(), - Kind: "PriorityClass", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Labels: common.CRLabels("priorityclass", name, common.FalconKernelSensor), - }, - Description: "This priority class would be used to deploy CrowdStrike Falcon node sensor", - Value: value, - } - - // Test with nil value - got := PriorityClass(name, nil) - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("PriorityClass() mismatch (-want +got): %s", diff) - } - - // Test with defined value - got = PriorityClass(name, &value) - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("PriorityClass() mismatch (-want +got): %s", diff) - } -} diff --git a/internal/controller/falcon_node/falconnodesensor_controller.go b/internal/controller/falcon_node/falconnodesensor_controller.go index 32a2d97e..be09db65 100644 --- a/internal/controller/falcon_node/falconnodesensor_controller.go +++ b/internal/controller/falcon_node/falconnodesensor_controller.go @@ -15,7 +15,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" - schedulingv1 "k8s.io/api/scheduling/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" @@ -116,11 +115,6 @@ func (r *FalconNodeSensorReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{Requeue: true}, nil } - err = r.handlePriorityClass(ctx, nodesensor, logger) - if err != nil { - return ctrl.Result{}, err - } - serviceAccount := common.NodeServiceAccountName created, err = r.handlePermissions(ctx, nodesensor, logger) @@ -385,77 +379,6 @@ func (r *FalconNodeSensorReconciler) handleNamespace(ctx context.Context, nodese return true, nil } -// handlePriorityClass creates and updates the priority class -func (r *FalconNodeSensorReconciler) handlePriorityClass(ctx context.Context, nodesensor *falconv1alpha1.FalconNodeSensor, logger logr.Logger) error { - existingPC := &schedulingv1.PriorityClass{} - pcName := nodesensor.Spec.Node.PriorityClass.Name - update := false - - if pcName == "" && nodesensor.Spec.Node.GKE.Enabled == nil && nodesensor.Spec.Node.PriorityClass.Deploy == nil { - return nil - } else if pcName != "" && nodesensor.Spec.Node.PriorityClass.Deploy == nil && - (nodesensor.Spec.Node.GKE.Enabled != nil && *nodesensor.Spec.Node.GKE.Enabled) { - //logger.Info("Skipping PriorityClass creation on GKE AutoPilot because an existing priority class name was provided") - return nil - } else if pcName != "" && (nodesensor.Spec.Node.PriorityClass.Deploy == nil && !*nodesensor.Spec.Node.PriorityClass.Deploy) { - logger.Info("Skipping PriorityClass creation because an existing priority class name was provided") - return nil - } else if pcName == "" && (nodesensor.Spec.Node.GKE.Enabled != nil && *nodesensor.Spec.Node.GKE.Enabled) { - pcName = nodesensor.Name + "-priorityclass" - nodesensor.Spec.Node.PriorityClass.Name = pcName - } - - pc := assets.PriorityClass(pcName, nodesensor.Spec.Node.PriorityClass.Value) - - err := r.Get(ctx, types.NamespacedName{Name: pcName, Namespace: nodesensor.TargetNs()}, existingPC) - if err != nil && errors.IsNotFound(err) { - err = ctrl.SetControllerReference(nodesensor, pc, r.Scheme) - if err != nil { - logger.Error(err, "Unable to assign Controller Reference to the PriorityClass") - } - - err = r.Create(ctx, pc) - if err != nil { - logger.Error(err, "Failed to create PriorityClass", "PriorityClass.Name", pcName) - return err - } - logger.Info("Creating FalconNodeSensor PriorityClass") - - return nil - } else if err != nil { - logger.Error(err, "Failed to get FalconNodeSensor PriorityClass") - return err - } - - if nodesensor.Spec.Node.PriorityClass.Value != nil && existingPC.Value != *nodesensor.Spec.Node.PriorityClass.Value { - update = true - } - - if nodesensor.Spec.Node.PriorityClass.Name != "" && existingPC.Name != nodesensor.Spec.Node.PriorityClass.Name { - update = true - } - - if update { - err = r.Delete(ctx, existingPC) - if err != nil { - return err - } - - err = ctrl.SetControllerReference(nodesensor, pc, r.Scheme) - if err != nil { - logger.Error(err, "Unable to assign Controller Reference to the PriorityClass") - } - - err = r.Create(ctx, pc) - if err != nil { - return err - } - logger.Info("Updating FalconNodeSensor PriorityClass") - } - - return nil -} - // handleConfigMaps creates and updates the node sensor configmap func (r *FalconNodeSensorReconciler) handleConfigMaps(ctx context.Context, config *node.ConfigCache, nodesensor *falconv1alpha1.FalconNodeSensor, logger logr.Logger) (*corev1.ConfigMap, bool, error) { var updated bool