Skip to content

Commit

Permalink
feat: add real size to backing image
Browse files Browse the repository at this point in the history
ref: longhorn/longhonr 8757

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Sep 24, 2024
1 parent 3ac6b93 commit 1a5db6c
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 655 deletions.
15 changes: 15 additions & 0 deletions controller/backing_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,21 @@ func (bic *BackingImageController) syncBackingImageFileInfo(bi *longhorn.Backing
}
}
}
if info.RealSize > 0 {
if bi.Status.RealSize == 0 {
bi.Status.RealSize = info.RealSize
bic.eventRecorder.Eventf(bi, corev1.EventTypeNormal, constant.EventReasonUpdate, "Set realSize to %v", bi.Status.RealSize)
}
if bi.Status.RealSize != info.RealSize {
if bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State != longhorn.BackingImageStateFailed {
msg := fmt.Sprintf("found mismatching realSize %v reported by backing image manager %v in disk %v, the realSoze recorded in status is %v",
info.RealSize, bim.Name, bim.Spec.DiskUUID, bi.Status.RealSize)
log.Error(msg)
bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State = longhorn.BackingImageStateFailed
bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].Message = msg
}
}
}
}

for diskUUID := range bi.Status.DiskFileStatusMap {
Expand Down
14 changes: 14 additions & 0 deletions controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ func (nc *NodeController) updateDiskStatusSchedulableCondition(node *longhorn.No
if err != nil {
return err
}
backingImages, err := nc.ds.ListBackingImagesRO()
if err != nil {
return err
}

for diskName, disk := range node.Spec.Disks {
diskStatus := diskStatusMap[diskName]
Expand Down Expand Up @@ -843,6 +847,7 @@ func (nc *NodeController) updateDiskStatusSchedulableCondition(node *longhorn.No
return err
}
scheduledReplica := map[string]int64{}
scheduledBackingImage := map[string]int64{}
storageScheduled := int64(0)
for _, replica := range replicas {
if replica.Spec.NodeID != node.Name || replica.Spec.DiskPath != disk.Path {
Expand All @@ -857,8 +862,17 @@ func (nc *NodeController) updateDiskStatusSchedulableCondition(node *longhorn.No
storageScheduled += replica.Spec.VolumeSize
scheduledReplica[replica.Name] = replica.Spec.VolumeSize
}

for _, backingImage := range backingImages {
if _, exists := backingImage.Spec.DiskFileSpecMap[diskStatus.DiskUUID]; exists {
storageScheduled += backingImage.Status.RealSize
scheduledBackingImage[backingImage.Name] = backingImage.Status.RealSize
}
}

diskStatus.StorageScheduled = storageScheduled
diskStatus.ScheduledReplica = scheduledReplica
diskStatus.ScheduledBackingImage = scheduledBackingImage
// check disk pressure
info, err := nc.scheduler.GetDiskSchedulingInfo(disk, diskStatus)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions engineapi/backing_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (c *BackingImageManagerClient) parseBackingImageFileInfo(bi *bimapi.Backing
UUID: bi.UUID,
Size: bi.Size,
VirtualSize: bi.VirtualSize,
RealSize: bi.RealSize,

State: longhorn.BackingImageState(bi.Status.State),
CurrentChecksum: bi.Status.CurrentChecksum,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/jinzhu/copier v0.4.0
github.com/kubernetes-csi/csi-lib-utils v0.19.0
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277
github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9
github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d
github.com/longhorn/go-iscsi-helper v0.0.0-20240922062410-c17a624e50c1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922 h1:Ikx3UIgHD90DHr1CBfu9IUTdyt+NzM313IHau5DMzJQ=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922/go.mod h1:raIdWG9r1P0YlnVRCqsCpavnEHd3TsqREQE2skKNQEA=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277 h1:b0IhPPH+F2ZOC701kzLDExSAAKN9FLVTHikhGaKYJWo=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240922.0.20240923074219-9aff32760277/go.mod h1:rLnxTIs4uEY0FUkHalr//1IKePxlqKXBhv+NRQ968yg=
github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9 h1:ua4PCfArX2TyPVnldF+m7I9c2eGi+TcP8pcPPx2wp0w=
github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9/go.mod h1:UTONYTgRryrw0RgDZbxwU+r1s4PeKQ+v0Z8Pb6jUWn4=
github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d h1:MXJlzyXLptspJEc1UC7ee2eBIYksTl0RT2bXUAXU+8Q=
Expand Down
14 changes: 14 additions & 0 deletions k8s/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ spec:
type: string
progress:
type: integer
realSize:
format: int64
type: integer
senderManagerAddress:
type: string
sendingReference:
Expand Down Expand Up @@ -560,6 +563,11 @@ spec:
type: object
ownerID:
type: string
realSize:
description: Real size of image, which may be smaller than the size
when the file is a sparse file. Will be zero until known (e.g. while a backing image is uploading)
format: int64
type: integer
size:
format: int64
type: integer
Expand Down Expand Up @@ -2507,6 +2515,12 @@ spec:
type: string
instanceManagerName:
type: string
scheduledBackingImage:
additionalProperties:
format: int64
type: integer
nullable: true
type: object
scheduledReplica:
additionalProperties:
format: int64
Expand Down
14 changes: 7 additions & 7 deletions k8s/generate_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ if [[ ! -d "${GOPATH}/src/k8s.io/code-generator" ]]; then
fi

# https://github.com/kubernetes-sigs/controller-tools/tree/${CONTROLLER_TOOLS_VERSION}/cmd/controller-gen
if ! command -v controller-gen > /dev/null; then
if ! command -v ${GOPATH}/bin/controller-gen > /dev/null; then
echo "controller-gen is missing"
echo "Prepare to install controller-gen"
go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_TOOLS_VERSION}
fi

# https://github.com/kubernetes-sigs/kustomize/tree/kustomize/${KUSTOMIZE_VERSION}/kustomize
if ! command -v kustomize > /dev/null; then
if ! command -v ${GOPATH}/bin/kustomize > /dev/null; then
echo "kustomize is missing"
echo "Prepare to install kustomize"
mkdir -p ${GOPATH}/src/github.com/kubernetes-sigs
Expand All @@ -65,16 +65,16 @@ bash ${GOPATH}/src/k8s.io/code-generator/generate-groups.sh \
$@

echo Generating CRD
controller-gen crd paths=${APIS_DIR}/... output:crd:dir=${CRDS_DIR}
${GOPATH}/bin/controller-gen crd paths=${APIS_DIR}/... output:crd:dir=${CRDS_DIR}
pushd ${CRDS_DIR}
kustomize create --autodetect 2>/dev/null || true
kustomize edit add label longhorn-manager: 2>/dev/null || true
${GOPATH}/bin/kustomize create --autodetect 2>/dev/null || true
${GOPATH}/bin/kustomize edit add label longhorn-manager: 2>/dev/null || true
if [ -e ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/patches/crd ]; then
cp -a ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/patches/crd patches
find patches -type f | xargs -i sh -c 'kustomize edit add patch --path {}'
find patches -type f | xargs -i sh -c '${GOPATH}/bin/kustomize edit add patch --path {}'

Check warning on line 74 in k8s/generate_code.sh

View check run for this annotation

codefactor.io / CodeFactor

k8s/generate_code.sh#L74

Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames. (SC2038)
fi
popd

echo "# Generated by the CRDs from ${APIS_DIR}" > ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/crds.yaml
kustomize build ${CRDS_DIR} >> ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/crds.yaml
${GOPATH}/bin/kustomize build ${CRDS_DIR} >> ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/crds.yaml
rm -r ${CRDS_DIR}
3 changes: 3 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/backingimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type BackingImageStatus struct {
// Virtual size of image, which may be larger than physical size. Will be zero until known (e.g. while a backing image is uploading)
// +optional
VirtualSize int64 `json:"virtualSize"`
// Real size of image, which may be smaller than the size when the file is a sparse file. Will be zero until known (e.g. while a backing image is uploading)
// +optional
RealSize int64 `json:"realSize"`
// +optional
Checksum string `json:"checksum"`
// +optional
Expand Down
2 changes: 2 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/backingimagemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type BackingImageFileInfo struct {
// +optional
VirtualSize int64 `json:"virtualSize"`
// +optional
RealSize int64 `json:"realSize"`
// +optional
State BackingImageState `json:"state"`
// +optional
CurrentChecksum string `json:"currentChecksum"`
Expand Down
3 changes: 3 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type DiskStatus struct {
// +nullable
ScheduledReplica map[string]int64 `json:"scheduledReplica"`
// +optional
// +nullable
ScheduledBackingImage map[string]int64 `json:"scheduledBackingImage"`
// +optional
DiskUUID string `json:"diskUUID"`
// +optional
DiskName string `json:"diskName"`
Expand Down
7 changes: 7 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions vendor/github.com/klauspost/compress/.gitignore

This file was deleted.

Loading

0 comments on commit 1a5db6c

Please sign in to comment.