Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nebula scheduled backup CRD #416

Merged
merged 11 commits into from
Jan 27, 2024
60 changes: 46 additions & 14 deletions apis/apps/v1alpha1/backupschedule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,56 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// BackupConditionType represents a valid condition of a Backup.
type ScheduledBackupConditionType string

const (
// ScheduledBackupPending means the scheduled backup job is pending, waiting for creation of the backup cronjob
ScheduledBackupPending ScheduledBackupConditionType = "Pending"
// ScheduledBackupScheduled means the scheduled backup cronjob was created successfully and no active backup jobs are running
// if there was an active backup job, the job has executed successfully and the backup data has been loaded into the nebula cluster.
ScheduledBackupScheduled ScheduledBackupConditionType = "Scheduled"
// ScheduledBackupRunning means there's an active backup job current running.
ScheduledBackupRunning ScheduledBackupConditionType = "Running"
// ScheduledBackupPaused means the schedule backup is currently suspended
ScheduledBackupPaused ScheduledBackupConditionType = "Paused"
// ScheduledBackupJobFailed means the active backup job has failed to execute successfully
ScheduledBackupJobFailed ScheduledBackupConditionType = "Backup job failed"
// BackupFailed means the backup cron job creation has failed.
ScheduledBackupFailed ScheduledBackupConditionType = "Cron Creation Failed"
kevinliu24 marked this conversation as resolved.
Show resolved Hide resolved
// BackupInvalid means invalid backup CR.
ScheduledBackupInvalid ScheduledBackupConditionType = "Invalid"
)

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName="bs"
// +kubebuilder:resource:shortName="nsb"
// +kubebuilder:printcolumn:name="Schedule",type=string,JSONPath=`.spec.schedule`,description="The current schedule set for the scheduled backup"
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.phase`,description="The current status of the scheduled backup"
// +kubebuilder:printcolumn:name="Last Backup Time",format=date-time,type=string,JSONPath=`.status.lastBackupTime`,description="The timestamp at which the last backup was ran"
// +kubebuilder:printcolumn:name="Next Backup Time",format=date-time,type=string,JSONPath=`.status.nextBackupTime`,description="The timestamp at which the next backup will ran"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

type BackupSchedule struct {
type NebulaScheduledBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BackupScheduleSpec `json:"spec,omitempty"`
Status BackupScheduleStatus `json:"status,omitempty"`
Spec ScheduledBackupSpec `json:"spec,omitempty"`
Status ScheduledBackupStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// BackupScheduleList contains a list of BackupSchedule.
type BackupScheduleList struct {
// NebulaScheduledBackupList contains a list of NebulaScheduledBackup.
type NebulaScheduledBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []BackupSchedule `json:"items"`
Items []NebulaScheduledBackup `json:"items"`
}

// BackupScheduleSpec contains the specification for a backupSchedule of a nebula cluster backupSchedule.
type BackupScheduleSpec struct {
// ScheduledBackupSpec contains the specification for a NebulaScheduledBackup of a nebula cluster NebulaScheduledBackup.
type ScheduledBackupSpec struct {
// Schedule specifies the cron string used for backup scheduling.
Schedule string `json:"schedule"`
// Pause means paused backupSchedule
kevinliu24 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -60,14 +86,20 @@ type BackupScheduleSpec struct {
// LogBackupTemplate is the specification of the log backup structure to get scheduled.
}

// BackupScheduleStatus represents the current status of a nebula cluster backupSchedule.
type BackupScheduleStatus struct {
// LastBackup represents the last backup.
LastBackup string `json:"lastBackup,omitempty"`
// ScheduledBackupStatus represents the current status of a nebula cluster NebulaScheduledBackup.
type ScheduledBackupStatus struct {
// LastBackup represents the last backup. Used for scheduled incremental backups. Not supported for now.
//LastBackup string `json:"lastBackup,omitempty"`
// CurrSchedule represents the current backup schedule
CurrSchedule string `json:"currSchedule,omitempty"`
// LastBackupTime represents the last time the backup was successfully created.
LastBackupTime *metav1.Time `json:"lastBackupTime,omitempty"`
// NextBackupTime represent the next time the backup will be run.
NextBackupTime *metav1.Time `json:"nextBackupTime,omitempty"`
// Phase represents the status of the scheduled backup
Phase ScheduledBackupConditionType `json:"phase,omitempty"`
}

func init() {
SchemeBuilder.Register(&BackupSchedule{}, &BackupScheduleList{})
SchemeBuilder.Register(&NebulaScheduledBackup{}, &NebulaScheduledBackupList{})
}
6 changes: 6 additions & 0 deletions apis/apps/v1alpha1/nebulabackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ type BackupSpec struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

BR *BRConfig `json:"br,omitempty"`

// MaxBackups is to specify how many backups we want to keep. Used for scheduled backups only.
MaxBackups *int32 `json:"maxBackups,omitempty"`

// MaxReservedTime is to specify how long backups we want to keep. Used for scheduled backups only.
MaxReservedTime *string `json:"maxReservedTime,omitempty"`
kevinliu24 marked this conversation as resolved.
Show resolved Hide resolved
kevinliu24 marked this conversation as resolved.
Show resolved Hide resolved
}

// BackupStatus represents the current status of a nebula cluster backup.
Expand Down
38 changes: 19 additions & 19 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions cmd/controller-manager/app/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/vesoft-inc/nebula-operator/pkg/controller/nebulabackup"
"github.com/vesoft-inc/nebula-operator/pkg/controller/nebulacluster"
"github.com/vesoft-inc/nebula-operator/pkg/controller/nebularestore"
"github.com/vesoft-inc/nebula-operator/pkg/controller/nebulascheduledbackup"
klogflag "github.com/vesoft-inc/nebula-operator/pkg/flag/klog"
profileflag "github.com/vesoft-inc/nebula-operator/pkg/flag/profile"
"github.com/vesoft-inc/nebula-operator/pkg/version"
Expand Down Expand Up @@ -180,6 +181,15 @@ func Run(ctx context.Context, opts *options.Options) error {
return err
}

scheduledBackupReconciler, err := nebulascheduledbackup.NewBackupReconciler(mgr)
if err != nil {
return err
}

if err := scheduledBackupReconciler.SetupWithManager(mgr); err != nil {
klog.Errorf("failed to set up ScheduledNebulaBackup controller: %v", err)
}

if opts.EnableAdmissionWebhook {
decoder := admission.NewDecoder(mgr.GetScheme())
klog.Info("Registering webhooks to nebula-controller-manager")
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/apps.nebula-graph.io_nebulabackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
maxBackups:
format: int32
type: integer
maxReservedTime:
type: string
nodeSelector:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,41 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
name: backupschedules.apps.nebula-graph.io
name: nebulascheduledbackups.apps.nebula-graph.io
spec:
group: apps.nebula-graph.io
names:
kind: BackupSchedule
listKind: BackupScheduleList
plural: backupschedules
kind: NebulaScheduledBackup
listKind: NebulaScheduledBackupList
plural: nebulascheduledbackups
shortNames:
- bs
singular: backupschedule
- nsb
singular: nebulascheduledbackup
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: The current schedule set for the scheduled backup
jsonPath: .spec.schedule
name: Schedule
type: string
- description: The current status of the scheduled backup
jsonPath: .status.phase
name: Status
type: string
- description: The timestamp at which the last backup was ran
format: date-time
jsonPath: .status.lastBackupTime
name: Last Backup Time
type: string
- description: The timestamp at which the next backup will ran
format: date-time
jsonPath: .status.nextBackupTime
name: Next Backup Time
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
properties:
Expand Down Expand Up @@ -67,6 +89,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
maxBackups:
format: int32
type: integer
maxReservedTime:
type: string
nodeSelector:
additionalProperties:
type: string
Expand All @@ -89,11 +116,16 @@ spec:
type: object
status:
properties:
lastBackup:
currSchedule:
type: string
lastBackupTime:
format: date-time
type: string
nextBackupTime:
format: date-time
type: string
phase:
type: string
type: object
type: object
served: true
Expand Down
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# It should be run by config/default
resources:
- bases/apps.nebula-graph.io_nebulaclusters.yaml
- bases/apps.nebula-graph.io_nebulabackups.yaml
- bases/apps.nebula-graph.io_nebularestores.yaml
- bases/apps.nebula-graph.io_nebulascheduledbackups.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
2 changes: 1 addition & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ patchesStrategicMerge:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
# 'CERTMANAGER' needs to be enabled to use ca injection
- webhookcainjection_patch.yaml
#- webhookcainjection_patch.yaml

# the following config is for teaching kustomize how to do var substitution
vars:
Expand Down
Loading