Skip to content

Commit

Permalink
cleanup: remove priorityclass deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
redhatrises committed Jan 26, 2024
1 parent b434a53 commit 5651308
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 184 deletions.
10 changes: 1 addition & 9 deletions api/falcon/v1alpha1/falconnodesensor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 1 addition & 11 deletions api/falcon/v1alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions deploy/falcon-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions internal/controller/assets/priorityclass.go

This file was deleted.

40 changes: 0 additions & 40 deletions internal/controller/assets/priorityclass_test.go

This file was deleted.

77 changes: 0 additions & 77 deletions internal/controller/falcon_node/falconnodesensor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5651308

Please sign in to comment.