Skip to content

Commit d4ed05f

Browse files
OADP-5901: DataProtectionTest CRD and Controller Implementation (#1714)
* Add DPT CRD and controller * Add s3 vendor determination * Add s3 vendor determination tests * Add cloud provider interface * Implement cloud provider interface for AWS * Add untils * Initialize provider and perform upload speed test * Handle aws profile from config * Resolve the backup location spec to be used from DPT * Add functionality to fetch bucket metadata: versioning and encryption * Add forceRun spec support, update spec timeouts datatype to metav1.Duration, fix aws vendor bug * update vendor determination and tests, minor fixes * Add unit tests for resolveBackupLocation, initializeProvider, runUploadTest and GetBucketMetadata * Add runSnapshotTests functionality * Code hardening and logging * Error handling for runSnapshotTests * Reconcile loop Error handling at DPT status level * Add printerColumns to DPT * Handle DPT status phase marking * Add snapshot.storage.k8s.io perms * Add snapshot summary * minor fixes * lint fix
1 parent 4ab8b14 commit d4ed05f

27 files changed

+2713
-6
lines changed

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ resources:
2929
kind: CloudStorage
3030
path: github.com/openshift/oadp-operator/api/v1alpha1
3131
version: v1alpha1
32+
- api:
33+
crdVersion: v1
34+
namespaced: true
35+
controller: true
36+
domain: openshift.io
37+
group: oadp
38+
kind: DataProtectionTest
39+
path: github.com/openshift/oadp-operator/api/v1alpha1
40+
version: v1alpha1
3241
version: "3"
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/*
2+
Copyright 2021.
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+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// DataProtectionTestSpec defines the desired tests to perform.
28+
type DataProtectionTestSpec struct {
29+
// backupLocationName specifies the name the Velero BackupStorageLocation (BSL) to test against.
30+
// +optional
31+
BackupLocationName string `json:"backupLocationName,omitempty"`
32+
33+
// backupLocationSpec is an inline copy of the BSL spec to use during testing.
34+
// +optional
35+
BackupLocationSpec *velerov1.BackupStorageLocationSpec `json:"backupLocationSpec,omitempty"`
36+
37+
// uploadSpeedTestConfig specifies parameters for an object storage upload speed test.
38+
// +optional
39+
UploadSpeedTestConfig *UploadSpeedTestConfig `json:"uploadSpeedTestConfig,omitempty"`
40+
41+
// csiVolumeSnapshotTestConfigs defines one or more CSI VolumeSnapshot tests to perform.
42+
// +optional
43+
CSIVolumeSnapshotTestConfigs []CSIVolumeSnapshotTestConfig `json:"csiVolumeSnapshotTestConfigs,omitempty"`
44+
45+
// forceRun will re-trigger the DPT even if it already completed
46+
// +kubebuilder:default=false
47+
// +optional
48+
ForceRun bool `json:"forceRun,omitempty"`
49+
}
50+
51+
// UploadSpeedTestConfig contains configuration for testing object storage upload performance.
52+
type UploadSpeedTestConfig struct {
53+
// fileSize is the size of data to upload, e.g., "100MB".
54+
// +optional
55+
FileSize string `json:"fileSize,omitempty"`
56+
57+
// timeout defines the maximum duration for the upload test, e.g., "60s".
58+
// +optional
59+
Timeout metav1.Duration `json:"timeout,omitempty"`
60+
}
61+
62+
// CSIVolumeSnapshotTestConfig contains config for performing a CSI VolumeSnapshot test.
63+
type CSIVolumeSnapshotTestConfig struct {
64+
// snapshotClassName specifies the CSI snapshot class to use.
65+
// +optional
66+
SnapshotClassName string `json:"snapshotClassName,omitempty"`
67+
68+
// timeout specifies how long to wait for the snapshot to become ready, e.g., "60s"
69+
// +optional
70+
Timeout metav1.Duration `json:"timeout,omitempty"`
71+
72+
// volumeSnapshotSource defines the PVC to snapshot.
73+
// +optional
74+
VolumeSnapshotSource VolumeSnapshotSource `json:"volumeSnapshotSource,omitempty"`
75+
}
76+
77+
// VolumeSnapshotSource points to the PVC that should be snapshotted.
78+
type VolumeSnapshotSource struct {
79+
// persistentVolumeClaimName is the name of the PVC to snapshot.
80+
// +optional
81+
PersistentVolumeClaimName string `json:"persistentVolumeClaimName,omitempty"`
82+
83+
// persistentVolumeClaimNamespace is the namespace of the PVC.
84+
// +optional
85+
PersistentVolumeClaimNamespace string `json:"persistentVolumeClaimNamespace,omitempty"`
86+
}
87+
88+
// DataProtectionTestStatus represents the observed results of the tests.
89+
type DataProtectionTestStatus struct {
90+
// lastTested is the timestamp when the test was last run.
91+
// +optional
92+
LastTested metav1.Time `json:"lastTested,omitempty"`
93+
94+
// s3Vendor indicates the detected s3 vendor name from the storage endpoint if applicable (e.g., AWS, MinIO).
95+
// +optional
96+
S3Vendor string `json:"s3Vendor,omitempty"`
97+
98+
// bucketMetadata reports the encryption and versioning status of the target bucket.
99+
// +optional
100+
BucketMetadata *BucketMetadata `json:"bucketMetadata,omitempty"`
101+
102+
// uploadTest contains results of the object storage upload test.
103+
// +optional
104+
UploadTest UploadTestStatus `json:"uploadTest,omitempty"`
105+
106+
// snapshotTests contains results for each snapshot tested PVC.
107+
// +optional
108+
SnapshotTests []SnapshotTestStatus `json:"snapshotTests,omitempty"`
109+
110+
// snapshot test pass/fail summary
111+
// +optional
112+
SnapshotSummary string `json:"snapshotSummary,omitempty"`
113+
114+
// phase indicates phase of the DataProtectionTest - Complete, Failed
115+
// +optional
116+
Phase string `json:"phase,omitempty"`
117+
118+
// errorMessage contains details of any DPT failure
119+
// +optional
120+
ErrorMessage string `json:"errorMessage,omitempty"`
121+
}
122+
123+
// UploadTestStatus holds the results of the upload test.
124+
type UploadTestStatus struct {
125+
// speedMbps is the calculated upload speed.
126+
// +optional
127+
SpeedMbps int64 `json:"speedMbps,omitempty"`
128+
129+
// duration is the time taken to upload the test file.
130+
// +optional
131+
Duration string `json:"duration,omitempty"`
132+
133+
// success indicates if the upload succeeded.
134+
// +optional
135+
Success bool `json:"success,omitempty"`
136+
137+
// errorMessage contains details of any upload failure.
138+
// +optional
139+
ErrorMessage string `json:"errorMessage,omitempty"`
140+
}
141+
142+
// SnapshotTestStatus holds the result for an individual PVC snapshot test.
143+
type SnapshotTestStatus struct {
144+
// persistentVolumeClaimName of the tested PVC.
145+
// +optional
146+
PersistentVolumeClaimName string `json:"persistentVolumeClaimName,omitempty"`
147+
148+
// persistentVolumeClaimNamespace of the tested PVC.
149+
// +optional
150+
PersistentVolumeClaimNamespace string `json:"persistentVolumeClaimNamespace,omitempty"`
151+
152+
// status indicates snapshot readiness ("Ready", "Failed").
153+
// +optional
154+
Status string `json:"status,omitempty"`
155+
156+
// readyDuration is the time it took for the snapshot to become ReadyToUse.
157+
// +optional
158+
ReadyDuration string `json:"readyDuration,omitempty"`
159+
160+
// errorMessage contains details of any snapshot failure.
161+
// +optional
162+
ErrorMessage string `json:"errorMessage,omitempty"`
163+
}
164+
165+
// BucketMetadata contains encryption and versioning info for the target bucket.
166+
type BucketMetadata struct {
167+
// encryptionAlgorithm reports the encryption method (AES256, aws:kms, or "None").
168+
// +optional
169+
EncryptionAlgorithm string `json:"encryptionAlgorithm,omitempty"`
170+
171+
// versioningStatus indicates whether bucket versioning is Enabled, Suspended, or None.
172+
// +optional
173+
VersioningStatus string `json:"versioningStatus,omitempty"`
174+
175+
// errorMessage contains details of any failure to fetch bucket metadata.
176+
// +optional
177+
ErrorMessage string `json:"errorMessage,omitempty"`
178+
}
179+
180+
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=".status.phase",description="Current phase of the DPT"
181+
// +kubebuilder:printcolumn:name="LastTested",type=date,JSONPath=".status.lastTested",description="Last time the test was executed"
182+
// +kubebuilder:printcolumn:name="UploadSpeed(Mbps)",type=integer,JSONPath=".status.uploadTest.speedMbps",description="Upload speed to object storage"
183+
// +kubebuilder:printcolumn:name="Encryption",type=string,JSONPath=".status.bucketMetadata.encryptionAlgorithm",description="Bucket encryption algorithm"
184+
// +kubebuilder:printcolumn:name="Versioning",type=string,JSONPath=".status.bucketMetadata.versioningStatus",description="Bucket versioning state"
185+
// +kubebuilder:printcolumn:name="Snapshots",type=string,JSONPath=`.status.snapshotSummary`,description="Snapshot test pass/fail summary"
186+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp",description="Time since DPT was created"
187+
//+kubebuilder:object:root=true
188+
//+kubebuilder:subresource:status
189+
//+kubebuilder:resource:path=dataprotectiontests,shortName=dpt
190+
191+
// DataProtectionTest is the Schema for the dataprotectiontests API
192+
type DataProtectionTest struct {
193+
metav1.TypeMeta `json:",inline"`
194+
metav1.ObjectMeta `json:"metadata,omitempty"`
195+
196+
Spec DataProtectionTestSpec `json:"spec,omitempty"`
197+
Status DataProtectionTestStatus `json:"status,omitempty"`
198+
}
199+
200+
//+kubebuilder:object:root=true
201+
202+
// DataProtectionTestList contains a list of DataProtectionTest
203+
type DataProtectionTestList struct {
204+
metav1.TypeMeta `json:",inline"`
205+
metav1.ListMeta `json:"metadata,omitempty"`
206+
Items []DataProtectionTest `json:"items"`
207+
}
208+
209+
func init() {
210+
SchemeBuilder.Register(&DataProtectionTest{}, &DataProtectionTestList{})
211+
}

0 commit comments

Comments
 (0)