Skip to content

Commit

Permalink
feat(backupbackingimage): add parameters to backup backing image crea…
Browse files Browse the repository at this point in the history
…te proto

ref: longhorn/longhorn 8884

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Jul 17, 2024
1 parent 06abbf3 commit 975985a
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 119 deletions.
2 changes: 2 additions & 0 deletions controller/backup_backing_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func (bc *BackupBackingImageController) reconcile(backupBackingImageName string)
bbi.Status.Checksum = backupBackingImageInfo.Checksum
bbi.Status.Size = backupBackingImageInfo.Size
bbi.Status.Labels = backupBackingImageInfo.Labels
bbi.Status.Secret = backupBackingImageInfo.Secret
bbi.Status.SecretNamespace = backupBackingImageInfo.SecretNamespace
bbi.Status.CompressionMethod = longhorn.BackupCompressionMethod(backupBackingImageInfo.CompressionMethod)
bbi.Status.LastSyncedAt = syncTime
return nil
Expand Down
4 changes: 2 additions & 2 deletions engineapi/backing_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ func (c *BackingImageManagerClient) VersionGet() (int, int, error) {
return output.BackingImageManagerAPIMinVersion, output.BackingImageManagerAPIVersion, nil
}

func (c *BackingImageManagerClient) BackupCreate(name, uuid, checksum, backupTargetURL string, labels, credential map[string]string, compressionMethod string, concurrentLimit int) error {
func (c *BackingImageManagerClient) BackupCreate(name, uuid, checksum, backupTargetURL string, labels, credential map[string]string, compressionMethod string, concurrentLimit int, parameters map[string]string) error {

if err := CheckBackingImageManagerCompatibility(c.apiMinVersion, c.apiVersion); err != nil {
return err
}
return c.grpcClient.BackupCreate(name, uuid, checksum, backupTargetURL, labels, credential, compressionMethod, concurrentLimit)
return c.grpcClient.BackupCreate(name, uuid, checksum, backupTargetURL, labels, credential, compressionMethod, concurrentLimit, parameters)
}

func (c *BackingImageManagerClient) BackupStatus(name string) (*longhorn.BackupBackingImageStatus, error) {
Expand Down
17 changes: 15 additions & 2 deletions engineapi/backup_backing_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/clock"

lhbackup "github.com/longhorn/go-common-libs/backup"

"github.com/longhorn/backupstore/backupbackingimage"
"github.com/longhorn/longhorn-manager/datastore"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/types"
)

Expand Down Expand Up @@ -112,10 +116,12 @@ func NewBackupBackingImageMonitor(logger logrus.FieldLogger, ds *datastore.DataS
quit: quit,
}

backupBackingImageParameters := getBackupBackingImageParameters(backingImage)

// Call backing image manager API snapshot backup
if bbi.Status.State == longhorn.BackupStateNew {
err := m.client.BackupCreate(bbi.Name, backingImage.Status.UUID, bbi.Status.Checksum,
backupTargetClient.URL, bbi.Spec.Labels, backupTargetClient.Credential, string(compressionMethod), concurrentLimit)
backupTargetClient.URL, bbi.Spec.Labels, backupTargetClient.Credential, string(compressionMethod), concurrentLimit, backupBackingImageParameters)
if err != nil {
if !strings.Contains(err.Error(), "DeadlineExceeded") {
m.logger.WithError(err).Warn("failed to take backing image backup")
Expand Down Expand Up @@ -258,3 +264,10 @@ func (m *BackupBackingImageMonitor) GetBackupBackingImageStatus() longhorn.Backu
func (m *BackupBackingImageMonitor) Close() {
m.quit()
}

func getBackupBackingImageParameters(backingImage *longhorn.BackingImage) map[string]string {
parameters := map[string]string{}
parameters[lhbackup.LonghornBackupBackingImageParameterSecret] = string(backingImage.Spec.Secret)
parameters[lhbackup.LonghornBackupBackingImageParameterSecretNamespace] = string(backingImage.Spec.SecretNamespace)
return parameters
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ module github.com/longhorn/longhorn-manager

go 1.22.2

replace github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544 => github.com/chanyilin/types v0.0.0-20240716081512-9303475fbf48

replace github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e => github.com/chanyilin/go-common-libs v0.0.0-20240716074450-cdf55483e4fc

replace github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3 => github.com/chanyilin/backupstore v0.0.0-20240716083705-c30b8fd2d973

replace github.com/longhorn/backing-image-manager v1.7.0-rc1 => github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240716084737-82b41eeaef6c

// 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
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,14 @@ 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.20240716084737-82b41eeaef6c h1:JmwT34fDctCXWBSJPfVpYohRhbJuY5jG9VYO1NTp/jM=
github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240716084737-82b41eeaef6c/go.mod h1:yDySyRZEP9J/xN27UwvMEzzEv38AlLYJjkf+GA133p4=
github.com/chanyilin/backupstore v0.0.0-20240716083705-c30b8fd2d973 h1:xhIQYJINAZgcVpclvnPBLxMCUWRs1kZ18NVwPg58Wu0=
github.com/chanyilin/backupstore v0.0.0-20240716083705-c30b8fd2d973/go.mod h1:n7cpM9QLOl1KxaTFA1t3WEtiCo3vM7KNHCWXkzmTwkE=
github.com/chanyilin/go-common-libs v0.0.0-20240716074450-cdf55483e4fc h1:t2Sumlm9ZEw6QvH1k4LF1NAjFQIT3skTp3kRXsBMBQI=
github.com/chanyilin/go-common-libs v0.0.0-20240716074450-cdf55483e4fc/go.mod h1:vX53A9KF4RHC1UTbEGouZHsZO6bwT3zk63l1hvwF5T8=
github.com/chanyilin/types v0.0.0-20240716081512-9303475fbf48 h1:9jzwp7CVYzxHy4HOp6SEUgJOiHS40KUwUZxDzbSJALU=
github.com/chanyilin/types v0.0.0-20240716081512-9303475fbf48/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 @@ -1220,12 +1228,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-20240709004445-1cadf9073de3 h1:DCNyiGtXlYKMdXBm7p3l86pXEaP0klFpes+BtLYleQc=
github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3/go.mod h1:IJ7rVDB0l5J8YBFgvbYRM0dCF9pLhnIToia+4PDzNqY=
github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e h1:0SiyvTuovYc9kLJbjagTSxv3sOfCCU9FQJasRo7bgzU=
github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e/go.mod h1:vX53A9KF4RHC1UTbEGouZHsZO6bwT3zk63l1hvwF5T8=
github.com/longhorn/go-iscsi-helper v0.0.0-20240708025845-7cc78e60866a h1:8FYqfmKkssHYiZqgpnodiyzjPkYmqSViEjXdCvij3rQ=
github.com/longhorn/go-iscsi-helper v0.0.0-20240708025845-7cc78e60866a/go.mod h1:ZP3plRH+n4J+t16PdgQ8c8QGhoR1OZAs+/1mhPnpyP4=
github.com/longhorn/go-spdk-helper v0.0.0-20240712141652-3cdeed2b60e4 h1:QgisqeLK3XaxImru/uF/S6B501fT16udzvxs9S8Jko4=
Expand All @@ -1236,8 +1238,6 @@ github.com/longhorn/longhorn-instance-manager v1.7.0-rc1 h1:9hugpEQEmK6tMa1zY87G
github.com/longhorn/longhorn-instance-manager v1.7.0-rc1/go.mod h1:HIo3UCiH81EtTPwOujkKZIIQbvmJ1A3OeRHShHlAEV0=
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-20240706151541-33cb010c3544 h1:U08l+0SbxCsododsraBHB5PdXrQme3TEh9iaREhRLQs=
github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544/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
6 changes: 6 additions & 0 deletions k8s/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,12 @@ spec:
progress:
description: The backing image backup progress.
type: integer
secret:
description: Record the secret if this backup backing image is encrytpted
type: string
secretNamespace:
description: Record the secret namespace if this backup backing image is encrytpted
type: string
size:
description: The backing image size.
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}
6 changes: 6 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ type BackupBackingImageStatus struct {
// Compression method
// +optional
CompressionMethod BackupCompressionMethod `json:"compressionMethod"`
// Record the secret if this backup backing image is encrytpted

Check failure on line 67 in k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go

View workflow job for this annotation

GitHub Actions / codespell

encrytpted ==> encrypted
// +optional
Secret string `json:"secret"`
// Record the secret namespace if this backup backing image is encrytpted

Check failure on line 70 in k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go

View workflow job for this annotation

GitHub Actions / codespell

encrytpted ==> encrypted
// +optional
SecretNamespace string `json:"secretNamespace"`
}

// +genclient
Expand Down

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

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

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

5 changes: 5 additions & 0 deletions vendor/github.com/longhorn/go-common-libs/backup/types.go

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

Loading

0 comments on commit 975985a

Please sign in to comment.