-
Notifications
You must be signed in to change notification settings - Fork 159
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
Support scaling changes during ongoing scaling #1283
Draft
zimnx
wants to merge
1
commit into
scylladb:master
Choose a base branch
from
zimnx:mz/1188-shortest-scale-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ package scyllacluster | |
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
"time" | ||
|
||
scyllav1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1" | ||
|
@@ -22,32 +20,56 @@ import ( | |
"k8s.io/klog/v2" | ||
) | ||
|
||
var serviceOrdinalRegex = regexp.MustCompile("^.*-([0-9]+)$") | ||
|
||
func (scc *Controller) makeServices(sc *scyllav1.ScyllaCluster, oldServices map[string]*corev1.Service, jobs map[string]*batchv1.Job) []*corev1.Service { | ||
func (scc *Controller) makeServices(sc *scyllav1.ScyllaCluster, oldServices map[string]*corev1.Service, statefulSets map[string]*appsv1.StatefulSet, jobs map[string]*batchv1.Job) ([]*corev1.Service, error) { | ||
var errs []error | ||
services := []*corev1.Service{ | ||
IdentityService(sc), | ||
} | ||
|
||
for _, rack := range sc.Spec.Datacenter.Racks { | ||
stsName := naming.StatefulSetNameForRack(rack, sc) | ||
sts, ok := statefulSets[stsName] | ||
if !ok { | ||
errs = append(errs, fmt.Errorf("statefulset %s/%s is missing", sc.Namespace, stsName)) | ||
continue | ||
} | ||
|
||
for ord := int32(0); ord < rack.Members; ord++ { | ||
for ord := int32(0); ord < *sts.Spec.Replicas; ord++ { | ||
svcName := fmt.Sprintf("%s-%d", stsName, ord) | ||
oldSvc := oldServices[svcName] | ||
services = append(services, MemberService(sc, rack.Name, svcName, oldSvc, jobs)) | ||
svc := MemberService(sc, rack.Name, svcName, oldSvc, jobs) | ||
|
||
// Services for nodes which were successfully decommissioned are not required. | ||
if decommissionLabel, ok := svc.Labels[naming.DecommissionedLabel]; ok { | ||
if decommissionLabel == naming.LabelValueTrue { | ||
continue | ||
} | ||
} | ||
|
||
// Mark last node for decommission | ||
if rack.Members < *sts.Spec.Replicas && ord == *sts.Spec.Replicas-1 { | ||
if len(svc.Labels[naming.DecommissionedLabel]) == 0 { | ||
svc.Labels[naming.DecommissionedLabel] = naming.LabelValueFalse | ||
} | ||
} | ||
|
||
services = append(services, svc) | ||
} | ||
} | ||
|
||
return services | ||
err := utilerrors.NewAggregate(errs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return services, nil | ||
} | ||
|
||
func (scc *Controller) pruneServices( | ||
ctx context.Context, | ||
sc *scyllav1.ScyllaCluster, | ||
requiredServices []*corev1.Service, | ||
services map[string]*corev1.Service, | ||
statefulSets map[string]*appsv1.StatefulSet, | ||
) ([]metav1.Condition, error) { | ||
var errs []error | ||
var progressingConditions []metav1.Condition | ||
|
@@ -66,43 +88,8 @@ func (scc *Controller) pruneServices( | |
continue | ||
} | ||
|
||
// Do not delete services for scale down. | ||
rackName, ok := svc.Labels[naming.RackNameLabel] | ||
if !ok { | ||
errs = append(errs, fmt.Errorf("service %s/%s is missing %q label", svc.Namespace, svc.Name, naming.RackNameLabel)) | ||
continue | ||
} | ||
stsName := fmt.Sprintf("%s-%s-%s", sc.Name, sc.Spec.Datacenter.Name, rackName) | ||
sts, ok := statefulSets[stsName] | ||
if !ok { | ||
errs = append(errs, fmt.Errorf("statefulset %s/%s is missing", sc.Namespace, stsName)) | ||
continue | ||
} | ||
// TODO: Label services with the ordinal instead of parsing. | ||
// TODO: Move it to a function and unit test it. | ||
svcOrdinalStrings := serviceOrdinalRegex.FindStringSubmatch(svc.Name) | ||
if len(svcOrdinalStrings) != 2 { | ||
errs = append(errs, fmt.Errorf("can't parse ordinal from service %s/%s", svc.Namespace, svc.Name)) | ||
continue | ||
} | ||
svcOrdinal, err := strconv.Atoi(svcOrdinalStrings[1]) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
if int32(svcOrdinal) < *sts.Spec.Replicas { | ||
progressingConditions = append(progressingConditions, metav1.Condition{ | ||
Type: serviceControllerProgressingCondition, | ||
Status: metav1.ConditionTrue, | ||
Reason: "WaitingForAnotherService", | ||
Message: fmt.Sprintf("Service %q is waiting for another service to be decommissioned first.", naming.ObjRef(svc)), | ||
ObservedGeneration: sc.Generation, | ||
}) | ||
continue | ||
} | ||
|
||
// Do not delete services that weren't properly decommissioned. | ||
if svc.Labels[naming.DecommissionedLabel] != naming.LabelValueTrue { | ||
// Do not delete services that were bootstrapped but weren't properly decommissioned. | ||
if svc.Annotations[naming.NodeInitialized] != "" && svc.Labels[naming.DecommissionedLabel] != naming.LabelValueTrue { | ||
klog.Warningf("Refusing to cleanup service %s/%s whose member wasn't decommissioned.", svc.Namespace, svc.Name) | ||
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. nit: Can you also switch from using "%s/%s" to KObj or similar while we're at it? |
||
progressingConditions = append(progressingConditions, metav1.Condition{ | ||
Type: serviceControllerProgressingCondition, | ||
|
@@ -135,7 +122,7 @@ func (scc *Controller) pruneServices( | |
continue | ||
} | ||
|
||
if freshSvc.Labels[naming.DecommissionedLabel] != naming.LabelValueTrue { | ||
if freshSvc.Annotations[naming.NodeInitialized] != "" && freshSvc.Labels[naming.DecommissionedLabel] != naming.LabelValueTrue { | ||
klog.V(2).InfoS("Stale caches, won't delete the pvc because the service is no longer decommissioned.", "Service", klog.KObj(svc)) | ||
progressingConditions = append(progressingConditions, metav1.Condition{ | ||
Type: serviceControllerProgressingCondition, | ||
|
@@ -152,7 +139,7 @@ func (scc *Controller) pruneServices( | |
|
||
controllerhelpers.AddGenericProgressingStatusCondition(&progressingConditions, serviceControllerProgressingCondition, &corev1.PersistentVolumeClaim{}, "delete", sc.Generation) | ||
pvcName := naming.PVCNameForService(svc.Name) | ||
err = scc.kubeClient.CoreV1().PersistentVolumeClaims(svc.Namespace).Delete(ctx, pvcName, metav1.DeleteOptions{ | ||
err := scc.kubeClient.CoreV1().PersistentVolumeClaims(svc.Namespace).Delete(ctx, pvcName, metav1.DeleteOptions{ | ||
PropagationPolicy: &backgroundPropagationPolicy, | ||
}) | ||
if err != nil && !apierrors.IsNotFound(err) { | ||
|
@@ -186,11 +173,14 @@ func (scc *Controller) syncServices( | |
) ([]metav1.Condition, error) { | ||
var err error | ||
|
||
requiredServices := scc.makeServices(sc, services, jobs) | ||
requiredServices, err := scc.makeServices(sc, services, statefulSets, jobs) | ||
if err != nil { | ||
return nil, fmt.Errorf("can't make Service(s): %w", err) | ||
} | ||
|
||
// Delete any excessive Services. | ||
// Delete has to be the fist action to avoid getting stuck on quota. | ||
progressingConditions, err := scc.pruneServices(ctx, sc, requiredServices, services, statefulSets) | ||
progressingConditions, err := scc.pruneServices(ctx, sc, requiredServices, services) | ||
if err != nil { | ||
return nil, fmt.Errorf("can't delete Service(s): %w", err) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't understand the semantics behind this annotation. The comment for
naming.NodeInitialized
says "NodeInitialized means given node was started.", while the Scylla process is run at a later time. Should this be moved to after the process is started?