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 Sep 5, 2024
1 parent 1cd29fd commit a404dab
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 @@ -60,12 +60,12 @@ 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.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-20240827171022-9fe38fff5b51
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 @@ -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.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 @@ -167,8 +167,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-20240827171022-9fe38fff5b51 h1:qU69qwOdcJyDG36Bgp4/b/lydmpJZsPVx+bpszrzQFc=
github.com/longhorn/go-spdk-helper v0.0.0-20240827171022-9fe38fff5b51/go.mod h1:i9btdUP+14isigk+vOfANF7MQAbDO+u/ixeA/oOUwtA=
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 @@ -232,7 +232,7 @@ github.com/kylelemons/godebug/diff
# 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 @@ -271,7 +271,7 @@ github.com/longhorn/go-iscsi-helper/util
# github.com/longhorn/go-spdk-helper v0.0.0-20240827171022-9fe38fff5b51
## 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 a404dab

Please sign in to comment.