Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Feb 5, 2025
1 parent 303a532 commit 0af1089
Show file tree
Hide file tree
Showing 14 changed files with 927 additions and 336 deletions.
12 changes: 12 additions & 0 deletions api/v1/mantlebackup_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -45,6 +46,17 @@ type MantleBackupStatus struct {

// 'snapID' indicates SNAPID of `rbd snap ls`
SnapID *int `json:"snapID,omitempty"`

//+kubebuilder:default:=-1
LargestCompletedExportPartNum int `json:"largestCompletedExportPartNum,omitempty"`

//+kubebuilder:default:=-1
LargestCompletedUploadPartNum int `json:"largestCompletedUploadPartNum,omitempty"`

//+kubebuilder:default:=-1
LargestCompletedImportPartNum int `json:"largestCompletedImportPartNum,omitempty"`

TransferPartSize *resource.Quantity `json:"transferPartSize,omitempty"`
}

const (
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ spec:
description: '''createdAt'' specifies the creation date and time'
format: date-time
type: string
largestCompletedExportPartNum:
default: -1
type: integer
largestCompletedImportPartNum:
default: -1
type: integer
largestCompletedUploadPartNum:
default: -1
type: integer
pvManifest:
description: '''pvManifest'' saving backup target PV manifest'
type: string
Expand All @@ -133,6 +142,12 @@ spec:
snapID:
description: '''snapID'' indicates SNAPID of `rbd snap ls`'
type: integer
transferPartSize:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
served: true
Expand Down
15 changes: 15 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -50,6 +51,7 @@ var (
role string
mantleServiceEndpoint string
maxExportJobs int
maxUploadJobs int
exportDataStorageClass string
envSecret string
objectStorageBucketName string
Expand All @@ -60,6 +62,7 @@ var (
httpProxy string
httpsProxy string
noProxy string
backupTransferPartSize string

scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand All @@ -86,6 +89,8 @@ func init() {
"this option is required and is interpreted as the address that the secondary mantle should listen to.")
flags.IntVar(&maxExportJobs, "max-export-jobs", 8,
"The maximum number of export jobs that can run simultaneously. If you set this to 0, there is no limit.")
flags.IntVar(&maxUploadJobs, "max-upload-jobs", 8,
"The maximum number of export jobs that can run simultaneously. If you set this to 0, there is no limit.")
flags.StringVar(&exportDataStorageClass, "export-data-storage-class", "",
"The storage class of PVCs used to store exported data temporarily.")
flags.StringVar(&envSecret, "env-secret", "",
Expand All @@ -107,6 +112,8 @@ func init() {
"The proxy URL for HTTPS requests to the object storage and the gRPC endpoint of secondary mantle.")
flags.StringVar(&noProxy, "no-proxy", "",
"A string that contains comma-separated values specifying hosts that should be excluded from proxying.")
flags.StringVar(&backupTransferPartSize, "backup-transfer-part-size", "200Gi",
"The size of each backup data chunk to be transferred at a time.")

goflags := flag.NewFlagSet("goflags", flag.ExitOnError)
zapOpts.Development = true
Expand Down Expand Up @@ -174,6 +181,12 @@ func setupReconcilers(mgr manager.Manager, primarySettings *controller.PrimarySe
return err
}

parsedBackupTransferPartSize, err := resource.ParseQuantity(backupTransferPartSize)
if err != nil {
setupLog.Error(err, "failed to parse backup-transfer-part-size", "value", backupTransferPartSize)
return fmt.Errorf("failed to parse backup-transfer-part-size: %w", err)
}

backupReconciler := controller.NewMantleBackupReconciler(
mgr.GetClient(),
mgr.GetScheme(),
Expand All @@ -193,6 +206,7 @@ func setupReconcilers(mgr manager.Manager, primarySettings *controller.PrimarySe
HttpsProxy: httpsProxy,
NoProxy: noProxy,
},
parsedBackupTransferPartSize,
)
if err := backupReconciler.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "MantleBackup")
Expand Down Expand Up @@ -287,6 +301,7 @@ func setupPrimary(ctx context.Context, mgr manager.Manager, wg *sync.WaitGroup)
Conn: conn,
Client: proto.NewMantleServiceClient(conn),
MaxExportJobs: maxExportJobs,
MaxUploadJobs: maxUploadJobs,
ExportDataStorageClass: exportDataStorageClass,
}

Expand Down
15 changes: 15 additions & 0 deletions config/crd/bases/mantle.cybozu.io_mantlebackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ spec:
description: '''createdAt'' specifies the creation date and time'
format: date-time
type: string
largestCompletedExportPartNum:
default: -1
type: integer
largestCompletedImportPartNum:
default: -1
type: integer
largestCompletedUploadPartNum:
default: -1
type: integer
pvManifest:
description: '''pvManifest'' saving backup target PV manifest'
type: string
Expand All @@ -133,6 +142,12 @@ spec:
snapID:
description: '''snapID'' indicates SNAPID of `rbd snap ls`'
type: integer
transferPartSize:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
served: true
Expand Down
Loading

0 comments on commit 0af1089

Please sign in to comment.