Skip to content

Commit

Permalink
Merge pull request #158 from cschwede/avoid-second-rebalance
Browse files Browse the repository at this point in the history
Avoid second rebalance on startup
  • Loading branch information
openshift-merge-bot[bot] authored Mar 5, 2024
2 parents 52d0be4 + b257699 commit 22b0f6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
6 changes: 6 additions & 0 deletions controllers/swiftring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 9 additions & 12 deletions pkg/swiftring/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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))
Expand Down
6 changes: 0 additions & 6 deletions templates/swiftring/bin/swift-ring-tool
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 22b0f6c

Please sign in to comment.