Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed May 7, 2023
1 parent e5d9aa5 commit 6f78027
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
13 changes: 5 additions & 8 deletions api/v1/coherenceresourcespec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,8 @@ func (in *CoherenceResourceSpec) GetRestartPolicy() *corev1.RestartPolicy {
if in == nil {
return nil
}
if in.IsRunAsJob() {
if in.RestartPolicy == nil {
return in.RestartPolicyPointer(corev1.RestartPolicyNever)
}
if in.IsRunAsJob() && in.RestartPolicy == nil {
return in.RestartPolicyPointer(corev1.RestartPolicyNever)
}
return in.RestartPolicy
}
Expand Down Expand Up @@ -942,10 +940,9 @@ func (in *CoherenceResourceSpec) CreatePodTemplateSpec(deployment *Coherence) co
// append any additional Volumes
podTemplate.Spec.Volumes = append(podTemplate.Spec.Volumes, in.Volumes...)

if in.RestartPolicy != nil {
podTemplate.Spec.RestartPolicy = *in.RestartPolicy
} else if in.IsRunAsJob() {
podTemplate.Spec.RestartPolicy = corev1.RestartPolicyNever
restartPolicy := in.GetRestartPolicy()
if restartPolicy != nil {
podTemplate.Spec.RestartPolicy = *restartPolicy
}

// Add any ConfigMap Volumes
Expand Down
15 changes: 6 additions & 9 deletions api/v1/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func assertJob(t *testing.T, res coh.Resource, expected *batchv1.Job) {
assertEnvironmentVariablesForJob(t, stsActual, expected)

diffs := deep.Equal(*stsActual, *expected)
msg := "StatefulSets not equal:"
msg := "Jobs not equal:"
if len(diffs) > 0 {
// Dump the diffs
err = os.WriteFile(fmt.Sprintf("%s%c%s-Diff.txt", dir, os.PathSeparator, stsActual.Name), []byte(strings.Join(diffs, "\n")), os.ModePerm)
Expand Down Expand Up @@ -237,26 +237,23 @@ func createMinimalExpectedJob(deployment *coh.Coherence) *batchv1.Job {
spec := deployment.Spec
labels := deployment.CreateCommonLabels()
labels[coh.LabelComponent] = coh.LabelComponentCoherenceStatefulSet
selector := deployment.CreateCommonLabels()
selector[coh.LabelComponent] = coh.LabelComponentCoherencePod
podTemplate := createMinimalExpectedPodSpec(deployment)

sts := batchv1.Job{
podTemplate.Spec.RestartPolicy = corev1.RestartPolicyNever

job := batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: deployment.Name,
Labels: labels,
},
Spec: batchv1.JobSpec{
Parallelism: pointer.Int32(spec.GetReplicas()),
Selector: &metav1.LabelSelector{
MatchLabels: selector,
},
Template: podTemplate,
Template: podTemplate,
},
Status: batchv1.JobStatus{},
}

return &sts
return &job
}

// Create the expected default PodTemplateSpec for a spec with nothing but the minimal fields set.
Expand Down

0 comments on commit 6f78027

Please sign in to comment.