github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/apis/dataprotection/v1alpha1/backuprepo_types.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha1
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  	"k8s.io/apimachinery/pkg/api/resource"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  )
    24  
    25  // AccessMethod is an enum type that defines the access method of the backup repo.
    26  type AccessMethod string
    27  
    28  const (
    29  	// AccessMethodMount means that the storage is mounted locally,
    30  	// so that remote files can be accessed just like a local file.
    31  	AccessMethodMount AccessMethod = "Mount"
    32  	// AccessMethodTool means to access the storage with a command-line tool,
    33  	// which helps to transfer files between the storage and local.
    34  	AccessMethodTool AccessMethod = "Tool"
    35  )
    36  
    37  // BackupRepoSpec defines the desired state of BackupRepo
    38  type BackupRepoSpec struct {
    39  	// The storage provider used by this backup repo.
    40  	// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="StorageProviderRef is immutable"
    41  	// +kubebuilder:validation:Required
    42  	StorageProviderRef string `json:"storageProviderRef"`
    43  
    44  	// Specifies the access method of the backup repo.
    45  	// +kubebuilder:validation:Enum={Mount,Tool}
    46  	// +kubebuilder:default=Mount
    47  	// +optional
    48  	AccessMethod AccessMethod `json:"accessMethod,omitempty"`
    49  
    50  	// The requested capacity for the PVC created by this backup repo.
    51  	// +optional
    52  	VolumeCapacity resource.Quantity `json:"volumeCapacity,omitempty"`
    53  
    54  	// The reclaim policy for the PV created by this backup repo.
    55  	// +kubebuilder:validation:Enum={Delete,Retain}
    56  	// +kubebuilder:validation:Required
    57  	PVReclaimPolicy corev1.PersistentVolumeReclaimPolicy `json:"pvReclaimPolicy"`
    58  
    59  	// Non-secret configurations for the storage provider.
    60  	// +optional
    61  	Config map[string]string `json:"config,omitempty"`
    62  
    63  	// A secret that contains the credentials needed by the storage provider.
    64  	// +optional
    65  	Credential *corev1.SecretReference `json:"credential,omitempty"`
    66  }
    67  
    68  // BackupRepoStatus defines the observed state of BackupRepo
    69  type BackupRepoStatus struct {
    70  	// Backup repo reconciliation phases. Valid values are PreChecking, Failed, Ready, Deleting.
    71  	// +kubebuilder:validation:Enum={PreChecking,Failed,Ready,Deleting}
    72  	// +optional
    73  	Phase BackupRepoPhase `json:"phase,omitempty"`
    74  
    75  	// conditions describes the current state of the repo.
    76  	// +optional
    77  	Conditions []metav1.Condition `json:"conditions,omitempty"`
    78  
    79  	// observedGeneration is the latest generation observed by the controller.
    80  	// +optional
    81  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
    82  
    83  	// generatedCSIDriverSecret references the generated secret used by the CSI driver.
    84  	// +optional
    85  	GeneratedCSIDriverSecret *corev1.SecretReference `json:"generatedCSIDriverSecret,omitempty"`
    86  
    87  	// generatedStorageClassName indicates the generated storage class name.
    88  	// +optional
    89  	GeneratedStorageClassName string `json:"generatedStorageClassName,omitempty"`
    90  
    91  	// backupPVCName is the name of the PVC used to store backup data.
    92  	// +optional
    93  	BackupPVCName string `json:"backupPVCName,omitempty"`
    94  
    95  	// toolConfigSecretName is the name of the secret containing the configuration for the access tool.
    96  	// +optional
    97  	ToolConfigSecretName string `json:"toolConfigSecretName,omitempty"`
    98  
    99  	// isDefault indicates whether this backup repo is the default one.
   100  	// +optional
   101  	IsDefault bool `json:"isDefault,omitempty"`
   102  }
   103  
   104  // +genclient
   105  // +genclient:nonNamespaced
   106  // +k8s:openapi-gen=true
   107  // +kubebuilder:object:root=true
   108  // +kubebuilder:subresource:status
   109  // +kubebuilder:resource:path=backuprepos,categories={kubeblocks},scope=Cluster
   110  // +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.phase"
   111  // +kubebuilder:printcolumn:name="STORAGEPROVIDER",type="string",JSONPath=".spec.storageProviderRef"
   112  // +kubebuilder:printcolumn:name="ACCESSMETHOD",type="string",JSONPath=".spec.accessMethod"
   113  // +kubebuilder:printcolumn:name="DEFAULT",type="boolean",JSONPath=`.status.isDefault`
   114  // +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
   115  
   116  // BackupRepo is the Schema for the backuprepos API
   117  type BackupRepo struct {
   118  	metav1.TypeMeta   `json:",inline"`
   119  	metav1.ObjectMeta `json:"metadata,omitempty"`
   120  
   121  	Spec   BackupRepoSpec   `json:"spec,omitempty"`
   122  	Status BackupRepoStatus `json:"status,omitempty"`
   123  }
   124  
   125  // +kubebuilder:object:root=true
   126  
   127  // BackupRepoList contains a list of BackupRepo
   128  type BackupRepoList struct {
   129  	metav1.TypeMeta `json:",inline"`
   130  	metav1.ListMeta `json:"metadata,omitempty"`
   131  	Items           []BackupRepo `json:"items"`
   132  }
   133  
   134  func init() {
   135  	SchemeBuilder.Register(&BackupRepo{}, &BackupRepoList{})
   136  }
   137  
   138  func (repo *BackupRepo) AccessByMount() bool {
   139  	return repo.Spec.AccessMethod == "" || repo.Spec.AccessMethod == AccessMethodMount
   140  }
   141  
   142  func (repo *BackupRepo) AccessByTool() bool {
   143  	return repo.Spec.AccessMethod == AccessMethodTool
   144  }