Skip to content

Commit

Permalink
[Misc] Operator: priorityClassName and nodeName supported
Browse files Browse the repository at this point in the history
Add support for priorityClassName and nodeName for workloads

Change-Id: I9ceb2a548aa2493295ac0a05cc5995f9ddf9aa65
  • Loading branch information
Pavan-SAP committed Nov 28, 2023
1 parent fcb7b2e commit 15ab5b9
Show file tree
Hide file tree
Showing 13 changed files with 679 additions and 29 deletions.
36 changes: 18 additions & 18 deletions cmd/web-hooks/internal/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func createAdmissionRequest(operation admissionv1.Operation, crdType string, crd
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentCAP,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -191,7 +191,7 @@ func createAdmissionRequest(operation admissionv1.Operation, crdType string, crd
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentRouter,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -201,7 +201,7 @@ func createAdmissionRequest(operation admissionv1.Operation, crdType string, crd
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobContent,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand Down Expand Up @@ -897,7 +897,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentCAP,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -907,7 +907,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentRouter,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -917,7 +917,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobContent,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -933,7 +933,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentAdditional,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -949,7 +949,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentCAP,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -961,7 +961,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentRouter,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobCustomTenantOperation,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1001,7 +1001,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobTenantOperation,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1011,7 +1011,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobCustomTenantOperation,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1034,7 +1034,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobTenantOperation,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1057,7 +1057,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobTenantOperation,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1067,7 +1067,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobCustomTenantOperation,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand Down Expand Up @@ -1116,7 +1116,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobContent,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1127,7 +1127,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobContent,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand All @@ -1139,7 +1139,7 @@ func TestCavInvalidity(t *testing.T) {
ConsumedBTPServices: []string{},
JobDefinition: &v1alpha1.JobDetails{
Type: v1alpha1.JobContent,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "foo",
},
},
Expand Down
8 changes: 8 additions & 0 deletions crds/sme.sap.com_capapplicationversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ spec:
format: int32
type: integer
type: object
nodeName:
type: string
nodeSelector:
additionalProperties:
type: string
Expand Down Expand Up @@ -706,6 +708,8 @@ spec:
- port
type: object
type: array
priorityClassName:
type: string
readinessProbe:
properties:
exec:
Expand Down Expand Up @@ -1395,6 +1399,8 @@ spec:
type: string
imagePullPolicy:
type: string
nodeName:
type: string
nodeSelector:
additionalProperties:
type: string
Expand Down Expand Up @@ -1463,6 +1469,8 @@ spec:
type: string
type: object
type: object
priorityClassName:
type: string
resources:
properties:
claims:
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/reconcile-capapplicationversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func newContentDeploymentJob(ca *v1alpha1.CAPApplication, cav *v1alpha1.CAPAppli
ImagePullSecrets: convertToLocalObjectReferences(cav.Spec.RegistrySecrets),
RestartPolicy: corev1.RestartPolicyOnFailure,
NodeSelector: workload.JobDefinition.NodeSelector,
NodeName: workload.JobDefinition.NodeName,
PriorityClassName: workload.JobDefinition.PriorityClassName,
Affinity: workload.JobDefinition.Affinity,
TopologySpreadConstraints: workload.JobDefinition.TopologySpreadConstraints,
Tolerations: workload.JobDefinition.Tolerations,
Expand Down Expand Up @@ -593,6 +595,8 @@ func createDeployment(params *DeploymentParameters) *appsv1.Deployment {
Containers: getContainer(params),
SecurityContext: params.WorkloadDetails.DeploymentDefinition.PodSecurityContext,
NodeSelector: params.WorkloadDetails.DeploymentDefinition.NodeSelector,
NodeName: params.WorkloadDetails.DeploymentDefinition.NodeName,
PriorityClassName: params.WorkloadDetails.DeploymentDefinition.PriorityClassName,
Affinity: params.WorkloadDetails.DeploymentDefinition.Affinity,
TopologySpreadConstraints: params.WorkloadDetails.DeploymentDefinition.TopologySpreadConstraints,
Tolerations: params.WorkloadDetails.DeploymentDefinition.Tolerations,
Expand Down
20 changes: 20 additions & 0 deletions internal/controller/reconcile-capapplicationversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,23 @@ func TestCAV_Tolerations(t *testing.T) {
},
)
}

func TestCAV_Node_PriorityClass_Names(t *testing.T) {
reconcileTestItem(
context.TODO(), t,
QueueItem{Key: ResourceCAPApplicationVersion, ResourceKey: NamespacedResourceKey{Namespace: "default", Name: "test-cap-01-cav-v1"}},
TestData{
description: "capapplication version with nodeName and priorityClassName",
initialResources: []string{
"testdata/common/capapplication.yaml",
"testdata/common/credential-secrets.yaml",
"testdata/capapplicationversion/content-job-completed.yaml",
"testdata/capapplicationversion/cav-node-prio.yaml",
},
expectedResources: "testdata/capapplicationversion/expected/cav-ready-node-prio.yaml",
backlogItems: []string{
"ERP4SMEPREPWORKAPPPLAT-3294", // More workload configuration enhancements
},
},
)
}
10 changes: 10 additions & 0 deletions internal/controller/reconcile-captenantoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type tentantOperationWorkload struct {
podSecurityContext *corev1.PodSecurityContext
affinity *corev1.Affinity
nodeSelector map[string]string
nodeName string
priorityClassName string
topologySpreadConstraints []corev1.TopologySpreadConstraint
tolerations []corev1.Toleration
backoffLimit *int32
Expand Down Expand Up @@ -493,6 +495,8 @@ func (c *Controller) createTenantOperationJob(ctx context.Context, ctop *v1alpha
Containers: getContainers(payload, ctop, derivedWorkload, workload, params),
SecurityContext: derivedWorkload.podSecurityContext,
NodeSelector: derivedWorkload.nodeSelector,
NodeName: derivedWorkload.nodeName,
PriorityClassName: derivedWorkload.priorityClassName,
Affinity: derivedWorkload.affinity,
TopologySpreadConstraints: derivedWorkload.topologySpreadConstraints,
Tolerations: derivedWorkload.tolerations,
Expand Down Expand Up @@ -584,6 +588,8 @@ func deriveWorkloadForTenantOperation(workload *v1alpha1.WorkloadDetails) tentan
result.podSecurityContext = workload.DeploymentDefinition.PodSecurityContext
result.affinity = workload.DeploymentDefinition.Affinity
result.nodeSelector = workload.DeploymentDefinition.NodeSelector
result.nodeName = workload.DeploymentDefinition.NodeName
result.priorityClassName = workload.DeploymentDefinition.PriorityClassName
result.topologySpreadConstraints = workload.DeploymentDefinition.TopologySpreadConstraints
result.tolerations = workload.DeploymentDefinition.Tolerations
} else {
Expand All @@ -603,6 +609,8 @@ func deriveWorkloadForTenantOperation(workload *v1alpha1.WorkloadDetails) tentan
}
result.affinity = workload.JobDefinition.Affinity
result.nodeSelector = workload.JobDefinition.NodeSelector
result.nodeName = workload.JobDefinition.NodeName
result.priorityClassName = workload.JobDefinition.PriorityClassName
result.topologySpreadConstraints = workload.JobDefinition.TopologySpreadConstraints
result.tolerations = workload.JobDefinition.Tolerations
}
Expand Down Expand Up @@ -631,6 +639,8 @@ func (c *Controller) createCustomTenantOperationJob(ctx context.Context, ctop *v
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: workload.JobDefinition.PodSecurityContext,
NodeSelector: workload.JobDefinition.NodeSelector,
NodeName: workload.JobDefinition.NodeName,
PriorityClassName: workload.JobDefinition.PriorityClassName,
Affinity: workload.JobDefinition.Affinity,
TopologySpreadConstraints: workload.JobDefinition.TopologySpreadConstraints,
Tolerations: workload.JobDefinition.Tolerations,
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func createCavCRO(name string, state v1alpha1.CAPApplicationVersionState, versio
},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
Type: v1alpha1.DeploymentCAP,
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "test://image",
},
},
Expand All @@ -214,7 +214,7 @@ func createCavCRO(name string, state v1alpha1.CAPApplicationVersionState, versio
Name: "app-router",
ConsumedBTPServices: []string{},
DeploymentDefinition: &v1alpha1.DeploymentDetails{
ContainerDetails: v1alpha1.ContainerDetails{
CommonDetails: v1alpha1.CommonDetails{
Image: "test://image",
},
},
Expand Down
Loading

0 comments on commit 15ab5b9

Please sign in to comment.