Skip to content

Commit

Permalink
Add pod priority support for broker, cruise control and envoy pods (#846
Browse files Browse the repository at this point in the history
)
  • Loading branch information
panyuenlau committed Aug 4, 2022
1 parent ecce211 commit d0c292f
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 6 deletions.
32 changes: 31 additions & 1 deletion api/v1beta1/kafkacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ type BrokerConfig struct {
// +kubebuilder:default=120
// +optional
TerminationGracePeriod *int64 `json:"terminationGracePeriodSeconds,omitempty"`
// PriorityClassName specifies the priority class name for a broker pod(s).
// If specified, the PriorityClass resource with this PriorityClassName must be created beforehand.
// If not specified, the broker pods' priority is default to zero.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}

type NetworkConfig struct {
Expand Down Expand Up @@ -257,6 +262,11 @@ type CruiseControlConfig struct {
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// SecurityContext allows to set security context for the CruiseControl container
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// PriorityClassName specifies the priority class name for the CruiseControl pod.
// If specified, the PriorityClass resource with this PriorityClassName must be created beforehand.
// If not specified, the CruiseControl pod's priority is default to zero.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}

// CruiseControlTaskSpec specifies the configuration of the CC Tasks
Expand Down Expand Up @@ -292,7 +302,7 @@ type EnvoyConfig struct {
// If specified and supported by the platform, traffic through the
// cloud-provider load-balancer will be restricted to the specified client
// IPs. This field will be ignored if the
// cloud-provider does not support the feature."
// cloud-provider does not support the feature.
// More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/
LoadBalancerSourceRanges []string `json:"loadBalancerSourceRanges,omitempty"`
// LoadBalancerIP can be used to specify an exact IP for the LoadBalancer service
Expand All @@ -307,6 +317,11 @@ type EnvoyConfig struct {
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
CommandLineArgs *EnvoyCommandLineArgs `json:"envoyCommandLineArgs,omitempty"`
// PriorityClassName specifies the priority class name for the Envoy pod(s)
// If specified, the PriorityClass resource with this PriorityClassName must be created beforehand
// If not specified, the Envoy pods' priority is default to zero
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}

// EnvoyCommandLineArgs defines envoy command line arguments
Expand Down Expand Up @@ -790,11 +805,21 @@ func (eConfig *EnvoyConfig) GetTopologySpreadConstaints() []corev1.TopologySprea
return eConfig.TopologySpreadConstraints
}

// GetPriorityClassName returns the priority class name for envoy
func (eConfig *EnvoyConfig) GetPriorityClassName() string {
return eConfig.PriorityClassName
}

// GetNodeSelector returns the node selector for the given broker
func (bConfig *BrokerConfig) GetNodeSelector() map[string]string {
return bConfig.NodeSelector
}

// GetPriorityClassName returns the priority class name for the given broker
func (bConfig *BrokerConfig) GetPriorityClassName() string {
return bConfig.PriorityClassName
}

// GetImagePullSecrets returns the list of Secrets needed to pull Containers images from private repositories
func (bConfig *BrokerConfig) GetImagePullSecrets() []corev1.LocalObjectReference {
return bConfig.ImagePullSecrets
Expand Down Expand Up @@ -829,6 +854,11 @@ func (cConfig *CruiseControlConfig) GetImagePullSecrets() []corev1.LocalObjectRe
return cConfig.ImagePullSecrets
}

// GetPriorityClassName returns the priority class name for the CruiseControl pod
func (cConfig *CruiseControlConfig) GetPriorityClassName() string {
return cConfig.PriorityClassName
}

// GetResources returns the envoy specific Kubernetes resource
func (eConfig *EnvoyConfig) GetResources() *corev1.ResourceRequirements {
if eConfig.Resources != nil {
Expand Down
38 changes: 36 additions & 2 deletions charts/kafka-operator/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3889,6 +3889,13 @@ spec:
type: string
type: object
type: object
priorityClassName:
description: PriorityClassName specifies the priority class
name for a broker pod(s). If specified, the PriorityClass
resource with this PriorityClassName must be created beforehand.
If not specified, the broker pods' priority is default to
zero.
type: string
resourceRequirements:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -10014,6 +10021,13 @@ spec:
type: string
type: object
type: object
priorityClassName:
description: PriorityClassName specifies the priority class
name for a broker pod(s). If specified, the PriorityClass
resource with this PriorityClassName must be created beforehand.
If not specified, the broker pods' priority is default
to zero.
type: string
resourceRequirements:
description: ResourceRequirements describes the compute
resource requirements.
Expand Down Expand Up @@ -13747,6 +13761,12 @@ spec:
type: string
type: object
type: object
priorityClassName:
description: PriorityClassName specifies the priority class name
for the CruiseControl pod. If specified, the PriorityClass resource
with this PriorityClassName must be created beforehand. If not
specified, the CruiseControl pod's priority is default to zero.
type: string
resourceRequirements:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -16568,7 +16588,7 @@ spec:
description: 'If specified and supported by the platform, traffic
through the cloud-provider load-balancer will be restricted
to the specified client IPs. This field will be ignored if the
cloud-provider does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
cloud-provider does not support the feature. More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
items:
type: string
type: array
Expand All @@ -16578,6 +16598,12 @@ spec:
description: NodeSelector is the node selector expression for
envoy pods
type: object
priorityClassName:
description: PriorityClassName specifies the priority class name
for the Envoy pod(s) If specified, the PriorityClass resource
with this PriorityClassName must be created beforehand If not
specified, the Envoy pods' priority is default to zero
type: string
replicas:
format: int32
minimum: 1
Expand Down Expand Up @@ -18575,7 +18601,7 @@ spec:
load-balancer will be restricted to the
specified client IPs. This field will be
ignored if the cloud-provider does not support
the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
the feature. More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
items:
type: string
type: array
Expand All @@ -18585,6 +18611,14 @@ spec:
description: NodeSelector is the node selector
expression for envoy pods
type: object
priorityClassName:
description: PriorityClassName specifies the
priority class name for the Envoy pod(s)
If specified, the PriorityClass resource
with this PriorityClassName must be created
beforehand If not specified, the Envoy pods'
priority is default to zero
type: string
replicas:
format: int32
minimum: 1
Expand Down
38 changes: 36 additions & 2 deletions config/base/crds/kafka.banzaicloud.io_kafkaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3888,6 +3888,13 @@ spec:
type: string
type: object
type: object
priorityClassName:
description: PriorityClassName specifies the priority class
name for a broker pod(s). If specified, the PriorityClass
resource with this PriorityClassName must be created beforehand.
If not specified, the broker pods' priority is default to
zero.
type: string
resourceRequirements:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -10013,6 +10020,13 @@ spec:
type: string
type: object
type: object
priorityClassName:
description: PriorityClassName specifies the priority class
name for a broker pod(s). If specified, the PriorityClass
resource with this PriorityClassName must be created beforehand.
If not specified, the broker pods' priority is default
to zero.
type: string
resourceRequirements:
description: ResourceRequirements describes the compute
resource requirements.
Expand Down Expand Up @@ -13746,6 +13760,12 @@ spec:
type: string
type: object
type: object
priorityClassName:
description: PriorityClassName specifies the priority class name
for the CruiseControl pod. If specified, the PriorityClass resource
with this PriorityClassName must be created beforehand. If not
specified, the CruiseControl pod's priority is default to zero.
type: string
resourceRequirements:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -16567,7 +16587,7 @@ spec:
description: 'If specified and supported by the platform, traffic
through the cloud-provider load-balancer will be restricted
to the specified client IPs. This field will be ignored if the
cloud-provider does not support the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
cloud-provider does not support the feature. More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
items:
type: string
type: array
Expand All @@ -16577,6 +16597,12 @@ spec:
description: NodeSelector is the node selector expression for
envoy pods
type: object
priorityClassName:
description: PriorityClassName specifies the priority class name
for the Envoy pod(s) If specified, the PriorityClass resource
with this PriorityClassName must be created beforehand If not
specified, the Envoy pods' priority is default to zero
type: string
replicas:
format: int32
minimum: 1
Expand Down Expand Up @@ -18574,7 +18600,7 @@ spec:
load-balancer will be restricted to the
specified client IPs. This field will be
ignored if the cloud-provider does not support
the feature." More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
the feature. More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/'
items:
type: string
type: array
Expand All @@ -18584,6 +18610,14 @@ spec:
description: NodeSelector is the node selector
expression for envoy pods
type: object
priorityClassName:
description: PriorityClassName specifies the
priority class name for the Envoy pod(s)
If specified, the PriorityClass resource
with this PriorityClassName must be created
beforehand If not specified, the Envoy pods'
priority is default to zero
type: string
replicas:
format: int32
minimum: 1
Expand Down
9 changes: 9 additions & 0 deletions config/samples/banzaicloud_v1beta1_kafkacluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ spec:
# Add custom labels to broker pods within the config group
# brokerLabels:
# kafka_broker_group: "default_group"
# priorityClassName can be used to set the priority of broker pods that use this config group
# note that the corresponding PriorityClass must be created beforehand
# priorityClassName: "high-priority"
# All Broker requires an image, unique id, and storageConfigs settings
brokers:
# Unique broker id which is used as kafka config broker.id
Expand Down Expand Up @@ -102,6 +105,8 @@ spec:
# tolerations:
# config parameter can be used to pass Kafka config https://kafka.apache.org/documentation/#brokerconfigs
# which has type per-broker
# priorityClassName can be used to set the broker pod's priority
# priorityClassName: "high-priority"
config: |
sasl.enabled.mechanisms=PLAIN
# serviceAccountName specifies the serviceAccount used for this specific broker
Expand Down Expand Up @@ -235,6 +240,8 @@ spec:
# replicas: 1
# image describes the Envoy docker image
# image: "banzaicloud/envoy:0.1.0"
# priorityClassName can be used to set the envoy pod's priority
# priorityClassName: "moderate-priority"
# resourceRequirements works exactly like Container resources, the user can specify the limit and the requests
# through this property
# resourceRequirements:
Expand Down Expand Up @@ -365,6 +372,8 @@ spec:
cruiseControlConfig:
# image describes the CC docker image
#image: "solsson/kafka-cruise-control@sha256:c70eae329b4ececba58e8cf4fa6e774dd2e0205988d8e5be1a70e622fcc46716"
# priorityClassName can be used to set the cruise control pod's priority
# priorityClassName: "low-priority"
# CruiseControlEndpoint describes the endpoint where the already running CC is accessable. If set the Operator will not
# try to install one
#cruiseControlEndpoint: "localhost:8090"
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/cruisecontrol/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ fi`},
},
},
}...),
PriorityClassName: r.KafkaCluster.Spec.CruiseControlConfig.GetPriorityClassName(),
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/envoy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func (r *Reconciler) deployment(log logr.Logger, extListener v1beta1.ExternalLis
Resources: *ingressConfig.EnvoyConfig.GetResources(),
},
},
Volumes: volumes,
Volumes: volumes,
PriorityClassName: ingressConfig.EnvoyConfig.GetPriorityClassName(),
},
},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/kafka/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fi`},
ServiceAccountName: brokerConfig.GetServiceAccount(),
Tolerations: brokerConfig.GetTolerations(),
NodeSelector: brokerConfig.GetNodeSelector(),
PriorityClassName: brokerConfig.GetPriorityClassName(),
},
}
if r.KafkaCluster.Spec.HeadlessServiceEnabled {
Expand Down

0 comments on commit d0c292f

Please sign in to comment.