Add support for specifying priority class name for control plane components

Signed-off-by: Joe Nathan Abellard <contact@jabellard.com>
This commit is contained in:
Joe Nathan Abellard 2025-01-20 13:37:21 -05:00
parent 820fd06409
commit 954ee76365
18 changed files with 273 additions and 83 deletions

View File

@ -153,6 +153,12 @@ spec:
items:
type: string
type: array
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2465,6 +2471,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2625,6 +2637,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2776,6 +2794,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2900,6 +2924,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3024,6 +3054,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3156,6 +3192,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3280,6 +3322,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3404,6 +3452,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3574,6 +3628,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit

View File

@ -153,6 +153,12 @@ spec:
items:
type: string
type: array
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2465,6 +2471,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2625,6 +2637,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2776,6 +2794,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -2900,6 +2924,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3024,6 +3054,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3156,6 +3192,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3280,6 +3322,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3404,6 +3452,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit
@ -3574,6 +3628,12 @@ spec:
and services.
More info: http://kubernetes.io/docs/user-guide/labels
type: object
priorityClassName:
default: system-node-critical
description: |-
PriorityClassName specifies the priority class name for the component.
If not specified, it defaults to "system-node-critical".
type: string
replicas:
description: |-
Number of desired pods. This is a pointer to distinguish between explicit

View File

@ -648,6 +648,12 @@ type CommonSettings struct {
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// PriorityClassName specifies the priority class name for the component.
// If not specified, it defaults to "system-node-critical".
// +kubebuilder:default="system-node-critical"
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}
// Image allows to customize the image used for components.

View File

@ -79,6 +79,7 @@ func installKarmadaAPIServer(client clientset.Interface, cfg *operatorv1alpha1.K
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithExtraVolumeMounts(cfg.ExtraVolumeMounts).
WithExtraVolumes(cfg.ExtraVolumes).WithResources(cfg.Resources).ForDeployment(apiserverDeployment)
@ -143,6 +144,7 @@ func installKarmadaAggregatedAPIServer(client clientset.Interface, cfg *operator
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(aggregatedAPIServerDeployment)
if err := apiclient.CreateOrUpdateDeployment(client, aggregatedAPIServerDeployment); err != nil {

View File

@ -122,6 +122,7 @@ func TestInstallKarmadaAPIServer(t *testing.T) {
name := "karmada-apiserver"
namespace := "test-namespace"
serviceSubnet := "10.96.0.0/12"
priorityClassName := "system-cluster-critical"
// Create fake clientset.
fakeClient := fakeclientset.NewSimpleClientset()
@ -129,12 +130,13 @@ func TestInstallKarmadaAPIServer(t *testing.T) {
// Define a valid KarmadaAPIServer configuration.
cfg := &operatorv1alpha1.KarmadaAPIServer{
CommonSettings: operatorv1alpha1.CommonSettings{
Image: operatorv1alpha1.Image{ImageTag: image},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Image: operatorv1alpha1.Image{ImageTag: image},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ServiceSubnet: ptr.To(serviceSubnet),
ExtraArgs: map[string]string{"cmd1": "arg1", "cmd2": "arg2"},
@ -150,7 +152,7 @@ func TestInstallKarmadaAPIServer(t *testing.T) {
t.Fatalf("expected no error, but got: %v", err)
}
deployment, err := verifyDeploymentCreation(fakeClient, &replicas, imagePullPolicy, cfg.ExtraArgs, name, namespace, image, util.KarmadaAPIServerName(name))
deployment, err := verifyDeploymentCreation(fakeClient, &replicas, imagePullPolicy, cfg.ExtraArgs, name, namespace, image, util.KarmadaAPIServerName(name), priorityClassName)
if err != nil {
t.Fatalf("failed to verify karmada apiserver correct deployment creation correct details: %v", err)
}
@ -218,6 +220,7 @@ func TestInstallKarmadaAggregatedAPIServer(t *testing.T) {
labelValues := map[string]string{"labelKey": "labelValue"}
name := "test-agg-server"
namespace := "test-namespace"
priorityClassName := "system-cluster-critical"
// Use fake clientset.
fakeClient := fakeclientset.NewSimpleClientset()
@ -225,12 +228,13 @@ func TestInstallKarmadaAggregatedAPIServer(t *testing.T) {
// Define valid inputs.
cfg := &operatorv1alpha1.KarmadaAggregatedAPIServer{
CommonSettings: operatorv1alpha1.CommonSettings{
Image: operatorv1alpha1.Image{ImageTag: image},
Replicas: ptr.To[int32](replicas),
Annotations: annotationValues,
Labels: labelValues,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Image: operatorv1alpha1.Image{ImageTag: image},
Replicas: ptr.To[int32](replicas),
Annotations: annotationValues,
Labels: labelValues,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: map[string]string{"cmd1": "arg1", "cmd2": "arg2"},
}
@ -244,7 +248,7 @@ func TestInstallKarmadaAggregatedAPIServer(t *testing.T) {
t.Fatalf("Failed to install Karmada Aggregated API Server: %v", err)
}
deployment, err := verifyDeploymentCreation(fakeClient, &replicas, imagePullPolicy, cfg.ExtraArgs, name, namespace, image, util.KarmadaAggregatedAPIServerName(name))
deployment, err := verifyDeploymentCreation(fakeClient, &replicas, imagePullPolicy, cfg.ExtraArgs, name, namespace, image, util.KarmadaAggregatedAPIServerName(name), priorityClassName)
if err != nil {
t.Fatalf("failed to verify karmada aggregated apiserver deployment creation correct details: %v", err)
}
@ -311,7 +315,7 @@ func contains(slice []string, item string) bool {
// based on the given parameters. It ensures that the deployment has the correct
// number of replicas, image pull policy, extra arguments, and labels, as well
// as the correct image for the Karmada API server.
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas *int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, expectedDeploymentName string) (*appsv1.Deployment, error) {
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas *int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, expectedDeploymentName, priorityClassName string) (*appsv1.Deployment, error) {
// Assert that a Deployment was created.
actions := client.Actions()
if len(actions) != 1 {
@ -330,7 +334,7 @@ func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas *int32,
}
deployment := createAction.GetObject().(*appsv1.Deployment)
err := verifyDeploymentDetails(deployment, replicas, imagePullPolicy, extraArgs, name, namespace, image, expectedDeploymentName)
err := verifyDeploymentDetails(deployment, replicas, imagePullPolicy, extraArgs, name, namespace, image, expectedDeploymentName, priorityClassName)
if err != nil {
return nil, err
}
@ -341,11 +345,15 @@ func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas *int32,
// verifyDeploymentDetails ensures that the specified deployment contains the
// correct configuration for replicas, image pull policy, extra args, and image.
// It validates that the deployment matches the expected Karmada API server settings.
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas *int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, expectedDeploymentName string) error {
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas *int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, expectedDeploymentName, priorityClassName string) error {
if deployment.Name != expectedDeploymentName {
return fmt.Errorf("expected deployment name '%s', but got '%s'", expectedDeploymentName, deployment.Name)
}
if deployment.Spec.Template.Spec.PriorityClassName != priorityClassName {
return fmt.Errorf("expected priorityClassName to be set to %s, but got %s", priorityClassName, deployment.Spec.Template.Spec.PriorityClassName)
}
expectedNamespace := "test-namespace"
if deployment.Namespace != expectedNamespace {
return fmt.Errorf("expected deployment namespace '%s', but got '%s'", expectedNamespace, deployment.Namespace)

View File

@ -108,7 +108,6 @@ spec:
- mountPath: /etc/karmada/pki
name: apiserver-cert
readOnly: true
priorityClassName: system-node-critical
volumes:
- name: apiserver-cert
secret:

View File

@ -106,6 +106,7 @@ func getKubeControllerManagerManifest(name, namespace string, cfg *operatorv1alp
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithLabels(cfg.Labels).WithExtraArgs(cfg.ExtraArgs).WithResources(cfg.Resources).ForDeployment(kcm)
return kcm, nil
}
@ -134,6 +135,7 @@ func getKarmadaControllerManagerManifest(name, namespace string, featureGates ma
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(kcm)
return kcm, nil
}
@ -163,6 +165,7 @@ func getKarmadaSchedulerManifest(name, namespace string, featureGates map[string
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(scheduler)
return scheduler, nil
}
@ -192,6 +195,7 @@ func getKarmadaDeschedulerManifest(name, namespace string, featureGates map[stri
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithFeatureGates(featureGates).WithResources(cfg.Resources).ForDeployment(descheduler)
return descheduler, nil

View File

@ -135,6 +135,7 @@ func TestGetKubeControllerManagerManifest(t *testing.T) {
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
extraArgs := map[string]string{"cmd1": "arg1", "cmd2": "arg2"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KubeControllerManager{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -142,11 +143,12 @@ func TestGetKubeControllerManagerManifest(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: extraArgs,
}
@ -158,7 +160,7 @@ func TestGetKubeControllerManagerManifest(t *testing.T) {
deployment, _, err = verifyDeploymentDetails(
deployment, replicas, imagePullPolicy, extraArgs, namespace,
image, imageTag, util.KubeControllerManagerName(name),
image, imageTag, util.KubeControllerManagerName(name), priorityClassName,
)
if err != nil {
t.Errorf("failed to verify kube controller manager deployment details: %v", err)
@ -182,6 +184,7 @@ func TestGetKarmadaControllerManagerManifest(t *testing.T) {
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
extraArgs := map[string]string{"cmd1": "arg1", "cmd2": "arg2"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaControllerManager{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -189,10 +192,11 @@ func TestGetKarmadaControllerManagerManifest(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: extraArgs,
}
@ -206,7 +210,7 @@ func TestGetKarmadaControllerManagerManifest(t *testing.T) {
deployment, container, err := verifyDeploymentDetails(
deployment, replicas, imagePullPolicy, extraArgs, namespace,
image, imageTag, util.KarmadaControllerManagerName(name),
image, imageTag, util.KarmadaControllerManagerName(name), priorityClassName,
)
if err != nil {
t.Errorf("failed to verify karmada controller manager deployment details: %v", err)
@ -237,6 +241,7 @@ func TestGetKarmadaSchedulerManifest(t *testing.T) {
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
extraArgs := map[string]string{"cmd1": "arg1", "cmd2": "arg2"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaScheduler{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -244,11 +249,12 @@ func TestGetKarmadaSchedulerManifest(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: extraArgs,
}
@ -262,7 +268,7 @@ func TestGetKarmadaSchedulerManifest(t *testing.T) {
deployment, container, err := verifyDeploymentDetails(
deployment, replicas, imagePullPolicy, extraArgs, namespace,
image, imageTag, util.KarmadaSchedulerName(name),
image, imageTag, util.KarmadaSchedulerName(name), priorityClassName,
)
if err != nil {
t.Errorf("failed to verify karmada scheduler deployment details: %v", err)
@ -296,6 +302,7 @@ func TestGetKarmadaDeschedulerManifest(t *testing.T) {
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
extraArgs := map[string]string{"cmd1": "arg1", "cmd2": "arg2"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaDescheduler{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -303,11 +310,12 @@ func TestGetKarmadaDeschedulerManifest(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: extraArgs,
}
@ -321,7 +329,7 @@ func TestGetKarmadaDeschedulerManifest(t *testing.T) {
deployment, container, err := verifyDeploymentDetails(
deployment, replicas, imagePullPolicy, extraArgs, namespace,
image, imageTag, util.KarmadaDeschedulerName(name),
image, imageTag, util.KarmadaDeschedulerName(name), priorityClassName,
)
if err != nil {
t.Errorf("failed to verify karmada descheduler deployment details: %v", err)
@ -352,11 +360,15 @@ func TestGetKarmadaDeschedulerManifest(t *testing.T) {
// It validates that the deployment matches the expected Karmada Controlplane settings.
// It could be against Kube Controller Manager, Karmada Controller Manager, Karmada Scheduler,
// and Karmada Descheduler.
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, namespace, image, imageTag, expectedDeploymentName string) (*appsv1.Deployment, *corev1.Container, error) {
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, namespace, image, imageTag, expectedDeploymentName, priorityClassName string) (*appsv1.Deployment, *corev1.Container, error) {
if deployment.Name != expectedDeploymentName {
return nil, nil, fmt.Errorf("expected deployment name '%s', but got '%s'", expectedDeploymentName, deployment.Name)
}
if deployment.Spec.Template.Spec.PriorityClassName != priorityClassName {
return nil, nil, fmt.Errorf("expected priorityClassName to be set to %s, but got %s", priorityClassName, deployment.Spec.Template.Spec.PriorityClassName)
}
if deployment.Namespace != namespace {
return nil, nil, fmt.Errorf("expected deployment namespace '%s', but got '%s'", namespace, deployment.Namespace)
}

View File

@ -91,6 +91,7 @@ func installKarmadaEtcd(client clientset.Interface, name, namespace string, cfg
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithVolumeData(cfg.VolumeData).WithResources(cfg.Resources).ForStatefulSet(etcdStatefulSet)
if err := apiclient.CreateOrUpdateStatefulSet(client, etcdStatefulSet); err != nil {

View File

@ -79,6 +79,7 @@ func TestInstallKarmadaEtcd(t *testing.T) {
imagePullPolicy := corev1.PullIfNotPresent
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
priorityClassName := "system-cluster-critical"
// Define a valid Etcd configuration.
cfg := &operatorv1alpha1.LocalEtcd{
@ -87,11 +88,12 @@ func TestInstallKarmadaEtcd(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
}
@ -104,7 +106,7 @@ func TestInstallKarmadaEtcd(t *testing.T) {
}
err = verifyStatefulSetCreation(
fakeClient, replicas, imagePullPolicy, name, namespace, image, imageTag,
fakeClient, replicas, imagePullPolicy, name, namespace, image, imageTag, priorityClassName,
)
if err != nil {
t.Fatalf("failed to verify statefulset creation: %v", err)
@ -201,7 +203,7 @@ func TestCreateEtcdService(t *testing.T) {
// verifyStatefulSetCreation asserts that a StatefulSet was created in the given clientset.
// It checks that exactly one action was recorded, verifies that it is a creation action for a StatefulSet,
// and then validates the details of the created StatefulSet against the expected parameters.
func verifyStatefulSetCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, name, namespace, image, imageTag string) error {
func verifyStatefulSetCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, name, namespace, image, imageTag, priorityClassName string) error {
// Assert that a Statefulset was created.
actions := client.Actions()
if len(actions) != 1 {
@ -219,6 +221,11 @@ func verifyStatefulSetCreation(client *fakeclientset.Clientset, replicas int32,
}
statefulSet := createAction.GetObject().(*appsv1.StatefulSet)
if statefulSet.Spec.Template.Spec.PriorityClassName != priorityClassName {
return fmt.Errorf("expected priorityClassName to be set to %s, but got %s", priorityClassName, statefulSet.Spec.Template.Spec.PriorityClassName)
}
return verifyStatefulSetDetails(
statefulSet, replicas, imagePullPolicy, name, namespace, image, imageTag,
)

View File

@ -38,7 +38,6 @@ spec:
karmada-app: kube-controller-manager
spec:
automountServiceAccountToken: false
priorityClassName: system-node-critical
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:

View File

@ -63,7 +63,8 @@ func installKarmadaMetricAdapter(client clientset.Interface, cfg *operatorv1alph
return fmt.Errorf("err when decoding KarmadaMetricAdapter Deployment: %w", err)
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).WithResources(cfg.Resources).ForDeployment(metricAdapter)
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithResources(cfg.Resources).ForDeployment(metricAdapter)
if err := apiclient.CreateOrUpdateDeployment(client, metricAdapter); err != nil {
return fmt.Errorf("error when creating deployment for %s, err: %w", metricAdapter.Name, err)

View File

@ -38,6 +38,7 @@ func TestEnsureKarmadaMetricAdapter(t *testing.T) {
imagePullPolicy := corev1.PullIfNotPresent
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaMetricsAdapter{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -45,11 +46,12 @@ func TestEnsureKarmadaMetricAdapter(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
}
@ -75,6 +77,7 @@ func TestInstallKarmadaMetricAdapter(t *testing.T) {
imagePullPolicy := corev1.PullIfNotPresent
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaMetricsAdapter{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -82,11 +85,12 @@ func TestInstallKarmadaMetricAdapter(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
}
@ -99,7 +103,7 @@ func TestInstallKarmadaMetricAdapter(t *testing.T) {
}
err = verifyDeploymentCreation(
fakeClient, replicas, imagePullPolicy, name, namespace, image, imageTag,
fakeClient, replicas, imagePullPolicy, name, namespace, image, imageTag, priorityClassName,
)
if err != nil {
t.Fatalf("failed to verify deployment creation: %v", err)
@ -147,7 +151,7 @@ func TestCreateKarmadaMetricAdapterService(t *testing.T) {
}
}
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, name, namespace, image, imageTag string) error {
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, name, namespace, image, imageTag, priorityClassName string) error {
// Assert that a Deployment was created.
actions := client.Actions()
if len(actions) != 1 {
@ -166,17 +170,21 @@ func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, i
deployment := createAction.GetObject().(*appsv1.Deployment)
return verifyDeploymentDetails(
deployment, replicas, imagePullPolicy, name, namespace, image, imageTag,
deployment, replicas, imagePullPolicy, name, namespace, image, imageTag, priorityClassName,
)
}
// verifyDeploymentDetails validates the details of a Deployment against the expected parameters.
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, name, namespace, image, imageTag string) error {
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, name, namespace, image, imageTag, priorityClassName string) error {
expectedDeploymentName := util.KarmadaMetricsAdapterName(name)
if deployment.Name != expectedDeploymentName {
return fmt.Errorf("expected deployment name '%s', but got '%s'", expectedDeploymentName, deployment.Name)
}
if deployment.Spec.Template.Spec.PriorityClassName != priorityClassName {
return fmt.Errorf("expected priorityClassName to be set to %s, but got %s", priorityClassName, deployment.Spec.Template.Spec.PriorityClassName)
}
if deployment.Namespace != namespace {
return fmt.Errorf("expected deployment namespace '%s', but got '%s'", namespace, deployment.Namespace)
}

View File

@ -70,6 +70,7 @@ func installKarmadaSearch(client clientset.Interface, cfg *operatorv1alpha1.Karm
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithResources(cfg.Resources).ForDeployment(searchDeployment)
if err := apiclient.CreateOrUpdateDeployment(client, searchDeployment); err != nil {

View File

@ -78,6 +78,7 @@ func TestInstallKarmadaSearch(t *testing.T) {
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
extraArgs := map[string]string{"cmd1": "arg1", "cmd2": "arg2"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaSearch{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -85,11 +86,12 @@ func TestInstallKarmadaSearch(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: extraArgs,
}
@ -104,7 +106,7 @@ func TestInstallKarmadaSearch(t *testing.T) {
t.Fatalf("failed to install karmada search: %v", err)
}
err = verifyDeploymentCreation(fakeClient, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag)
err = verifyDeploymentCreation(fakeClient, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag, priorityClassName)
if err != nil {
t.Fatalf("failed to verify karmada search deployment creation: %v", err)
}
@ -152,7 +154,7 @@ func TestCreateKarmadaSearchService(t *testing.T) {
}
// verifyDeploymentCreation validates the details of a Deployment against the expected parameters.
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag string) error {
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag, priorityClassName string) error {
// Assert that a Deployment was created.
actions := client.Actions()
if len(actions) != 1 {
@ -170,16 +172,20 @@ func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, i
}
deployment := createAction.GetObject().(*appsv1.Deployment)
return verifyDeploymentDetails(deployment, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag)
return verifyDeploymentDetails(deployment, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag, priorityClassName)
}
// verifyDeploymentDetails validates the details of a Deployment against the expected parameters.
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag string) error {
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag, priorityClassName string) error {
expectedDeploymentName := util.KarmadaSearchName(name)
if deployment.Name != expectedDeploymentName {
return fmt.Errorf("expected deployment name '%s', but got '%s'", expectedDeploymentName, deployment.Name)
}
if deployment.Spec.Template.Spec.PriorityClassName != priorityClassName {
return fmt.Errorf("expected priorityClassName to be set to %s, but got %s", priorityClassName, deployment.Spec.Template.Spec.PriorityClassName)
}
if deployment.Namespace != namespace {
return fmt.Errorf("expected deployment namespace '%s', but got '%s'", namespace, deployment.Namespace)
}

View File

@ -64,6 +64,7 @@ func installKarmadaWebhook(client clientset.Interface, cfg *operatorv1alpha1.Kar
}
patcher.NewPatcher().WithAnnotations(cfg.Annotations).WithLabels(cfg.Labels).
WithPriorityClassName(cfg.CommonSettings.PriorityClassName).
WithExtraArgs(cfg.ExtraArgs).WithResources(cfg.Resources).ForDeployment(webhookDeployment)
if err := apiclient.CreateOrUpdateDeployment(client, webhookDeployment); err != nil {

View File

@ -75,6 +75,7 @@ func TestInstallKarmadaWebhook(t *testing.T) {
annotations := map[string]string{"annotationKey": "annotationValue"}
labels := map[string]string{"labelKey": "labelValue"}
extraArgs := map[string]string{"cmd1": "arg1", "cmd2": "arg2"}
priorityClassName := "system-cluster-critical"
cfg := &operatorv1alpha1.KarmadaWebhook{
CommonSettings: operatorv1alpha1.CommonSettings{
@ -82,11 +83,12 @@ func TestInstallKarmadaWebhook(t *testing.T) {
ImageRepository: image,
ImageTag: imageTag,
},
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
Replicas: ptr.To[int32](replicas),
Annotations: annotations,
Labels: labels,
Resources: corev1.ResourceRequirements{},
ImagePullPolicy: imagePullPolicy,
PriorityClassName: priorityClassName,
},
ExtraArgs: extraArgs,
}
@ -99,7 +101,7 @@ func TestInstallKarmadaWebhook(t *testing.T) {
t.Fatalf("failed to install karmada webhook: %v", err)
}
err = verifyDeploymentCreation(fakeClient, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag)
err = verifyDeploymentCreation(fakeClient, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag, priorityClassName)
if err != nil {
t.Fatalf("failed to verify karmada webhook deployment creation: %v", err)
}
@ -147,7 +149,7 @@ func TestCreateKarmadaWebhookService(t *testing.T) {
}
// verifyDeploymentCreation validates the details of a Deployment against the expected parameters.
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag string) error {
func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag, priorityClassName string) error {
// Assert that a Deployment was created.
actions := client.Actions()
if len(actions) != 1 {
@ -165,16 +167,20 @@ func verifyDeploymentCreation(client *fakeclientset.Clientset, replicas int32, i
}
deployment := createAction.GetObject().(*appsv1.Deployment)
return verifyDeploymentDetails(deployment, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag)
return verifyDeploymentDetails(deployment, replicas, imagePullPolicy, extraArgs, name, namespace, image, imageTag, priorityClassName)
}
// verifyDeploymentDetails validates the details of a Deployment against the expected parameters.
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag string) error {
func verifyDeploymentDetails(deployment *appsv1.Deployment, replicas int32, imagePullPolicy corev1.PullPolicy, extraArgs map[string]string, name, namespace, image, imageTag, priorityClassName string) error {
expectedDeploymentName := util.KarmadaWebhookName(name)
if deployment.Name != expectedDeploymentName {
return fmt.Errorf("expected deployment name '%s', but got '%s'", expectedDeploymentName, deployment.Name)
}
if deployment.Spec.Template.Spec.PriorityClassName != priorityClassName {
return fmt.Errorf("expected priorityClassName to be set to %s, but got %s", priorityClassName, deployment.Spec.Template.Spec.PriorityClassName)
}
if deployment.Namespace != namespace {
return fmt.Errorf("expected deployment namespace '%s', but got '%s'", namespace, deployment.Namespace)
}

View File

@ -35,6 +35,7 @@ import (
// Patcher defines multiple variables that need to be patched.
type Patcher struct {
priorityClassName string
labels map[string]string
annotations map[string]string
extraArgs map[string]string
@ -68,6 +69,12 @@ func (p *Patcher) WithExtraArgs(extraArgs map[string]string) *Patcher {
return p
}
// WithPriorityClassName sets the priority class name for the patcher.
func (p *Patcher) WithPriorityClassName(priorityClassName string) *Patcher {
p.priorityClassName = priorityClassName
return p
}
// WithExtraVolumes sets extra volumes for the patcher.
func (p *Patcher) WithExtraVolumes(extraVolumes []corev1.Volume) *Patcher {
p.extraVolumes = extraVolumes
@ -105,6 +112,7 @@ func (p *Patcher) ForDeployment(deployment *appsv1.Deployment) {
deployment.Annotations = labels.Merge(deployment.Annotations, p.annotations)
deployment.Spec.Template.Annotations = labels.Merge(deployment.Spec.Template.Annotations, p.annotations)
deployment.Spec.Template.Spec.PriorityClassName = p.priorityClassName
if p.resources.Size() > 0 {
// It's considered the first container is the karmada component by default.
@ -149,6 +157,7 @@ func (p *Patcher) ForStatefulSet(sts *appsv1.StatefulSet) {
sts.Annotations = labels.Merge(sts.Annotations, p.annotations)
sts.Spec.Template.Annotations = labels.Merge(sts.Spec.Template.Annotations, p.annotations)
sts.Spec.Template.Spec.PriorityClassName = p.priorityClassName
if p.volume != nil {
patchVolumeForStatefulSet(sts, p.volume)