Skip to content

Commit b538ba1

Browse files
authored
Merge pull request #113 from BuddhiWathsala/master
Replace Running status with Ready
2 parents 2a5dc3d + a355ffa commit b538ba1

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

pkg/apis/siddhi/v1alpha2/siddhiprocess_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Apps struct {
4949
// PartialApp siddhi partial app
5050
type PartialApp struct {
5151
DeploymentName string `json:"deploymentName"`
52-
Apps []string `json:"apps"`
52+
Apps []string `json:"app"`
5353
}
5454

5555
// SiddhiProcessSpec defines the desired state of SiddhiProcess

pkg/controller/siddhiprocess/siddhicontroller/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ const (
3535
ERROR
3636
WARNING
3737
NORMAL
38-
UPDATING
38+
NOTREADY
3939
)

pkg/controller/siddhiprocess/siddhicontroller/siddhicontroller.go

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ func (sc *SiddhiController) UpdateWarningStatus(
8787
}
8888
}
8989

90-
// UpdateRunningStatus update the status of the CR object and send events to the SiddhiProcess object using EventRecorder object
90+
// UpdateRunningStatus send events to the SiddhiProcess object using EventRecorder object
9191
func (sc *SiddhiController) UpdateRunningStatus(
9292
reason string,
9393
message string,
9494
) {
95-
st := getStatus(RUNNING)
9695
s := sc.SiddhiProcess
97-
sc.SiddhiProcess.Status.Status = st
9896
if reason != "" && message != "" {
9997
sc.EventRecorder.Event(sc.SiddhiProcess, getStatus(NORMAL), reason, message)
10098
sc.Logger.Info(message)
@@ -139,9 +137,20 @@ func (sc *SiddhiController) UpdatePendingStatus() {
139137
}
140138
}
141139

142-
// UpdateUpdatingtatus update the status of the CR object to Updating status
143-
func (sc *SiddhiController) UpdateUpdatingtatus() {
144-
st := getStatus(UPDATING)
140+
// UpdateNotReadytatus update the status of the CR object to Not Ready status
141+
func (sc *SiddhiController) UpdateNotReadytatus() {
142+
st := getStatus(NOTREADY)
143+
s := sc.SiddhiProcess
144+
sc.SiddhiProcess.Status.Status = st
145+
err := sc.KubeClient.Client.Status().Update(context.TODO(), sc.SiddhiProcess)
146+
if err != nil {
147+
sc.SiddhiProcess = s
148+
}
149+
}
150+
151+
// UpdateReadyStatus update the status of the CR object to Ready status
152+
func (sc *SiddhiController) UpdateReadyStatus() {
153+
st := getStatus(READY)
145154
s := sc.SiddhiProcess
146155
sc.SiddhiProcess.Status.Status = st
147156
err := sc.KubeClient.Client.Status().Update(context.TODO(), sc.SiddhiProcess)
@@ -150,9 +159,9 @@ func (sc *SiddhiController) UpdateUpdatingtatus() {
150159
}
151160
}
152161

153-
// UpdateReady update ready attribute of the CR object
162+
// UpdateReadyDeployments update ready attribute of the CR object
154163
// Ready attribute contains the number of deployments are complete and running out of requested deployments
155-
func (sc *SiddhiController) UpdateReady(available int, need int) {
164+
func (sc *SiddhiController) UpdateReadyDeployments(available int, need int) {
156165
s := sc.SiddhiProcess
157166
s.Status.Ready = strconv.Itoa(available) + "/" + strconv.Itoa(need)
158167
err := sc.KubeClient.Client.Status().Update(context.TODO(), sc.SiddhiProcess)
@@ -252,7 +261,7 @@ func (sc *SiddhiController) CreateArtifacts(applications []deploymanager.Applica
252261
sc.SyncVersion()
253262
if (eventType == controllerutil.OperationResultCreated) ||
254263
(eventType == controllerutil.OperationResultUpdated) {
255-
sc.UpdateReady(0, needDep)
264+
sc.UpdateReadyDeployments(0, needDep)
256265
}
257266
return
258267
}
@@ -284,6 +293,11 @@ func (sc *SiddhiController) CheckDeployments(applications []deploymanager.Applic
284293
func (sc *SiddhiController) CheckAvailableDeployments(applications []deploymanager.Application) (terminate bool) {
285294
availableDeployments := 0
286295
needDeployments := 0
296+
isStatelessReady := true
297+
needStatefulDeployments := 0
298+
availableStatefuleDeployments := 0
299+
needStatelessDeployments := 0
300+
availableStatelesseDeployments := 0
287301
for _, application := range applications {
288302
deployment := &appsv1.Deployment{}
289303
err := sc.KubeClient.Client.Get(
@@ -294,16 +308,35 @@ func (sc *SiddhiController) CheckAvailableDeployments(applications []deploymanag
294308
},
295309
deployment,
296310
)
297-
needDeployments++
311+
needDeployments += int(application.Replicas)
298312
if err == nil && &deployment.Status.AvailableReplicas != nil {
299313
availableDeployments += int(deployment.Status.AvailableReplicas)
300314
}
315+
316+
if application.PersistenceEnabled {
317+
needStatefulDeployments += int(application.Replicas)
318+
if err == nil && &deployment.Status.AvailableReplicas != nil {
319+
availableStatefuleDeployments += int(deployment.Status.AvailableReplicas)
320+
}
321+
} else {
322+
needStatelessDeployments += int(application.Replicas)
323+
if err == nil && &deployment.Status.AvailableReplicas != nil {
324+
availableStatelesseDeployments += int(deployment.Status.AvailableReplicas)
325+
if int(deployment.Status.AvailableReplicas) == 0 {
326+
isStatelessReady = false
327+
}
328+
}
329+
}
301330
}
302-
sc.UpdateReady(availableDeployments, needDeployments)
331+
sc.UpdateReadyDeployments(availableDeployments, needDeployments)
303332
if needDeployments == availableDeployments {
304333
terminate = true
305-
sc.UpdateRunningStatus("", "")
334+
sc.UpdateReadyStatus()
306335
return
336+
} else if isStatelessReady && (needStatefulDeployments == availableStatefuleDeployments) {
337+
sc.UpdateReadyStatus()
338+
} else {
339+
sc.UpdateNotReadytatus()
307340
}
308341
terminate = false
309342
return
@@ -461,13 +494,13 @@ func (sc *SiddhiController) SetDefaultPendingState() {
461494
}
462495
}
463496

464-
// SetUpdatingState set the state of a SiddhiProcess object to Updating
465-
func (sc *SiddhiController) SetUpdatingState() {
497+
// SetNotReadyState set the state of a SiddhiProcess object to Updating
498+
func (sc *SiddhiController) SetNotReadyState() {
466499
eventType := getEventType(
467500
sc.SiddhiProcess.Status.CurrentVersion,
468501
sc.SiddhiProcess.Status.PreviousVersion,
469502
)
470503
if eventType == controllerutil.OperationResultUpdated {
471-
sc.UpdateUpdatingtatus()
504+
sc.UpdateNotReadytatus()
472505
}
473506
}

pkg/controller/siddhiprocess/siddhicontroller/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var status = []string{
2929
"Error",
3030
"Warning",
3131
"Normal",
32-
"Updating",
32+
"Not Ready",
3333
}
3434

3535
// getStatus return relevant status to a given integer. This uses status array and the constants list.

pkg/controller/siddhiprocess/siddhiprocess_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (rsp *ReconcileSiddhiProcess) Reconcile(request reconcile.Request) (reconci
220220
}
221221

222222
siddhiController.SetDefaultPendingState()
223-
siddhiController.SetUpdatingState()
223+
siddhiController.SetNotReadyState()
224224
if !siddhiProcessChanged {
225225
siddhiController.UpgradeVersion()
226226
sp = siddhiController.SiddhiProcess

0 commit comments

Comments
 (0)