Skip to content

Commit 4330231

Browse files
committed
feat(backupbackingimage): add parameters to backup backing image create proto
ref: longhorn/longhorn 8884 Signed-off-by: Jack Lin <[email protected]>
1 parent 06abbf3 commit 4330231

File tree

16 files changed

+198
-119
lines changed

16 files changed

+198
-119
lines changed

api/model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ type BackupBackingImage struct {
187187
Labels map[string]string `json:"labels"`
188188
Messages map[string]string `json:"messages"`
189189
CompressionMethod string `json:"compressionMethod"`
190+
Secret string `json:"secret"`
191+
SecretNamespace string `json:"secretNamespace"`
190192
}
191193

192194
type Setting struct {
@@ -1893,6 +1895,8 @@ func toBackupBackingImageResource(bbi *longhorn.BackupBackingImage, apiContext *
18931895
Labels: bbi.Status.Labels,
18941896
Messages: bbi.Status.Messages,
18951897
CompressionMethod: string(bbi.Status.CompressionMethod),
1898+
Secret: bbi.Status.Secret,
1899+
SecretNamespace: bbi.Status.SecretNamespace,
18961900
}
18971901

18981902
backupBackingImage.Actions = map[string]string{

client/generated_backup_backing_image.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ type BackupBackingImage struct {
2121

2222
Progress int64 `json:"progress,omitempty" yaml:"progress,omitempty"`
2323

24+
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
25+
26+
SecretNamespace string `json:"secretNamespace,omitempty" yaml:"secretNamespace,omitempty"`
27+
2428
Size int64 `json:"size,omitempty" yaml:"size,omitempty"`
2529

2630
State string `json:"state,omitempty" yaml:"state,omitempty"`

controller/backup_backing_image_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ func (bc *BackupBackingImageController) reconcile(backupBackingImageName string)
332332
bbi.Status.Checksum = backupBackingImageInfo.Checksum
333333
bbi.Status.Size = backupBackingImageInfo.Size
334334
bbi.Status.Labels = backupBackingImageInfo.Labels
335+
bbi.Status.Secret = backupBackingImageInfo.Secret
336+
bbi.Status.SecretNamespace = backupBackingImageInfo.SecretNamespace
335337
bbi.Status.CompressionMethod = longhorn.BackupCompressionMethod(backupBackingImageInfo.CompressionMethod)
336338
bbi.Status.LastSyncedAt = syncTime
337339
return nil

engineapi/backing_image_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ func (c *BackingImageManagerClient) VersionGet() (int, int, error) {
145145
return output.BackingImageManagerAPIMinVersion, output.BackingImageManagerAPIVersion, nil
146146
}
147147

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

150150
if err := CheckBackingImageManagerCompatibility(c.apiMinVersion, c.apiVersion); err != nil {
151151
return err
152152
}
153-
return c.grpcClient.BackupCreate(name, uuid, checksum, backupTargetURL, labels, credential, compressionMethod, concurrentLimit)
153+
return c.grpcClient.BackupCreate(name, uuid, checksum, backupTargetURL, labels, credential, compressionMethod, concurrentLimit, parameters)
154154
}
155155

156156
func (c *BackingImageManagerClient) BackupStatus(name string) (*longhorn.BackupBackingImageStatus, error) {

engineapi/backup_backing_image.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ import (
1616
"k8s.io/apimachinery/pkg/util/wait"
1717
"k8s.io/utils/clock"
1818

19+
lhbackup "github.com/longhorn/go-common-libs/backup"
20+
1921
"github.com/longhorn/backupstore/backupbackingimage"
20-
"github.com/longhorn/longhorn-manager/datastore"
22+
2123
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
24+
25+
"github.com/longhorn/longhorn-manager/datastore"
2226
"github.com/longhorn/longhorn-manager/types"
2327
)
2428

@@ -112,10 +116,12 @@ func NewBackupBackingImageMonitor(logger logrus.FieldLogger, ds *datastore.DataS
112116
quit: quit,
113117
}
114118

119+
backupBackingImageParameters := getBackupBackingImageParameters(backingImage)
120+
115121
// Call backing image manager API snapshot backup
116122
if bbi.Status.State == longhorn.BackupStateNew {
117123
err := m.client.BackupCreate(bbi.Name, backingImage.Status.UUID, bbi.Status.Checksum,
118-
backupTargetClient.URL, bbi.Spec.Labels, backupTargetClient.Credential, string(compressionMethod), concurrentLimit)
124+
backupTargetClient.URL, bbi.Spec.Labels, backupTargetClient.Credential, string(compressionMethod), concurrentLimit, backupBackingImageParameters)
119125
if err != nil {
120126
if !strings.Contains(err.Error(), "DeadlineExceeded") {
121127
m.logger.WithError(err).Warn("failed to take backing image backup")
@@ -258,3 +264,10 @@ func (m *BackupBackingImageMonitor) GetBackupBackingImageStatus() longhorn.Backu
258264
func (m *BackupBackingImageMonitor) Close() {
259265
m.quit()
260266
}
267+
268+
func getBackupBackingImageParameters(backingImage *longhorn.BackingImage) map[string]string {
269+
parameters := map[string]string{}
270+
parameters[lhbackup.LonghornBackupBackingImageParameterSecret] = string(backingImage.Spec.Secret)
271+
parameters[lhbackup.LonghornBackupBackingImageParameterSecretNamespace] = string(backingImage.Spec.SecretNamespace)
272+
return parameters
273+
}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ module github.com/longhorn/longhorn-manager
22

33
go 1.22.2
44

5+
replace github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544 => github.com/chanyilin/types v0.0.0-20240716081512-9303475fbf48
6+
7+
replace github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e => github.com/chanyilin/go-common-libs v0.0.0-20240716074450-cdf55483e4fc
8+
9+
replace github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3 => github.com/chanyilin/backupstore v0.0.0-20240716083705-c30b8fd2d973
10+
11+
replace github.com/longhorn/backing-image-manager v1.7.0-rc1 => github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240716084737-82b41eeaef6c
12+
513
// Replace directives are required for dependencies in this section because:
614
// - This module imports k8s.io/kubernetes.
715
// - The development for all of these dependencies is done at kubernetes/staging and then synced to other repos.

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,14 @@ github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
827827
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
828828
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
829829
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
830+
github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240716084737-82b41eeaef6c h1:JmwT34fDctCXWBSJPfVpYohRhbJuY5jG9VYO1NTp/jM=
831+
github.com/chanyilin/backing-image-manager v1.4.0-rc1.0.20240716084737-82b41eeaef6c/go.mod h1:yDySyRZEP9J/xN27UwvMEzzEv38AlLYJjkf+GA133p4=
832+
github.com/chanyilin/backupstore v0.0.0-20240716083705-c30b8fd2d973 h1:xhIQYJINAZgcVpclvnPBLxMCUWRs1kZ18NVwPg58Wu0=
833+
github.com/chanyilin/backupstore v0.0.0-20240716083705-c30b8fd2d973/go.mod h1:n7cpM9QLOl1KxaTFA1t3WEtiCo3vM7KNHCWXkzmTwkE=
834+
github.com/chanyilin/go-common-libs v0.0.0-20240716074450-cdf55483e4fc h1:t2Sumlm9ZEw6QvH1k4LF1NAjFQIT3skTp3kRXsBMBQI=
835+
github.com/chanyilin/go-common-libs v0.0.0-20240716074450-cdf55483e4fc/go.mod h1:vX53A9KF4RHC1UTbEGouZHsZO6bwT3zk63l1hvwF5T8=
836+
github.com/chanyilin/types v0.0.0-20240716081512-9303475fbf48 h1:9jzwp7CVYzxHy4HOp6SEUgJOiHS40KUwUZxDzbSJALU=
837+
github.com/chanyilin/types v0.0.0-20240716081512-9303475fbf48/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w=
830838
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
831839
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
832840
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -1220,12 +1228,6 @@ github.com/kubernetes-csi/csi-lib-utils v0.6.1 h1:+AZ58SRSRWh2vmMoWAAGcv7x6fIyBM
12201228
github.com/kubernetes-csi/csi-lib-utils v0.6.1/go.mod h1:GVmlUmxZ+SUjVLXicRFjqWUUvWez0g0Y78zNV9t7KfQ=
12211229
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
12221230
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
1223-
github.com/longhorn/backing-image-manager v1.7.0-rc1 h1:kD106yhLtofxDwXkvKs77VAFzTVdJnbxsD2m28X4tp0=
1224-
github.com/longhorn/backing-image-manager v1.7.0-rc1/go.mod h1:ZXD/+yKwMer/eZzwQ2ev/eAyLvih7WNq6NDgfUpvQ+8=
1225-
github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3 h1:DCNyiGtXlYKMdXBm7p3l86pXEaP0klFpes+BtLYleQc=
1226-
github.com/longhorn/backupstore v0.0.0-20240709004445-1cadf9073de3/go.mod h1:IJ7rVDB0l5J8YBFgvbYRM0dCF9pLhnIToia+4PDzNqY=
1227-
github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e h1:0SiyvTuovYc9kLJbjagTSxv3sOfCCU9FQJasRo7bgzU=
1228-
github.com/longhorn/go-common-libs v0.0.0-20240707062002-b9354601827e/go.mod h1:vX53A9KF4RHC1UTbEGouZHsZO6bwT3zk63l1hvwF5T8=
12291231
github.com/longhorn/go-iscsi-helper v0.0.0-20240708025845-7cc78e60866a h1:8FYqfmKkssHYiZqgpnodiyzjPkYmqSViEjXdCvij3rQ=
12301232
github.com/longhorn/go-iscsi-helper v0.0.0-20240708025845-7cc78e60866a/go.mod h1:ZP3plRH+n4J+t16PdgQ8c8QGhoR1OZAs+/1mhPnpyP4=
12311233
github.com/longhorn/go-spdk-helper v0.0.0-20240712141652-3cdeed2b60e4 h1:QgisqeLK3XaxImru/uF/S6B501fT16udzvxs9S8Jko4=
@@ -1236,8 +1238,6 @@ github.com/longhorn/longhorn-instance-manager v1.7.0-rc1 h1:9hugpEQEmK6tMa1zY87G
12361238
github.com/longhorn/longhorn-instance-manager v1.7.0-rc1/go.mod h1:HIo3UCiH81EtTPwOujkKZIIQbvmJ1A3OeRHShHlAEV0=
12371239
github.com/longhorn/longhorn-share-manager v1.7.0-rc1 h1:LsSkSajhG8tCfORKKfwK+8XHVrT/8rI9DRWb7fuoVls=
12381240
github.com/longhorn/longhorn-share-manager v1.7.0-rc1/go.mod h1:R6+NscPU4lAV5ueO7//lBCAO3en0aDbZi5KkkOSUJvk=
1239-
github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544 h1:U08l+0SbxCsododsraBHB5PdXrQme3TEh9iaREhRLQs=
1240-
github.com/longhorn/types v0.0.0-20240706151541-33cb010c3544/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w=
12411241
github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
12421242
github.com/lyft/protoc-gen-star v0.6.1/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
12431243
github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WVYF7/opLeUgcQs/o=

k8s/crds.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ spec:
712712
progress:
713713
description: The backing image backup progress.
714714
type: integer
715+
secret:
716+
description: Record the secret if this backup backing image is encrypted
717+
type: string
718+
secretNamespace:
719+
description: Record the secret namespace if this backup backing image is encrypted
720+
type: string
715721
size:
716722
description: The backing image size.
717723
format: int64

k8s/generate_code.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ if [[ ! -d "${GOPATH}/src/k8s.io/code-generator" ]]; then
3737
fi
3838

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

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

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

7878
echo "# Generated by the CRDs from ${APIS_DIR}" > ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/crds.yaml
79-
kustomize build ${CRDS_DIR} >> ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/crds.yaml
79+
${GOPATH}/bin/kustomize build ${CRDS_DIR} >> ${GOPATH}/src/${LH_MANAGER_DIR}/k8s/crds.yaml
8080
rm -r ${CRDS_DIR}

k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ type BackupBackingImageStatus struct {
6464
// Compression method
6565
// +optional
6666
CompressionMethod BackupCompressionMethod `json:"compressionMethod"`
67+
// Record the secret if this backup backing image is encrypted
68+
// +optional
69+
Secret string `json:"secret"`
70+
// Record the secret namespace if this backup backing image is encrypted
71+
// +optional
72+
SecretNamespace string `json:"secretNamespace"`
6773
}
6874

6975
// +genclient

vendor/github.com/longhorn/backing-image-manager/pkg/client/manager_client.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/longhorn/backupstore/backupbackingimage/backupbackingimage.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/longhorn/backupstore/backupbackingimage/config.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/longhorn/go-common-libs/backup/types.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)