Skip to content

Commit 3cceb1e

Browse files
Merge pull request #2010 from kaovilai/OADP-2765
OADP-2785: Add PriorityClassName support to PodConfig in DataProtectionApplication
2 parents 1036f58 + 13f9851 commit 3cceb1e

File tree

7 files changed

+151
-16
lines changed

7 files changed

+151
-16
lines changed

api/v1alpha1/dataprotectionapplication_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ type PodConfig struct {
391391
// env defines the list of environment variables to be supplied to podSpec
392392
// +optional
393393
Env []corev1.EnvVar `json:"env,omitempty"`
394+
// priorityClassName defines the PriorityClass name to be applied to the pod
395+
// +optional
396+
PriorityClassName string `json:"priorityClassName,omitempty"`
394397
}
395398

396399
type NodeAgentCommonFields struct {

bundle/manifests/oadp.openshift.io_dataprotectionapplications.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ spec:
539539
type: string
540540
description: nodeSelector defines the nodeSelector to be supplied to podSpec
541541
type: object
542+
priorityClassName:
543+
description: priorityClassName defines the PriorityClass name to be applied to the pod
544+
type: string
542545
resourceAllocations:
543546
description: resourceAllocations defines the CPU, Memory and ephemeral-storage resource allocations for the Pod
544547
nullable: true
@@ -893,6 +896,9 @@ spec:
893896
type: string
894897
description: nodeSelector defines the nodeSelector to be supplied to podSpec
895898
type: object
899+
priorityClassName:
900+
description: priorityClassName defines the PriorityClass name to be applied to the pod
901+
type: string
896902
resourceAllocations:
897903
description: resourceAllocations defines the CPU, Memory and ephemeral-storage resource allocations for the Pod
898904
nullable: true
@@ -1416,6 +1422,9 @@ spec:
14161422
type: string
14171423
description: nodeSelector defines the nodeSelector to be supplied to podSpec
14181424
type: object
1425+
priorityClassName:
1426+
description: priorityClassName defines the PriorityClass name to be applied to the pod
1427+
type: string
14191428
resourceAllocations:
14201429
description: resourceAllocations defines the CPU, Memory and ephemeral-storage resource allocations for the Pod
14211430
nullable: true

config/crd/bases/oadp.openshift.io_dataprotectionapplications.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ spec:
539539
type: string
540540
description: nodeSelector defines the nodeSelector to be supplied to podSpec
541541
type: object
542+
priorityClassName:
543+
description: priorityClassName defines the PriorityClass name to be applied to the pod
544+
type: string
542545
resourceAllocations:
543546
description: resourceAllocations defines the CPU, Memory and ephemeral-storage resource allocations for the Pod
544547
nullable: true
@@ -893,6 +896,9 @@ spec:
893896
type: string
894897
description: nodeSelector defines the nodeSelector to be supplied to podSpec
895898
type: object
899+
priorityClassName:
900+
description: priorityClassName defines the PriorityClass name to be applied to the pod
901+
type: string
896902
resourceAllocations:
897903
description: resourceAllocations defines the CPU, Memory and ephemeral-storage resource allocations for the Pod
898904
nullable: true
@@ -1416,6 +1422,9 @@ spec:
14161422
type: string
14171423
description: nodeSelector defines the nodeSelector to be supplied to podSpec
14181424
type: object
1425+
priorityClassName:
1426+
description: priorityClassName defines the PriorityClass name to be applied to the pod
1427+
type: string
14191428
resourceAllocations:
14201429
description: resourceAllocations defines the CPU, Memory and ephemeral-storage resource allocations for the Pod
14211430
nullable: true

internal/controller/nodeagent.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ func (r *DataProtectionApplicationReconciler) buildNodeAgentDaemonset(ds *appsv1
422422
install.WithNodeAgentConfigMap(configMapName),
423423
install.WithLabels(map[string]string{NodeAgentCMVersionLabel: configMapGeneration}),
424424
install.WithBackupRepoConfigMap(backupRepoConfigMapName),
425+
install.WithPriorityClassName(func() string {
426+
if dpa.Spec.Configuration.NodeAgent != nil && dpa.Spec.Configuration.NodeAgent.PodConfig != nil {
427+
return dpa.Spec.Configuration.NodeAgent.PodConfig.PriorityClassName
428+
}
429+
return ""
430+
}()),
425431
)
426432
ds.TypeMeta = installDs.TypeMeta
427433
var err error

internal/controller/nodeagent_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ type TestBuiltNodeAgentDaemonSetOptions struct {
256256
toleration []corev1.Toleration
257257
nodeSelector map[string]string
258258
disableFsBackup *bool
259+
priorityClassName string
259260
}
260261

261262
func createTestBuiltNodeAgentDaemonSet(options TestBuiltNodeAgentDaemonSetOptions) *appsv1.DaemonSet {
@@ -568,6 +569,10 @@ func createTestBuiltNodeAgentDaemonSet(options TestBuiltNodeAgentDaemonSetOption
568569
testBuiltNodeAgentDaemonSet.Spec.Template.Spec.Containers[0].Args = append(testBuiltNodeAgentDaemonSet.Spec.Template.Spec.Containers[0].Args, fmt.Sprintf("--log-format=%s", *options.logFormat))
569570
}
570571

572+
if len(options.priorityClassName) > 0 {
573+
testBuiltNodeAgentDaemonSet.Spec.Template.Spec.PriorityClassName = options.priorityClassName
574+
}
575+
571576
return testBuiltNodeAgentDaemonSet
572577
}
573578

@@ -707,6 +712,52 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) {
707712
annotations: map[string]string{"test-annotation": "awesome annotation"},
708713
}),
709714
},
715+
{
716+
name: "valid DPA CR with PodConfig PriorityClassName, NodeAgent DaemonSet is built with PriorityClassName",
717+
dpa: createTestDpaWith(
718+
nil,
719+
oadpv1alpha1.DataProtectionApplicationSpec{
720+
Configuration: &oadpv1alpha1.ApplicationConfig{
721+
Velero: &oadpv1alpha1.VeleroConfig{},
722+
NodeAgent: &oadpv1alpha1.NodeAgentConfig{
723+
NodeAgentCommonFields: oadpv1alpha1.NodeAgentCommonFields{
724+
PodConfig: &oadpv1alpha1.PodConfig{
725+
PriorityClassName: "node-agent-critical",
726+
},
727+
},
728+
UploaderType: "kopia",
729+
},
730+
},
731+
},
732+
),
733+
clientObjects: []client.Object{testGenericInfrastructure},
734+
nodeAgentDaemonSet: testNodeAgentDaemonSet.DeepCopy(),
735+
wantNodeAgentDaemonSet: createTestBuiltNodeAgentDaemonSet(TestBuiltNodeAgentDaemonSetOptions{
736+
priorityClassName: "node-agent-critical",
737+
}),
738+
},
739+
{
740+
name: "valid DPA CR with PodConfig but no PriorityClassName, NodeAgent DaemonSet is built without PriorityClassName",
741+
dpa: createTestDpaWith(
742+
nil,
743+
oadpv1alpha1.DataProtectionApplicationSpec{
744+
Configuration: &oadpv1alpha1.ApplicationConfig{
745+
Velero: &oadpv1alpha1.VeleroConfig{},
746+
NodeAgent: &oadpv1alpha1.NodeAgentConfig{
747+
NodeAgentCommonFields: oadpv1alpha1.NodeAgentCommonFields{
748+
PodConfig: &oadpv1alpha1.PodConfig{},
749+
},
750+
UploaderType: "kopia",
751+
},
752+
},
753+
},
754+
),
755+
clientObjects: []client.Object{testGenericInfrastructure},
756+
nodeAgentDaemonSet: testNodeAgentDaemonSet.DeepCopy(),
757+
wantNodeAgentDaemonSet: createTestBuiltNodeAgentDaemonSet(TestBuiltNodeAgentDaemonSetOptions{
758+
priorityClassName: "",
759+
}),
760+
},
710761
{
711762
name: "valid DPA CR with DataMoverPrepareTimeout, NodeAgent DaemonSet is built with DataMoverPrepareTimeout",
712763
dpa: createTestDpaWith(

internal/controller/velero.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ func (r *DataProtectionApplicationReconciler) buildVeleroDeployment(veleroDeploy
203203
// our secrets are appended to containers/volumeMounts in credentials.AppendPluginSpecificSpecs function
204204
install.WithSecret(false),
205205
install.WithServiceAccountName(common.Velero),
206+
install.WithPriorityClassName(func() string {
207+
if dpa.Spec.Configuration.Velero.PodConfig != nil {
208+
return dpa.Spec.Configuration.Velero.PodConfig.PriorityClassName
209+
}
210+
return ""
211+
}()),
206212
)
207213

208214
veleroDeploymentName := veleroDeployment.Name

internal/controller/velero_test.go

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -615,22 +615,23 @@ func createTestDpaWith(
615615
}
616616

617617
type TestBuiltVeleroDeploymentOptions struct {
618-
args []string
619-
customLabels map[string]string
620-
labels map[string]string
621-
annotations map[string]string
622-
metricsPort int
623-
initContainers []corev1.Container
624-
volumes []corev1.Volume
625-
volumeMounts []corev1.VolumeMount
626-
env []corev1.EnvVar
627-
dnsPolicy corev1.DNSPolicy
628-
dnsConfig *corev1.PodDNSConfig
629-
resourceLimits corev1.ResourceList
630-
resourceRequests corev1.ResourceList
631-
toleration []corev1.Toleration
632-
nodeSelector map[string]string
633-
loadAffinity []corev1.NodeSelectorTerm
618+
args []string
619+
customLabels map[string]string
620+
labels map[string]string
621+
annotations map[string]string
622+
metricsPort int
623+
initContainers []corev1.Container
624+
volumes []corev1.Volume
625+
volumeMounts []corev1.VolumeMount
626+
env []corev1.EnvVar
627+
dnsPolicy corev1.DNSPolicy
628+
dnsConfig *corev1.PodDNSConfig
629+
resourceLimits corev1.ResourceList
630+
resourceRequests corev1.ResourceList
631+
toleration []corev1.Toleration
632+
nodeSelector map[string]string
633+
loadAffinity []corev1.NodeSelectorTerm
634+
priorityClassName string
634635
}
635636

636637
func createTestBuiltVeleroDeployment(options TestBuiltVeleroDeploymentOptions) *appsv1.Deployment {
@@ -770,6 +771,10 @@ func createTestBuiltVeleroDeployment(options TestBuiltVeleroDeploymentOptions) *
770771
testBuiltVeleroDeployment.Spec.Template.Spec.DNSConfig = options.dnsConfig
771772
}
772773

774+
if len(options.priorityClassName) > 0 {
775+
testBuiltVeleroDeployment.Spec.Template.Spec.PriorityClassName = options.priorityClassName
776+
}
777+
773778
return testBuiltVeleroDeployment
774779
}
775780

@@ -1030,6 +1035,52 @@ func TestDPAReconciler_buildVeleroDeployment(t *testing.T) {
10301035
},
10311036
}),
10321037
},
1038+
{
1039+
name: "valid DPA CR with PodConfig PriorityClassName, Velero Deployment is built with PriorityClassName",
1040+
dpa: createTestDpaWith(
1041+
nil,
1042+
oadpv1alpha1.DataProtectionApplicationSpec{
1043+
Configuration: &oadpv1alpha1.ApplicationConfig{
1044+
Velero: &oadpv1alpha1.VeleroConfig{
1045+
PodConfig: &oadpv1alpha1.PodConfig{
1046+
PriorityClassName: "velero-critical",
1047+
},
1048+
},
1049+
},
1050+
},
1051+
),
1052+
veleroDeployment: testVeleroDeployment.DeepCopy(),
1053+
wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{
1054+
priorityClassName: "velero-critical",
1055+
args: []string{
1056+
defaultFileSystemBackupTimeout,
1057+
defaultRestoreResourcePriorities,
1058+
defaultDisableInformerCache,
1059+
},
1060+
}),
1061+
},
1062+
{
1063+
name: "valid DPA CR with PodConfig but no PriorityClassName, Velero Deployment is built without PriorityClassName",
1064+
dpa: createTestDpaWith(
1065+
nil,
1066+
oadpv1alpha1.DataProtectionApplicationSpec{
1067+
Configuration: &oadpv1alpha1.ApplicationConfig{
1068+
Velero: &oadpv1alpha1.VeleroConfig{
1069+
PodConfig: &oadpv1alpha1.PodConfig{},
1070+
},
1071+
},
1072+
},
1073+
),
1074+
veleroDeployment: testVeleroDeployment.DeepCopy(),
1075+
wantVeleroDeployment: createTestBuiltVeleroDeployment(TestBuiltVeleroDeploymentOptions{
1076+
priorityClassName: "",
1077+
args: []string{
1078+
defaultFileSystemBackupTimeout,
1079+
defaultRestoreResourcePriorities,
1080+
defaultDisableInformerCache,
1081+
},
1082+
}),
1083+
},
10331084
{
10341085
name: "valid DPA CR with noDefaultBackupLocation, all default plugins and unsupportedOverrides operatorType MTC, Velero Deployment is built with secret volumes",
10351086
dpa: createTestDpaWith(

0 commit comments

Comments
 (0)