-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Restart task to CassandraTasks #394
Changes from all commits
4a58f70
41c1330
80e0d56
7dd3f90
0b3f07b
467153d
2673975
02ae0e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"strconv" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -256,6 +257,7 @@ func (r *CassandraTaskReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
|
||
var err error | ||
var failed, completed int | ||
JobDefinition: | ||
for _, job := range cassTask.Spec.Jobs { | ||
taskConfig := &TaskConfiguration{ | ||
RestartPolicy: cassTask.Spec.RestartPolicy, | ||
|
@@ -273,7 +275,17 @@ func (r *CassandraTaskReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
case api.CommandCleanup: | ||
cleanup(taskConfig) | ||
case api.CommandRestart: | ||
r.restart(taskConfig) | ||
// This job is targeting StatefulSets and not Pods | ||
sts, err := r.getDatacenterStatefulSets(ctx, dc) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
res, err = r.restartSts(ctx, sts, taskConfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that res used on the line 333? I don't see it being overwritten anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it overwritten on line 320?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. break JobDefinition should break us from the for() clause and thus line 320 should never be run. |
||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
break JobDefinition | ||
case api.CommandReplaceNode: | ||
r.replace(taskConfig) | ||
case "forceupgraderacks": | ||
|
@@ -333,6 +345,7 @@ func (r *CassandraTaskReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
|
||
cassTask.Status.Active = 0 | ||
cassTask.Status.CompletionTime = &timeNow | ||
SetCondition(&cassTask, api.JobComplete, corev1.ConditionTrue) | ||
|
||
// Requeue for deletion later | ||
deletionTime := calculateDeletionTime(&cassTask) | ||
|
@@ -344,8 +357,6 @@ func (r *CassandraTaskReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
cassTask.Status.Succeeded = completed | ||
cassTask.Status.Failed = failed | ||
|
||
SetCondition(&cassTask, api.JobComplete, corev1.ConditionTrue) | ||
|
||
if err = r.Client.Status().Update(ctx, &cassTask); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
@@ -498,6 +509,16 @@ func (r *CassandraTaskReconciler) getDatacenterPods(ctx context.Context, dc *cas | |
return pods.Items, nil | ||
} | ||
|
||
func (r *CassandraTaskReconciler) getDatacenterStatefulSets(ctx context.Context, dc *cassapi.CassandraDatacenter) ([]appsv1.StatefulSet, error) { | ||
var sts appsv1.StatefulSetList | ||
|
||
if err := r.Client.List(ctx, &sts, client.InNamespace(dc.Namespace), client.MatchingLabels(dc.GetDatacenterLabels())); err != nil { | ||
return nil, err | ||
} | ||
|
||
return sts.Items, nil | ||
} | ||
|
||
// cleanupJobAnnotations removes the job annotations from the pod once it has finished | ||
func (r *CassandraTaskReconciler) cleanupJobAnnotations(ctx context.Context, dc *cassapi.CassandraDatacenter, taskId string) error { | ||
logger := log.FromContext(ctx) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this related to a restart?