From cc57b6d93987980001098a125eb46f6d116aac7f Mon Sep 17 00:00:00 2001 From: Jack Lin Date: Wed, 17 Jul 2024 16:01:00 +0800 Subject: [PATCH] feat(backupbackingimage): add parameters to backup backing image create proto ref: longhorn/longhorn 8884 Signed-off-by: Jack Lin --- api/model.go | 4 ++++ client/generated_backup_backing_image.go | 4 ++++ controller/backup_backing_image_controller.go | 2 ++ engineapi/backing_image_manager.go | 4 ++-- engineapi/backup_backing_image.go | 17 +++++++++++++++-- go.mod | 4 ++-- go.sum | 8 ++++---- k8s/crds.yaml | 6 ++++++ .../apis/longhorn/v1beta2/backupbackingimage.go | 6 ++++++ .../pkg/client/manager_client.go | 3 ++- vendor/modules.txt | 4 ++-- 11 files changed, 49 insertions(+), 13 deletions(-) diff --git a/api/model.go b/api/model.go index 9170fdf2d2..60df599c22 100644 --- a/api/model.go +++ b/api/model.go @@ -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 { @@ -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{ diff --git a/client/generated_backup_backing_image.go b/client/generated_backup_backing_image.go index c0fbfc1f43..4fcf01f9ed 100644 --- a/client/generated_backup_backing_image.go +++ b/client/generated_backup_backing_image.go @@ -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"` diff --git a/controller/backup_backing_image_controller.go b/controller/backup_backing_image_controller.go index d667869026..c8cc99db07 100644 --- a/controller/backup_backing_image_controller.go +++ b/controller/backup_backing_image_controller.go @@ -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 diff --git a/engineapi/backing_image_manager.go b/engineapi/backing_image_manager.go index 539a3b93b0..9d7df41ce9 100644 --- a/engineapi/backing_image_manager.go +++ b/engineapi/backing_image_manager.go @@ -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) { diff --git a/engineapi/backup_backing_image.go b/engineapi/backup_backing_image.go index 4e73a18180..46c4b48428 100644 --- a/engineapi/backup_backing_image.go +++ b/engineapi/backup_backing_image.go @@ -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" ) @@ -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") @@ -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 +} diff --git a/go.mod b/go.mod index f322f956d6..476f5071bb 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index aa83e9c434..2886099b4e 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/k8s/crds.yaml b/k8s/crds.yaml index ad2db96aba..4c691de0d5 100644 --- a/k8s/crds.yaml +++ b/k8s/crds.yaml @@ -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 diff --git a/k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go b/k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go index 8fbbfd69e8..3a741e2c62 100644 --- a/k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go +++ b/k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go @@ -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 diff --git a/vendor/github.com/longhorn/backing-image-manager/pkg/client/manager_client.go b/vendor/github.com/longhorn/backing-image-manager/pkg/client/manager_client.go index b9fc711b55..6947bce748 100644 --- a/vendor/github.com/longhorn/backing-image-manager/pkg/client/manager_client.go +++ b/vendor/github.com/longhorn/backing-image-manager/pkg/client/manager_client.go @@ -240,7 +240,7 @@ func (cli *BackingImageManagerClient) Watch() (*api.BackingImageStream, error) { return api.NewBackingImageStream(conn, cancel, stream), nil } -func (cli *BackingImageManagerClient) BackupCreate(name, uuid, checksum, backupTargetURL string, labels, credential map[string]string, compressionMethod string, concurrentLimit int) error { +func (cli *BackingImageManagerClient) BackupCreate(name, uuid, checksum, backupTargetURL string, labels, credential map[string]string, compressionMethod string, concurrentLimit int, parameters map[string]string) error { if name == "" || uuid == "" || checksum == "" { return fmt.Errorf("failed to create backup backing image: missing required parameter") } @@ -269,6 +269,7 @@ func (cli *BackingImageManagerClient) BackupCreate(name, uuid, checksum, backupT Credential: credential, CompressionMethod: compressionMethod, ConcurrentLimit: int32(concurrentLimit), + Parameters: parameters, }) return err } diff --git a/vendor/modules.txt b/vendor/modules.txt index d6c0fe59fe..cf9d1ed138 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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 @@ -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