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 Aug 26, 2024
1 parent 385346b commit d282af0
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 180 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 @@ -899,6 +899,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 @@ -936,6 +940,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 @@ -950,8 +955,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
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module github.com/longhorn/longhorn-manager

go 1.22.2

replace github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 => github.com/chanyilin/types v0.0.0-20240826101424-96408c7b8e43

replace github.com/longhorn/backing-image-manager v1.7.0-rc1 => github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240826102155-2a1e68d1678a

// Replace directives are required for dependencies in this section because:
// - This module imports k8s.io/kubernetes.
// - The development for all of these dependencies is done at kubernetes/staging and then synced to other repos.
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@ github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240826102155-2a1e68d1678a h1:Tz48g5Kq4rtmxAa5ipjWqziGLFTTaf8H2PeXDKasGGU=
github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240826102155-2a1e68d1678a/go.mod h1:3GGrzcg1g4G/UuPbfXyxshSJnAYKpGXsS2q44tJLYvU=
github.com/chanyilin/types v0.0.0-20240826101424-96408c7b8e43 h1:IVgdQe+kLHSBQkrVx57WNp02DfNVPrq80jrxKsQhIRg=
github.com/chanyilin/types v0.0.0-20240826101424-96408c7b8e43/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -1221,8 +1225,6 @@ github.com/kubernetes-csi/csi-lib-utils v0.6.1 h1:+AZ58SRSRWh2vmMoWAAGcv7x6fIyBM
github.com/kubernetes-csi/csi-lib-utils v0.6.1/go.mod h1:GVmlUmxZ+SUjVLXicRFjqWUUvWez0g0Y78zNV9t7KfQ=
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.7.0-rc1 h1:kD106yhLtofxDwXkvKs77VAFzTVdJnbxsD2m28X4tp0=
github.com/longhorn/backing-image-manager v1.7.0-rc1/go.mod h1:ZXD/+yKwMer/eZzwQ2ev/eAyLvih7WNq6NDgfUpvQ+8=
github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e h1:Kvt/BqiHKaOlTPSM2HFz0VupuQM0laln67rMIDCRYxQ=
github.com/longhorn/backupstore v0.0.0-20240823072635-7afd6aa10d3e/go.mod h1:N4cqNhSs4VUw9aGbO2OfyiIvJL7/L53hUrNiT73UN+U=
github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f h1:hjqUs3WVodkzrWwlUMVsnKAlom3uohoNlhZBGLsRvQY=
Expand All @@ -1237,8 +1239,6 @@ github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240824081444-10108a
github.com/longhorn/longhorn-instance-manager v1.7.0-dev.0.20240824081444-10108a7c3ffc/go.mod h1:tUatwl4OazNIwSEK1HQQCOwW9KSIJRzTfQH8WNI2eFY=
github.com/longhorn/longhorn-share-manager v1.7.0-rc1 h1:LsSkSajhG8tCfORKKfwK+8XHVrT/8rI9DRWb7fuoVls=
github.com/longhorn/longhorn-share-manager v1.7.0-rc1/go.mod h1:R6+NscPU4lAV5ueO7//lBCAO3en0aDbZi5KkkOSUJvk=
github.com/longhorn/types v0.0.0-20240725040629-473d671316c4 h1:L2g0sIJ2fXt4BSFRYNnF6ObtKryCUFm9qLcCXHWssCk=
github.com/longhorn/types v0.0.0-20240725040629-473d671316c4/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w=
github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
github.com/lyft/protoc-gen-star v0.6.1/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WVYF7/opLeUgcQs/o=
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 @@ -2485,6 +2493,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.

3 changes: 3 additions & 0 deletions vendor/github.com/longhorn/backing-image-manager/api/types.go

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

14 changes: 14 additions & 0 deletions vendor/github.com/longhorn/backing-image-manager/pkg/util/util.go

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

Loading

0 comments on commit d282af0

Please sign in to comment.