Skip to content

Commit

Permalink
Use RestartPolicy: Never for the jobs
Browse files Browse the repository at this point in the history
With RestartPolicy: OnFailure new pods are not created[1], but
the containers in esiting pod are restarted. We were using
RestartPolicy: Never with openstack-ansibleee-operator. This
was changed when we switched to drop it's usage.

[1] https://kubernetes.io/docs/concepts/workloads/controllers/job/#handling-pod-and-container-failures

Signed-off-by: rabi <[email protected]>
  • Loading branch information
rabi committed Sep 18, 2024
1 parent 749d164 commit 5021b09
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 59 deletions.
10 changes: 3 additions & 7 deletions pkg/dataplane/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (d *Deployer) ConditionalDeploy(

}

var ansibleCondition *batchv1.JobCondition
if nsConditions.IsFalse(readyCondition) {
var ansibleEE *batchv1.Job
_, labelSelector := dataplaneutil.GetAnsibleExecutionNameAndLabels(&foundService, d.Deployment.Name, d.NodeSet.Name)
Expand All @@ -221,19 +222,14 @@ func (d *Deployer) ConditionalDeploy(
nsConditions.Set(condition.TrueCondition(
readyCondition,
readyMessage))
}

if ansibleEE.Status.Active > 0 {
} else if ansibleEE.Status.Active > 0 {
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Active pods: %d", ansibleEE.Name, ansibleEE.Status.Active))
nsConditions.Set(condition.FalseCondition(
readyCondition,
condition.RequestedReason,
condition.SeverityInfo,
readyWaitingMessage))
}

var ansibleCondition *batchv1.JobCondition
if ansibleEE.Status.Failed > 0 {
} else if ansibleEE.Status.Failed > 0 {
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s failed pods: %d", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.Failed)
for _, condition := range ansibleEE.Status.Conditions {
if condition.Type == batchv1.JobFailed {
Expand Down
3 changes: 0 additions & 3 deletions pkg/dataplane/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ func (a *EEJob) BuildAeeJobSpec(
service *dataplanev1.OpenStackDataPlaneService,
nodeSet client.Object,
) {
const jobRestartPolicy string = "OnFailure"

if aeeSpec.DNSConfig != nil {
a.DNSConfig = aeeSpec.DNSConfig
}
Expand All @@ -195,7 +193,6 @@ func (a *EEJob) BuildAeeJobSpec(
}

a.BackoffLimit = deployment.Spec.BackoffLimit
a.RestartPolicy = jobRestartPolicy
a.FormatAEECmdLineArguments(aeeSpec)
a.FormatAEEExtraVars(aeeSpec, service, deployment, nodeSet)
a.DetermineAeeImage(aeeSpec)
Expand Down
7 changes: 2 additions & 5 deletions pkg/dataplane/util/ansibleee.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ type EEJob struct {
Namespace string `json:"namespace,omitempty"`
// EnvConfigMapName is the name of the k8s config map that contains the ansible env variables
EnvConfigMapName string `json:"envConfigMapName,omitempty"`
// RestartPolicy is the policy applied to the Job on whether it needs to restart the Pod. It can be "OnFailure" or "Never".
// RestartPolicy default: Never
RestartPolicy string `json:"restartPolicy,omitempty"`
// CmdLine is the command line passed to ansible-runner
CmdLine string `json:"cmdLine,omitempty"`
// ServiceAccountName allows to specify what ServiceAccountName do we want the ansible execution run with. Without specifying,
Expand Down Expand Up @@ -103,9 +100,9 @@ func (a *EEJob) JobForOpenStackAnsibleEE(h *helper.Helper) (*batchv1.Job, error)
}

podSpec := corev1.PodSpec{
RestartPolicy: corev1.RestartPolicy(a.RestartPolicy),
RestartPolicy: corev1.RestartPolicyNever,
Containers: []corev1.Container{{
ImagePullPolicy: "Always",
ImagePullPolicy: corev1.PullAlways,
Image: a.Image,
Name: a.Name,
Args: args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ spec:
- mountPath: /runner/inventory/inventory-0
name: inventory-0
subPath: inventory-0
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -258,7 +258,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -365,7 +365,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -473,7 +473,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -581,7 +581,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -689,7 +689,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -797,7 +797,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -899,7 +899,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -1017,7 +1017,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -1147,7 +1147,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -1256,7 +1256,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -1365,7 +1365,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -1474,7 +1474,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down Expand Up @@ -1592,7 +1592,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-beta-nodeset
Expand Down Expand Up @@ -255,7 +255,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-beta-nodeset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: openstack-edpm-tls
Expand Down Expand Up @@ -313,7 +313,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: openstack-edpm-tls
Expand Down
26 changes: 13 additions & 13 deletions tests/kuttl/tests/dataplane-deploy-no-nodes-test/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -252,7 +252,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -361,7 +361,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -470,7 +470,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -579,7 +579,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -688,7 +688,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -791,7 +791,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -910,7 +910,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -1041,7 +1041,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -1151,7 +1151,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -1261,7 +1261,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -1371,7 +1371,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down Expand Up @@ -1490,7 +1490,7 @@ spec:
- mountPath: /runner/inventory/hosts
name: inventory
subPath: inventory
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ spec:
name: inventory
subPath: inventory
dnsPolicy: ClusterFirst
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ spec:
name: inventory
subPath: inventory
dnsPolicy: ClusterFirst
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-no-nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ spec:
name: inventory
subPath: inventory
dnsPolicy: ClusterFirst
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-beta-nodeset
Expand Down Expand Up @@ -256,7 +256,7 @@ spec:
name: inventory
subPath: inventory
dnsPolicy: ClusterFirst
restartPolicy: OnFailure
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
serviceAccount: edpm-compute-beta-nodeset
Expand Down
Loading

0 comments on commit 5021b09

Please sign in to comment.