Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Custom type fpr cluster status field
Browse files Browse the repository at this point in the history
  • Loading branch information
adp312 committed Sep 26, 2022
1 parent dbcb41f commit 5c8af4f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
15 changes: 8 additions & 7 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1alpha1

import (
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -154,10 +153,12 @@ type WorkloadConfig struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}

type ClusterStatusType string

// ClusterStatusConfig defines the observed state of a given cluster. The
// controllers will generate and populate these fields during reconciliation.
type ClusterStatusConfig struct {
ClusterStatus batchv1.JobConditionType `json:"clusterStatus,omitempty"`
ClusterStatus ClusterStatusType `json:"clusterStatus,omitempty"`
// Reason may contain additional information when status is "Failed"
Reason string `json:"reason,omitempty"`
StartTime *metav1.Time `json:"startTime,omitempty"`
Expand All @@ -172,11 +173,11 @@ type ClusterStatusConfig struct {
}

const (
PendingStatus batchv1.JobConditionType = "Pending"
StartingStatus batchv1.JobConditionType = "Starting"
RunningStatus batchv1.JobConditionType = "Running"
StoppingStatus batchv1.JobConditionType = "Stopping"
FailedStatus batchv1.JobConditionType = "Failed"
PendingStatus ClusterStatusType = "Pending"
StartingStatus ClusterStatusType = "Starting"
RunningStatus ClusterStatusType = "Running"
StoppingStatus ClusterStatusType = "Stopping"
FailedStatus ClusterStatusType = "Failed"
)

func IsPodReady(pod corev1.Pod) bool {
Expand Down
4 changes: 1 addition & 3 deletions controllers/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"strings"
"time"

v1 "k8s.io/api/batch/v1"

appsv1 "k8s.io/api/apps/v1"
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -345,7 +343,7 @@ func (r *RayClusterReconciler) reconcileStatefulSets(ctx context.Context, rc *dc
}

updateStatus := false
var status v1.JobConditionType
var status dcv1alpha1.ClusterStatusType
masterPod, masterPodFound := r.getMasterPod(ctx, rc)
if masterPodFound {
if dcv1alpha1.IsPodReady(masterPod) {
Expand Down
4 changes: 1 addition & 3 deletions controllers/sparkcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"strings"
"time"

v1 "k8s.io/api/batch/v1"

"github.com/banzaicloud/k8s-objectmatcher/patch"
"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -468,7 +466,7 @@ func (r *SparkClusterReconciler) reconcileStatefulSets(ctx context.Context, sc *
log.V(1).Info("updating status", "path", ".status.workerSelector", "value", sc.Status.WorkerSelector)
}

var status v1.JobConditionType
var status dcv1alpha1.ClusterStatusType
masterPod, masterPodFound := r.getMasterPod(ctx, sc)
if masterPodFound {
if dcv1alpha1.IsPodReady(masterPod) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/mpi/statusupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"k8s.io/apimachinery/pkg/types"

v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (c statusUpdateComponent) Reconcile(ctx *core.Context) (ctrl.Result, error)

expectedPodCnt := int(*cr.Spec.Worker.Replicas)

var status v1.JobConditionType
var status dcv1alpha1.ClusterStatusType
switch {
case failureReason != "":
status = dcv1alpha1.FailedStatus
Expand Down
4 changes: 1 addition & 3 deletions pkg/controller/components/clusterstatusupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strings"
"time"

v1 "k8s.io/api/batch/v1"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -99,7 +97,7 @@ func (c *clusterStatusUpdateComponent) Reconcile(ctx *core.Context) (ctrl.Result
modified = true
}

var status v1.JobConditionType
var status dcv1alpha1.ClusterStatusType
if masterPodFound {
if dcv1alpha1.IsPodReady(masterPod) {
status = dcv1alpha1.RunningStatus
Expand Down

0 comments on commit 5c8af4f

Please sign in to comment.