|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 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 | + velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + |
| 23 | + "github.com/openshift/oadp-operator/internal/common/constant" |
| 24 | +) |
| 25 | + |
| 26 | +// NonAdminBackupSpec defines the desired state of NonAdminBackup |
| 27 | +type NonAdminBackupSpec struct { |
| 28 | + // BackupSpec defines the specification for a Velero backup. |
| 29 | + BackupSpec *velerov1.BackupSpec `json:"backupSpec"` |
| 30 | + |
| 31 | + // DeleteBackup removes the NonAdminBackup and its associated NonAdminRestores and VeleroBackup from the cluster, |
| 32 | + // as well as the corresponding data in object storage |
| 33 | + // +optional |
| 34 | + DeleteBackup bool `json:"deleteBackup,omitempty"` |
| 35 | +} |
| 36 | + |
| 37 | +// VeleroBackup contains information of the related Velero backup object. |
| 38 | +type VeleroBackup struct { |
| 39 | + // spec captures the current spec of the Velero backup. |
| 40 | + // +optional |
| 41 | + Spec *velerov1.BackupSpec `json:"spec,omitempty"` |
| 42 | + |
| 43 | + // status captures the current status of the Velero backup. |
| 44 | + // +optional |
| 45 | + Status *velerov1.BackupStatus `json:"status,omitempty"` |
| 46 | + |
| 47 | + // nacuuid references the Velero Backup object by it's label containing same NACUUID. |
| 48 | + // +optional |
| 49 | + NACUUID string `json:"nacuuid,omitempty"` |
| 50 | + |
| 51 | + // references the Velero Backup object by it's name. |
| 52 | + // +optional |
| 53 | + Name string `json:"name,omitempty"` |
| 54 | + |
| 55 | + // namespace references the Namespace in which Velero backup exists. |
| 56 | + // +optional |
| 57 | + Namespace string `json:"namespace,omitempty"` |
| 58 | +} |
| 59 | + |
| 60 | +// VeleroDeleteBackupRequest contains information of the related Velero delete backup request object. |
| 61 | +type VeleroDeleteBackupRequest struct { |
| 62 | + // status captures the current status of the Velero delete backup request. |
| 63 | + // +optional |
| 64 | + Status *velerov1.DeleteBackupRequestStatus `json:"status,omitempty"` |
| 65 | + |
| 66 | + // nacuuid references the Velero delete backup request object by it's label containing same NACUUID. |
| 67 | + // +optional |
| 68 | + NACUUID string `json:"nacuuid,omitempty"` |
| 69 | + |
| 70 | + // name references the Velero delete backup request object by it's name. |
| 71 | + // +optional |
| 72 | + Name string `json:"name,omitempty"` |
| 73 | + |
| 74 | + // namespace references the Namespace in which Velero delete backup request exists. |
| 75 | + // +optional |
| 76 | + Namespace string `json:"namespace,omitempty"` |
| 77 | +} |
| 78 | + |
| 79 | +// DataMoverDataUploads contains information of the related Velero DataUpload objects. |
| 80 | +type DataMoverDataUploads struct { |
| 81 | + // number of DataUploads related to this NonAdminBackup's Backup |
| 82 | + // +optional |
| 83 | + Total int `json:"total,omitempty"` |
| 84 | + |
| 85 | + // number of DataUploads related to this NonAdminBackup's Backup in phase New |
| 86 | + // +optional |
| 87 | + New int `json:"new,omitempty"` |
| 88 | + |
| 89 | + // number of DataUploads related to this NonAdminBackup's Backup in phase Accepted |
| 90 | + // +optional |
| 91 | + Accepted int `json:"accepted,omitempty"` |
| 92 | + |
| 93 | + // number of DataUploads related to this NonAdminBackup's Backup in phase Prepared |
| 94 | + // +optional |
| 95 | + Prepared int `json:"prepared,omitempty"` |
| 96 | + |
| 97 | + // number of DataUploads related to this NonAdminBackup's Backup in phase InProgress |
| 98 | + // +optional |
| 99 | + InProgress int `json:"inProgress,omitempty"` |
| 100 | + |
| 101 | + // number of DataUploads related to this NonAdminBackup's Backup in phase Canceling |
| 102 | + // +optional |
| 103 | + Canceling int `json:"canceling,omitempty"` |
| 104 | + |
| 105 | + // number of DataUploads related to this NonAdminBackup's Backup in phase Canceled |
| 106 | + // +optional |
| 107 | + Canceled int `json:"canceled,omitempty"` |
| 108 | + |
| 109 | + // number of DataUploads related to this NonAdminBackup's Backup in phase Failed |
| 110 | + // +optional |
| 111 | + Failed int `json:"failed,omitempty"` |
| 112 | + |
| 113 | + // number of DataUploads related to this NonAdminBackup's Backup in phase Completed |
| 114 | + // +optional |
| 115 | + Completed int `json:"completed,omitempty"` |
| 116 | +} |
| 117 | + |
| 118 | +// FileSystemPodVolumeBackups contains information of the related Velero PodVolumeBackup objects. |
| 119 | +type FileSystemPodVolumeBackups struct { |
| 120 | + // number of PodVolumeBackups related to this NonAdminBackup's Backup |
| 121 | + // +optional |
| 122 | + Total int `json:"total,omitempty"` |
| 123 | + |
| 124 | + // number of PodVolumeBackups related to this NonAdminBackup's Backup in phase New |
| 125 | + // +optional |
| 126 | + New int `json:"new,omitempty"` |
| 127 | + |
| 128 | + // number of PodVolumeBackups related to this NonAdminBackup's Backup in phase InProgress |
| 129 | + // +optional |
| 130 | + InProgress int `json:"inProgress,omitempty"` |
| 131 | + |
| 132 | + // number of PodVolumeBackups related to this NonAdminBackup's Backup in phase Failed |
| 133 | + // +optional |
| 134 | + Failed int `json:"failed,omitempty"` |
| 135 | + |
| 136 | + // number of PodVolumeBackups related to this NonAdminBackup's Backup in phase Completed |
| 137 | + // +optional |
| 138 | + Completed int `json:"completed,omitempty"` |
| 139 | +} |
| 140 | + |
| 141 | +// NonAdminBackupStatus defines the observed state of NonAdminBackup |
| 142 | +type NonAdminBackupStatus struct { |
| 143 | + // +optional |
| 144 | + VeleroBackup *VeleroBackup `json:"veleroBackup,omitempty"` |
| 145 | + |
| 146 | + // +optional |
| 147 | + VeleroDeleteBackupRequest *VeleroDeleteBackupRequest `json:"veleroDeleteBackupRequest,omitempty"` |
| 148 | + |
| 149 | + // +optional |
| 150 | + DataMoverDataUploads *DataMoverDataUploads `json:"dataMoverDataUploads,omitempty"` |
| 151 | + |
| 152 | + // +optional |
| 153 | + FileSystemPodVolumeBackups *FileSystemPodVolumeBackups `json:"fileSystemPodVolumeBackups,omitempty"` |
| 154 | + |
| 155 | + // queueInfo is used to estimate how many backups are scheduled before the given VeleroBackup in the OADP namespace. |
| 156 | + // This number is not guaranteed to be accurate, but it should be close. It's inaccurate for cases when |
| 157 | + // Velero pod is not running or being restarted after Backup object were created. |
| 158 | + // It counts only VeleroBackups that are still subject to be handled by OADP/Velero. |
| 159 | + // +optional |
| 160 | + QueueInfo *QueueInfo `json:"queueInfo,omitempty"` |
| 161 | + |
| 162 | + // phase is a simple one high-level summary of the lifecycle of an NonAdminBackup. |
| 163 | + Phase NonAdminPhase `json:"phase,omitempty"` |
| 164 | + |
| 165 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 166 | +} |
| 167 | + |
| 168 | +// +kubebuilder:object:root=true |
| 169 | +// +kubebuilder:subresource:status |
| 170 | +// +kubebuilder:resource:path=nonadminbackups,shortName=nab |
| 171 | +// +kubebuilder:printcolumn:name="Request-Phase",type="string",JSONPath=".status.phase" |
| 172 | +// +kubebuilder:printcolumn:name="Velero-Phase",type="string",JSONPath=".status.veleroBackup.status.phase" |
| 173 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 174 | + |
| 175 | +// NonAdminBackup is the Schema for the nonadminbackups API |
| 176 | +type NonAdminBackup struct { |
| 177 | + Spec NonAdminBackupSpec `json:"spec,omitempty"` |
| 178 | + Status NonAdminBackupStatus `json:"status,omitempty"` |
| 179 | + |
| 180 | + metav1.TypeMeta `json:",inline"` |
| 181 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 182 | +} |
| 183 | + |
| 184 | +// +kubebuilder:object:root=true |
| 185 | + |
| 186 | +// NonAdminBackupList contains a list of NonAdminBackup |
| 187 | +type NonAdminBackupList struct { |
| 188 | + metav1.TypeMeta `json:",inline"` |
| 189 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 190 | + Items []NonAdminBackup `json:"items"` |
| 191 | +} |
| 192 | + |
| 193 | +func init() { |
| 194 | + SchemeBuilder.Register(&NonAdminBackup{}, &NonAdminBackupList{}) |
| 195 | +} |
| 196 | + |
| 197 | +// Helper Functions to avoid digging into NAB controller to understand how to get desired values |
| 198 | + |
| 199 | +// VeleroBackupName returns the name of the VeleroBackup object. |
| 200 | +func (nab *NonAdminBackup) VeleroBackupName() string { |
| 201 | + if nab.Status.VeleroBackup == nil { |
| 202 | + return constant.EmptyString |
| 203 | + } |
| 204 | + return nab.Status.VeleroBackup.Name |
| 205 | +} |
| 206 | + |
| 207 | +// UsesNaBSL returns true if backup is using NonAdminBackupStorageLocation |
| 208 | +func (nab *NonAdminBackup) UsesNaBSL() bool { |
| 209 | + return nab.Spec.BackupSpec != nil && nab.Spec.BackupSpec.StorageLocation != constant.EmptyString |
| 210 | +} |
0 commit comments