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 Aug 28, 2024
1 parent c99b453 commit cc57b6d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 13 deletions.
4 changes: 4 additions & 0 deletions api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type BackupBackingImage struct {
Labels map[string]string `json:"labels"`
Messages map[string]string `json:"messages"`
CompressionMethod string `json:"compressionMethod"`
Secret string `json:"secret"`
SecretNamespace string `json:"secretNamespace"`
}

type Setting struct {
Expand Down Expand Up @@ -1873,6 +1875,8 @@ func toBackupBackingImageResource(bbi *longhorn.BackupBackingImage, apiContext *
Labels: bbi.Status.Labels,
Messages: bbi.Status.Messages,
CompressionMethod: string(bbi.Status.CompressionMethod),
Secret: bbi.Status.Secret,
SecretNamespace: bbi.Status.SecretNamespace,
}

backupBackingImage.Actions = map[string]string{
Expand Down
4 changes: 4 additions & 0 deletions client/generated_backup_backing_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type BackupBackingImage struct {

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

Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`

SecretNamespace string `json:"secretNamespace,omitempty" yaml:"secretNamespace,omitempty"`

Size int64 `json:"size,omitempty" yaml:"size,omitempty"`

State string `json:"state,omitempty" yaml:"state,omitempty"`
Expand Down
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
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/jinzhu/copier v0.3.5
github.com/kubernetes-csi/csi-lib-utils v0.6.1
github.com/longhorn/backing-image-manager v1.7.0-dev.0.20240823042906-1ae3d5073f60
github.com/longhorn/backing-image-manager v1.8.0-dev-20240825.0.20240828064910-e0449cbedcae
github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f
github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f
github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58
github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240824053610-9d2b194f765f
github.com/longhorn/longhorn-engine v1.8.0-dev-20240825
github.com/longhorn/longhorn-instance-manager v1.8.0-dev-20240825.0.20240828024302-1bdcacd93207
github.com/longhorn/longhorn-share-manager v1.7.0-rc1
github.com/pkg/errors v0.9.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@ 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-dev.0.20240823042906-1ae3d5073f60 h1:iZrC1Xq2k9fUVFkeZrD6X6UxaPZNr3jBZ5tyo+Efbhg=
github.com/longhorn/backing-image-manager v1.7.0-dev.0.20240823042906-1ae3d5073f60/go.mod h1:uRo+kg+oA0+5jcFtBcajOzAv6pXjy7gKUgwMEndn698=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240825.0.20240828064910-e0449cbedcae h1:fPsMlEy7I7Qx2EbuTGOjVkfkwAjCkTatFIeF3+fz8l4=
github.com/longhorn/backing-image-manager v1.8.0-dev-20240825.0.20240828064910-e0449cbedcae/go.mod h1:3IoBX6MkcjJefcwZNSoprmc/GgFfrTYYK44KtzaxI3g=
github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f h1:/Wo/leT2yrMmiDieCGhzqyzXb9FNsWoGeYWNfuf29KA=
github.com/longhorn/backupstore v0.0.0-20240827054225-fe89e488b75f/go.mod h1:N4cqNhSs4VUw9aGbO2OfyiIvJL7/L53hUrNiT73UN+U=
github.com/longhorn/go-common-libs v0.0.0-20240821134112-907f57efd48f h1:hjqUs3WVodkzrWwlUMVsnKAlom3uohoNlhZBGLsRvQY=
Expand All @@ -1227,8 +1227,8 @@ github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58 h1:fzLAnC
github.com/longhorn/go-iscsi-helper v0.0.0-20240811043302-df8de353dd58/go.mod h1:TobRDCXmF0Ni+jz6+nLJamw3uVu+gNDZoZre1JczGwc=
github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff h1:8vR29tkbmzmdqRVtOo5kL7Rs7nfhA6duXsmetIh1Tbg=
github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff/go.mod h1:Bzz7kGNYikAJqpmeV3cgN8jP1y9M+/oaiBc5iolIxuA=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240824053610-9d2b194f765f h1:Nsal/5akxiEyoBL+M0NOXiV5R96ACEgC64rK5w0VKcY=
github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240824053610-9d2b194f765f/go.mod h1:E1ec7ub7SNGvASDtiFHL1dXX4bhEQiroBixD2GGeRbQ=
github.com/longhorn/longhorn-engine v1.8.0-dev-20240825 h1:O0A7ebPjvVXXLN3r3oXYUV8D1v4qVC+6Cp/ATQstNQU=
github.com/longhorn/longhorn-engine v1.8.0-dev-20240825/go.mod h1:E1ec7ub7SNGvASDtiFHL1dXX4bhEQiroBixD2GGeRbQ=
github.com/longhorn/longhorn-instance-manager v1.8.0-dev-20240825.0.20240828024302-1bdcacd93207 h1:07e35ywxlYhF2yFgYko6Ni6tL4NyjeZU7eSm5pOvF6o=
github.com/longhorn/longhorn-instance-manager v1.8.0-dev-20240825.0.20240828024302-1bdcacd93207/go.mod h1:D6ciWSaUShhjZGK3V/IHgO0o1XOOmdIRUSGX59GDjiY=
github.com/longhorn/longhorn-share-manager v1.7.0-rc1 h1:LsSkSajhG8tCfORKKfwK+8XHVrT/8rI9DRWb7fuoVls=
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 encrypted
type: string
secretNamespace:
description: Record the secret namespace if this backup backing image is encrypted
type: string
size:
description: The backing image size.
format: int64
Expand Down
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 encrypted
// +optional
Secret string `json:"secret"`
// Record the secret namespace if this backup backing image is 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.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ github.com/kubernetes-csi/csi-lib-utils/protosanitizer
# github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
## explicit
github.com/liggitt/tabwriter
# github.com/longhorn/backing-image-manager v1.7.0-dev.0.20240823042906-1ae3d5073f60
# github.com/longhorn/backing-image-manager v1.8.0-dev-20240825.0.20240828064910-e0449cbedcae
## explicit; go 1.22.2
github.com/longhorn/backing-image-manager/api
github.com/longhorn/backing-image-manager/pkg/client
Expand Down Expand Up @@ -255,7 +255,7 @@ github.com/longhorn/go-iscsi-helper/util
# github.com/longhorn/go-spdk-helper v0.0.0-20240820144231-33c0873802ff
## explicit; go 1.22.0
github.com/longhorn/go-spdk-helper/pkg/types
# github.com/longhorn/longhorn-engine v1.7.0-dev.0.20240824053610-9d2b194f765f
# github.com/longhorn/longhorn-engine v1.8.0-dev-20240825
## explicit; go 1.22.2
github.com/longhorn/longhorn-engine/pkg/interceptor
github.com/longhorn/longhorn-engine/pkg/meta
Expand Down

0 comments on commit cc57b6d

Please sign in to comment.