Skip to content

Commit

Permalink
feature: syncleaf CRD and informer init
Browse files Browse the repository at this point in the history
Signed-off-by: renxiangyu <[email protected]>
  • Loading branch information
renxiangyu committed Jan 29, 2024
1 parent 1533eea commit f3b7c5d
Show file tree
Hide file tree
Showing 18 changed files with 1,365 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmd/clustertree/cluster-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ func run(ctx context.Context, opts *options.Options) error {
if err := rootPodReconciler.SetupWithManager(mgr); err != nil {
return fmt.Errorf("error starting rootPodReconciler %s: %v", podcontrollers.RootPodControllerName, err)
}
//
//syncLeafReconciler := controllers.SyncLeafReconciler{
// Client: mgr.GetClient(),
//}
//if err := syncLeafReconciler.SetupWithManager(mgr); err != nil {
// return fmt.Errorf("error starting rootPodReconciler %s: %v", podcontrollers.RootPodControllerName, err)
//}

if !opts.OnewayStorageControllers {
rootPVCController := pvc.RootPVCController{
Expand Down
121 changes: 121 additions & 0 deletions deploy/crds/kosmos.io_syncleaf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.13.0
name: syncleaves.kosmos.io
spec:
group: kosmos.io
names:
kind: SyncLeaf
listKind: SyncLeafList
plural: syncleaves
singular: syncleaf
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: SyncLeaf is custom resource that represents the capture of sync
leaf cluster
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: SyncLeafSpec defines the desired state of SyncLeaf
properties:
excludedNamespaceScopedResources:
description: ExcludedNamespaceScopedResources is a slice of namespace-scoped
resource type names to exclude from the backup. If set to "*", all
namespace-scoped resource types are excluded. The default value
is empty.
items:
type: string
nullable: true
type: array
excludedNamespaces:
description: ExcludedNamespaces contains a list of namespaces that
are not included in the backup.
items:
type: string
nullable: true
type: array
includedNamespaces:
description: IncludedNamespaces is a slice of namespace names to include
objects from. If empty, all namespaces are included.
items:
type: string
nullable: true
type: array
includedResources:
description: IncludedNamespaceScopedResources is a slice of namespace-scoped
resource type names to include in the backup. The default value
is "*".
items:
type: string
nullable: true
type: array
type: object
status:
description: SyncLeafStatus defines the observed state of SyncLeaf
properties:
completionTimestamp:
description: CompletionTimestamp records the time a sync was completed.
Completion time is recorded even on failed sync. The server's time
is used for CompletionTimestamps
format: date-time
nullable: true
type: string
failureReason:
description: FailureReason is an error that caused the entire sync
to fail.
type: string
phase:
description: Phase is the current state of the Backup.
type: string
precheckErrors:
description: PrecheckErrors is a slice of all precheck errors (if
applicable).
items:
type: string
nullable: true
type: array
progress:
description: Progress contains information about the sync's execution
progress. Note that this information is best-effort only -- if fails
to update it for any reason, it may be inaccurate/stale.
nullable: true
properties:
itemsBackedUp:
description: ItemsBackedUp is the number of items that have actually
been written to the backup tarball so far.
type: integer
totalItems:
description: TotalItems is the total number of items to be backed
up. This number may change throughout the execution of the backup
due to plugins that return additional related items to back
up, the velero.io/exclude-from-backup label, and various other
filters that happen as items are processed.
type: integer
type: object
startTimestamp:
description: StartTimestamp records the time a sync was started. The
server's time is used for StartTimestamps
format: date-time
nullable: true
type: string
type: object
type: object
served: true
storage: true
166 changes: 166 additions & 0 deletions pkg/apis/kosmos/v1alpha1/syncleaf_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

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

// SyncLeafSpec defines the desired state of SyncLeaf
type SyncLeafSpec struct {
// IncludedNamespaces is a slice of namespace names to include objects
// from. If empty, all namespaces are included.
// +optional
// +nullable
IncludedNamespaces []string `json:"includedNamespaces,omitempty"`

// ExcludedNamespaces contains a list of namespaces that are not
// included in the backup.
// +optional
// +nullable
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`

// IncludedNamespaceScopedResources is a slice of namespace-scoped
// resource type names to include in the backup.
// The default value is "*".
// +optional
// +nullable
IncludedNamespaceScopedResources []string `json:"includedResources,omitempty"`

// ExcludedNamespaceScopedResources is a slice of namespace-scoped
// resource type names to exclude from the backup.
// If set to "*", all namespace-scoped resource types are excluded.
// The default value is empty.
// +optional
// +nullable
ExcludedNamespaceScopedResources []string `json:"excludedNamespaceScopedResources,omitempty"`
}

// SyncLeafPhase is a string representation of the lifecycle phase
type SyncLeafPhase string

const (
// SyncLeafPhasePrecheck means in precheck progess
SyncLeafPhasePrecheck SyncLeafPhase = "Prechecking"

// SyncLeafPhaseFailedPrecheck means precheck has failed
SyncLeafPhaseFailedPrecheck SyncLeafPhase = "FailedPrecheck"

// SyncLeafPhaseBackup means in backup progess
SyncLeafPhaseBackup SyncLeafPhase = "Backuping"

// SyncLeafPhaseFailedBackup means backup has failed
SyncLeafPhaseFailedBackup SyncLeafPhase = "FailedBackup"

// SyncLeafPhaseDetach means in detach progess
SyncLeafPhaseDetach SyncLeafPhase = "Detaching"

// SyncLeafPhaseFailedDetach means detach has failed
SyncLeafPhaseFailedDetach SyncLeafPhase = "FailedDetach"

// SyncLeafPhaseRestore means in restore progess
SyncLeafPhaseRestore SyncLeafPhase = "Restoring"

// SyncLeafPhaseFailedRestore means restore has failed
SyncLeafPhaseFailedRestore SyncLeafPhase = "FailedRestore"

// SyncLeafPhaseCompleted means the sync has run successfully
SyncLeafPhaseCompleted SyncLeafPhase = "Completed"
)

// BackupProgress stores information about the progress of a Backup's execution.
type SyncLeafProgress struct {
// TotalItems is the total number of items to be backed up. This number may change
// throughout the execution of the backup due to plugins that return additional related
// items to back up, the velero.io/exclude-from-backup label, and various other
// filters that happen as items are processed.
// +optional
TotalItems int `json:"totalItems,omitempty"`

// ItemsBackedUp is the number of items that have actually been written to the
// backup tarball so far.
// +optional
ItemsBackedUp int `json:"itemsBackedUp,omitempty"`
}

// SyncLeafStatus defines the observed state of SyncLeaf
type SyncLeafStatus struct {
// Phase is the current state of the Backup.
// +optional
Phase SyncLeafPhase `json:"phase,omitempty"`

// PrecheckErrors is a slice of all precheck errors (if
// applicable).
// +optional
// +nullable
PrecheckErrors []string `json:"precheckErrors,omitempty"`

// StartTimestamp records the time a sync was started.
// The server's time is used for StartTimestamps
// +optional
// +nullable
StartTimestamp *metav1.Time `json:"startTimestamp,omitempty"`

// CompletionTimestamp records the time a sync was completed.
// Completion time is recorded even on failed sync.
// The server's time is used for CompletionTimestamps
// +optional
// +nullable
CompletionTimestamp *metav1.Time `json:"completionTimestamp,omitempty"`

// FailureReason is an error that caused the entire sync to fail.
// +optional
FailureReason string `json:"failureReason,omitempty"`

// Progress contains information about the sync's execution progress. Note
// that this information is best-effort only -- if fails to update it for any reason, it may be inaccurate/stale.
// +optional
// +nullable
Progress *SyncLeafProgress `json:"progress,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:object:generate=true
// +kubebuilder:storageversion
// +kubebuilder:rbac:groups=velero.io,resources=backups,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups=velero.io,resources=backups/status,verbs=get;update;patch

// SyncLeaf is custom resource that represents the capture of sync leaf cluster
type SyncLeaf struct {
metav1.TypeMeta `json:",inline"`

// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SyncLeafSpec `json:"spec,omitempty"`

Status SyncLeafStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BackupList is a list of SyncLeafs.
type SyncLeafList struct {
metav1.TypeMeta `json:",inline"`

// +optional
metav1.ListMeta `json:"metadata,omitempty"`

Items []SyncLeaf `json:"items"`
}
Loading

0 comments on commit f3b7c5d

Please sign in to comment.