From 004c6f51033f48c9fc16cf674ed050cc2ebcb32a Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Mon, 4 Mar 2024 08:20:52 +0100 Subject: [PATCH 1/2] Avoid second rebalance on startup Until now the SwiftRing instance created a ring with estimated disk sizes if PVCs and size data was not yet available. Rings were updated later once sizes were known. However, this is no longer needed. PVCs have to be created eventually if SwiftStorage replicas > 0, thus we can requeue until these are bound. This eliminates a second rebalance with the correct values shortly after. It also simplifies the rebalance script and removes a possible risk when changing weights for existing devices. Initially set weights are kept now, which should be the correct ones from the beginning. --- pkg/swiftring/funcs.go | 21 +++++++++------------ templates/swiftring/bin/swift-ring-tool | 6 ------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/pkg/swiftring/funcs.go b/pkg/swiftring/funcs.go index fce418d3..1192db89 100644 --- a/pkg/swiftring/funcs.go +++ b/pkg/swiftring/funcs.go @@ -25,7 +25,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -57,18 +56,16 @@ func DeviceList(ctx context.Context, h *helper.Helper, instance *swiftv1beta1.Sw cn := fmt.Sprintf("%s-%s-%d", swift.ClaimName, storageInstance.Name, replica) foundClaim := &corev1.PersistentVolumeClaim{} err = h.GetClient().Get(ctx, types.NamespacedName{Name: cn, Namespace: storageInstance.Namespace}, foundClaim) - capacity := resource.MustParse(storageInstance.Spec.StorageRequest) - weight, _ := capacity.AsInt64() - if err == nil { - if foundClaim.Status.Phase != corev1.ClaimBound { - err = fmt.Errorf("PVC %s found, but not bound yet (%s). Requeueing", cn, foundClaim.Status.Phase) - return "", "", err // requeueing - } - capacity := foundClaim.Status.Capacity[corev1.ResourceStorage] - weight, _ = capacity.AsInt64() - } else { - h.GetLogger().Info(fmt.Sprintf("Did not find PVC %s, assuming %s as capacity", cn, storageInstance.Spec.StorageRequest)) + if err != nil { + return "", "", err // requeueing } + + if foundClaim.Status.Phase != corev1.ClaimBound { + err = fmt.Errorf("PersistentVolumeClaim %s found, but not bound yet (%s). Requeueing", cn, foundClaim.Status.Phase) + return "", "", err // requeueing + } + capacity := foundClaim.Status.Capacity[corev1.ResourceStorage] + weight, _ := capacity.AsInt64() weight = weight / (1000 * 1000 * 1000) // 10GiB gets a weight of 10 etc. // CSV: region,zone,hostname,devicename,weight devices = append(devices, fmt.Sprintf("1 1 %s-%d.%s %s %d\n", storageInstance.Name, replica, storageInstance.Name, "d1", weight)) diff --git a/templates/swiftring/bin/swift-ring-tool b/templates/swiftring/bin/swift-ring-tool index 27a453e2..4b18bc90 100755 --- a/templates/swiftring/bin/swift-ring-tool +++ b/templates/swiftring/bin/swift-ring-tool @@ -61,12 +61,6 @@ function update() { # Check if host/disk exists and only add if not swift-ring-builder object.builder search --ip $HOST --device $DEVICE_NAME [ $? -eq 2 ] && swift-ring-builder object.builder add --region $REGION --zone $ZONE --ip $HOST --port 6200 --device $DEVICE_NAME --weight $WEIGHT - - # This will change the weights, eg. after bootstrapping and correct PVC - # sizes are known. - swift-ring-builder account.builder set_weight --region $REGION --zone $ZONE --ip $HOST --port 6202 --device $DEVICE_NAME $WEIGHT - swift-ring-builder container.builder set_weight --region $REGION --zone $ZONE --ip $HOST --port 6201 --device $DEVICE_NAME $WEIGHT - swift-ring-builder object.builder set_weight --region $REGION --zone $ZONE --ip $HOST --port 6200 --device $DEVICE_NAME $WEIGHT done < $DEVICESFILE } From b257699fd7c522301f1937c40a05bde9a715debf Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Mon, 4 Mar 2024 12:06:21 +0100 Subject: [PATCH 2/2] Update SwiftRing status if PVCs not ready The function DeviceList returns an error if the requested PVCs are not found or bound yet. This patch updates the conditions to reflect the current state. --- controllers/swiftring_controller.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/controllers/swiftring_controller.go b/controllers/swiftring_controller.go index 447623cc..bf9bab9c 100644 --- a/controllers/swiftring_controller.go +++ b/controllers/swiftring_controller.go @@ -160,6 +160,12 @@ func (r *SwiftRingReconciler) reconcileNormal(ctx context.Context, instance *swi deviceList, deviceListHash, err := swiftring.DeviceList(ctx, helper, instance) if err != nil { + instance.Status.Conditions.Set(condition.FalseCondition( + swiftv1beta1.SwiftRingReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + swiftv1beta1.SwiftRingReadyErrorMessage, + err.Error())) return ctrl.Result{}, err }