Skip to content

Commit f6e439d

Browse files
committed
Make SparkApplication.Spec.Suspend be a pointer
Signed-off-by: Shingo Omura <[email protected]>
1 parent 0f79646 commit f6e439d

9 files changed

+23
-17
lines changed

api/v1beta2/sparkapplication_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type SparkApplicationSpec struct {
4141
// (i.e. the flag goes from false to true), the Spark operator will delete
4242
// all active Pods associated with this SparkApplication.
4343
// Users must design their Spark application to gracefully handle this.
44-
Suspend bool `json:"suspend"`
44+
Suspend *bool `json:"suspend,omitempty"`
4545
// Type tells the type of the Spark application.
4646
// +kubebuilder:validation:Enum={Java,Python,Scala,R}
4747
Type SparkApplicationType `json:"type"`

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/spark-operator-chart/crds/sparkoperator.k8s.io_scheduledsparkapplications.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12409,7 +12409,6 @@ spec:
1240912409
- executor
1241012410
- mainApplicationFile
1241112411
- sparkVersion
12412-
- suspend
1241312412
- type
1241412413
type: object
1241512414
timeZone:

charts/spark-operator-chart/crds/sparkoperator.k8s.io_sparkapplications.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12323,7 +12323,6 @@ spec:
1232312323
- executor
1232412324
- mainApplicationFile
1232512325
- sparkVersion
12326-
- suspend
1232712326
- type
1232812327
type: object
1232912328
status:

config/crd/bases/sparkoperator.k8s.io_scheduledsparkapplications.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12409,7 +12409,6 @@ spec:
1240912409
- executor
1241012410
- mainApplicationFile
1241112411
- sparkVersion
12412-
- suspend
1241312412
- type
1241412413
type: object
1241512414
timeZone:

config/crd/bases/sparkoperator.k8s.io_sparkapplications.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12323,7 +12323,6 @@ spec:
1232312323
- executor
1232412324
- mainApplicationFile
1232512325
- sparkVersion
12326-
- suspend
1232712326
- type
1232812327
type: object
1232912328
status:

internal/controller/sparkapplication/controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"k8s.io/apimachinery/pkg/types"
3535
"k8s.io/client-go/tools/record"
3636
"k8s.io/client-go/util/retry"
37+
"k8s.io/utils/ptr"
38+
3739
ctrl "sigs.k8s.io/controller-runtime"
3840
"sigs.k8s.io/controller-runtime/pkg/builder"
3941
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -197,7 +199,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
197199
return r.handleSparkApplicationDeletion(ctx, req)
198200
}
199201

200-
if app.Spec.Suspend {
202+
if ptr.Deref(app.Spec.Suspend, false) {
201203
if !(util.IsTerminated(app) ||
202204
app.Status.AppState.State == v1beta2.ApplicationStateSuspended ||
203205
app.Status.AppState.State == v1beta2.ApplicationStateSuspending) {
@@ -781,7 +783,7 @@ func (r *Reconciler) reconcileSuspendedSparkApplication(ctx context.Context, req
781783
logger.Info("Successfully deleted resources associated with SparkApplication", "name", app.Name, "namespace", app.Namespace, "state", app.Status.AppState.State)
782784
r.resetSparkApplicationStatus(app)
783785
r.recordSparkApplicationEvent(app)
784-
if !app.Spec.Suspend {
786+
if !ptr.Deref(app.Spec.Suspend, false) {
785787
app.Status.AppState = v1beta2.ApplicationState{
786788
State: v1beta2.ApplicationStateResuming,
787789
}

internal/controller/sparkapplication/controller_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/types"
3232
"k8s.io/client-go/tools/record"
33+
"k8s.io/utils/ptr"
34+
3335
"sigs.k8s.io/controller-runtime/pkg/client"
3436
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3537

@@ -781,7 +783,7 @@ var _ = Describe("SparkApplication Controller", func() {
781783
Context("Suspend", func() {
782784
When("reconciling a new SparkApplication with Suspend=True", func() {
783785
BeforeEach(func() {
784-
app.Spec.Suspend = true
786+
app.Spec.Suspend = ptr.To(true)
785787
Expect(k8sClient.Create(ctx, app)).To(Succeed())
786788
})
787789
AfterEach(func() {
@@ -834,7 +836,7 @@ var _ = Describe("SparkApplication Controller", func() {
834836
executorPod2.Status.Phase = corev1.PodRunning
835837
Expect(k8sClient.Status().Update(ctx, executorPod2)).To(Succeed())
836838

837-
app.Spec.Suspend = true
839+
app.Spec.Suspend = ptr.To(true)
838840
Expect(k8sClient.Update(ctx, app)).To(Succeed())
839841
})
840842
AfterEach(func() {
@@ -879,7 +881,7 @@ var _ = Describe("SparkApplication Controller", func() {
879881
})
880882
When("reconciling a Terminated(Failed or Completed) SparkApplication with Suspend=true", func() {
881883
BeforeEach(func() {
882-
app.Spec.Suspend = true
884+
app.Spec.Suspend = ptr.To(true)
883885
Expect(k8sClient.Create(ctx, app)).To(Succeed())
884886
app.Status.AppState.State = v1beta2.ApplicationStateFailed
885887
Expect(k8sClient.Status().Update(ctx, app)).To(Succeed())
@@ -913,7 +915,7 @@ var _ = Describe("SparkApplication Controller", func() {
913915
})
914916
When("reconciling Resuming SparkApplication with Suspend=true", func() {
915917
BeforeEach(func() {
916-
app.Spec.Suspend = true
918+
app.Spec.Suspend = ptr.To(true)
917919
Expect(k8sClient.Create(ctx, app)).To(Succeed())
918920
app.Status.AppState.State = v1beta2.ApplicationStateResuming
919921
Expect(k8sClient.Status().Update(ctx, app)).To(Succeed())
@@ -948,7 +950,7 @@ var _ = Describe("SparkApplication Controller", func() {
948950
When("reconciling a Suspending SparkApplication with Suspend=true", func() {
949951
var driverPod *corev1.Pod
950952
BeforeEach(func() {
951-
app.Spec.Suspend = true
953+
app.Spec.Suspend = ptr.To(true)
952954
Expect(k8sClient.Create(ctx, app)).To(Succeed())
953955

954956
driverPod = createDriverPod(appName, appNamespace)
@@ -994,7 +996,7 @@ var _ = Describe("SparkApplication Controller", func() {
994996
Context("Resume", func() {
995997
When("reconciling Suspended SparkApplication with Suspend=false(resuming)", func() {
996998
BeforeEach(func() {
997-
app.Spec.Suspend = false
999+
app.Spec.Suspend = ptr.To(false)
9981000
Expect(k8sClient.Create(ctx, app)).To(Succeed())
9991001
app.Status.AppState.State = v1beta2.ApplicationStateSuspended
10001002
Expect(k8sClient.Status().Update(ctx, app)).To(Succeed())
@@ -1029,7 +1031,7 @@ var _ = Describe("SparkApplication Controller", func() {
10291031
When("reconciling Suspending SparkApplication with Suspend=false(resuming)", func() {
10301032
var driverPod *corev1.Pod
10311033
BeforeEach(func() {
1032-
app.Spec.Suspend = false
1034+
app.Spec.Suspend = ptr.To(false)
10331035
Expect(k8sClient.Create(ctx, app)).To(Succeed())
10341036

10351037
driverPod = createDriverPod(appName, appNamespace)
@@ -1081,7 +1083,7 @@ var _ = Describe("SparkApplication Controller", func() {
10811083
})
10821084
When("reconciling Resuming SparkApplication with Suspend=false(resuming)", func() {
10831085
BeforeEach(func() {
1084-
app.Spec.Suspend = false
1086+
app.Spec.Suspend = ptr.To(false)
10851087
Expect(k8sClient.Create(ctx, app)).To(Succeed())
10861088
app.Status.AppState.State = v1beta2.ApplicationStateResuming
10871089
Expect(k8sClient.Status().Update(ctx, app)).To(Succeed())

test/e2e/sparkapplication_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
3535
"k8s.io/apimachinery/pkg/util/yaml"
36+
"k8s.io/utils/ptr"
3637

3738
"github.com/kubeflow/spark-operator/v2/api/v1beta2"
3839
"github.com/kubeflow/spark-operator/v2/pkg/common"
@@ -439,7 +440,7 @@ var _ = Describe("Example SparkApplication", func() {
439440

440441
By("Suspending Spark Application")
441442
Expect(k8sClient.Get(ctx, key, app)).To(Succeed())
442-
app.Spec.Suspend = true
443+
app.Spec.Suspend = ptr.To(true)
443444
Expect(k8sClient.Update(ctx, app)).To(Succeed())
444445

445446
By("Waiting for SparkApplication to Suspended")
@@ -451,7 +452,7 @@ var _ = Describe("Example SparkApplication", func() {
451452

452453
By("Resuming for SparkApplication")
453454
Expect(k8sClient.Get(ctx, key, app)).To(Succeed())
454-
app.Spec.Suspend = false
455+
app.Spec.Suspend = ptr.To(false)
455456
Expect(k8sClient.Update(ctx, app)).To(Succeed())
456457

457458
By("Waiting for SparkApplication to Running")

0 commit comments

Comments
 (0)