Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] Operator: RestartPolicy handling added #161

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crds/sme.sap.com_capapplications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
controller-gen.kubebuilder.io/version: v0.16.5
name: capapplications.sme.sap.com
spec:
group: sme.sap.com
Expand Down
6 changes: 5 additions & 1 deletion crds/sme.sap.com_capapplicationversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
controller-gen.kubebuilder.io/version: v0.16.5
name: capapplicationversions.sme.sap.com
spec:
group: sme.sap.com
Expand Down Expand Up @@ -1654,6 +1654,8 @@ spec:
x-kubernetes-int-or-string: true
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -3927,6 +3929,8 @@ spec:
x-kubernetes-int-or-string: true
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down
2 changes: 1 addition & 1 deletion crds/sme.sap.com_captenantoperations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
controller-gen.kubebuilder.io/version: v0.16.5
name: captenantoperations.sme.sap.com
spec:
group: sme.sap.com
Expand Down
2 changes: 1 addition & 1 deletion crds/sme.sap.com_captenantoutputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
controller-gen.kubebuilder.io/version: v0.16.5
name: captenantoutputs.sme.sap.com
spec:
group: sme.sap.com
Expand Down
2 changes: 1 addition & 1 deletion crds/sme.sap.com_captenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.4
controller-gen.kubebuilder.io/version: v0.16.5
name: captenants.sme.sap.com
spec:
group: sme.sap.com
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/reconcile-capapplicationversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func newContentDeploymentJob(cav *v1alpha1.CAPApplicationVersion, workload *v1al
ServiceAccountName: workload.JobDefinition.ServiceAccountName,
Volumes: workload.JobDefinition.Volumes,
ImagePullSecrets: convertToLocalObjectReferences(cav.Spec.RegistrySecrets),
RestartPolicy: corev1.RestartPolicyOnFailure,
RestartPolicy: getRestartPolicy(workload.JobDefinition.RestartPolicy, true),
NodeSelector: workload.JobDefinition.NodeSelector,
NodeName: workload.JobDefinition.NodeName,
PriorityClassName: workload.JobDefinition.PriorityClassName,
Expand Down Expand Up @@ -743,6 +743,7 @@ func createDeployment(params *DeploymentParameters) *appsv1.Deployment {
Affinity: params.WorkloadDetails.DeploymentDefinition.Affinity,
TopologySpreadConstraints: params.WorkloadDetails.DeploymentDefinition.TopologySpreadConstraints,
Tolerations: params.WorkloadDetails.DeploymentDefinition.Tolerations,
RestartPolicy: getRestartPolicy(params.WorkloadDetails.DeploymentDefinition.RestartPolicy, false),
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions internal/controller/reconcile-captenantoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type tentantOperationWorkload struct {
tolerations []corev1.Toleration
backoffLimit *int32
ttlSecondsAfterFinished *int32
restartPolicy corev1.RestartPolicy
}

const (
Expand Down Expand Up @@ -484,7 +485,7 @@ func (c *Controller) createTenantOperationJob(ctx context.Context, ctop *v1alpha
Annotations: params.annotations,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
RestartPolicy: getRestartPolicy(derivedWorkload.restartPolicy, true),
ImagePullSecrets: params.imagePullSecrets,
Containers: getContainers(ctop, derivedWorkload, workload, params),
InitContainers: *updateInitContainers(derivedWorkload.initContainers, getCTOPEnv(params, ctop, v1alpha1.JobTenantOperation), params.vcapSecretName),
Expand Down Expand Up @@ -574,6 +575,7 @@ func deriveWorkloadForTenantOperation(workload *v1alpha1.WorkloadDetails) tentan
if workload.JobDefinition.TTLSecondsAfterFinished != nil {
result.ttlSecondsAfterFinished = workload.JobDefinition.TTLSecondsAfterFinished
}
result.restartPolicy = workload.JobDefinition.RestartPolicy
result.affinity = workload.JobDefinition.Affinity
result.nodeSelector = workload.JobDefinition.NodeSelector
result.nodeName = workload.JobDefinition.NodeName
Expand Down Expand Up @@ -603,7 +605,7 @@ func (c *Controller) createCustomTenantOperationJob(ctx context.Context, ctop *v
Annotations: params.annotations,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
RestartPolicy: getRestartPolicy(workload.JobDefinition.RestartPolicy, true),
SecurityContext: workload.JobDefinition.PodSecurityContext,
Volumes: workload.JobDefinition.Volumes,
ServiceAccountName: workload.JobDefinition.ServiceAccountName,
Expand Down
7 changes: 7 additions & 0 deletions internal/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,10 @@ func updateInitContainers(initContainers []corev1.Container, additionalEnv []cor
func getWorkloadName(cavName, workloadName string) string {
return fmt.Sprintf("%s-%s", cavName, strings.ToLower(workloadName))
}

func getRestartPolicy(restartPolicy corev1.RestartPolicy, isJob bool) corev1.RestartPolicy {
if isJob && restartPolicy == "" {
return corev1.RestartPolicyNever
}
return restartPolicy
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down Expand Up @@ -128,7 +128,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/sme.sap.com/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ type CommonDetails struct {
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
// List of containers executed before the main container is started
InitContainers []corev1.Container `json:"initContainers,omitempty"`
// Restart policy for the Pod. See: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
RestartPolicy corev1.RestartPolicy `json:"restartPolicy,omitempty"`
}

// Configuration of Service Ports for the deployment
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading