Skip to content

Commit 4600ba2

Browse files
committed
pod/non-admin-controller-74775c6977-2mncl running
1 parent 45a16b6 commit 4600ba2

25 files changed

+6490
-133
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY main.go main.go
1717
COPY api/ api/
1818
COPY pkg/ pkg/
1919
COPY controllers/ controllers/
20+
COPY internal/ internal/
2021

2122
# Build
2223
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod=mod -a -o /go/src/manager main.go

api/v1alpha1/nonadmin_types.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
// NonAdminPhase is a simple one high-level summary of the lifecycle of a NonAdminBackup, NonAdminRestore, NonAdminBackupStorageLocation, or NonAdminDownloadRequest
20+
// +kubebuilder:validation:Enum=New;BackingOff;Created;Deleting
21+
type NonAdminPhase string
22+
23+
const (
24+
// NonAdminPhaseNew - NonAdmin object was accepted by the OpenShift cluster, but it has not yet been processed by the NonAdminController
25+
NonAdminPhaseNew NonAdminPhase = "New"
26+
// NonAdminPhaseBackingOff - Velero object was not created due to NonAdmin object error (configuration or similar)
27+
NonAdminPhaseBackingOff NonAdminPhase = "BackingOff"
28+
// NonAdminPhaseCreated - Velero object was created. The Phase will not have additional information about it.
29+
NonAdminPhaseCreated NonAdminPhase = "Created"
30+
// NonAdminPhaseDeleting - Velero object is pending deletion. The Phase will not have additional information about it.
31+
NonAdminPhaseDeleting NonAdminPhase = "Deleting"
32+
)
33+
34+
// NonAdminCondition are used for more detailed information supporing NonAdminBackupPhase state.
35+
// +kubebuilder:validation:Enum=Accepted;Queued;Deleting
36+
type NonAdminCondition string
37+
38+
// Predefined conditions for NonAdminController objects.
39+
// One NonAdminController object may have multiple conditions.
40+
// It is more granular knowledge of the NonAdminController object and represents the
41+
// array of the conditions through which the NonAdminController has or has not passed
42+
const (
43+
NonAdminConditionAccepted NonAdminCondition = "Accepted"
44+
NonAdminConditionQueued NonAdminCondition = "Queued"
45+
NonAdminConditionDeleting NonAdminCondition = "Deleting"
46+
)
47+
48+
// QueueInfo holds the queue position for a specific operation.
49+
type QueueInfo struct {
50+
// estimatedQueuePosition is the number of operations ahead in the queue (0 if not queued)
51+
EstimatedQueuePosition int `json:"estimatedQueuePosition"`
52+
}
53+
54+
// Constants representing resource names for non-admin objects
55+
// These are used to identify custom resources managed for non-admin users.
56+
const (
57+
// NonAdminBackups represents the resource name for non-admin backups.
58+
NonAdminBackups = "nonadminbackups"
59+
60+
// NonAdminRestores represents the resource name for non-admin restores.
61+
NonAdminRestores = "nonadminrestores"
62+
63+
// NonAdminBackupStorageLocations represents the resource name for non-admin backup storage locations.
64+
NonAdminBackupStorageLocations = "nonadminbackupstoragelocations"
65+
)
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
24+
// NonAdminBSLCondition contains additional conditions to the
25+
// generic ones defined as NonAdminCondition
26+
type NonAdminBSLCondition string
27+
28+
// Predefined NonAdminBSLConditions
29+
const (
30+
NonAdminBSLConditionSecretSynced NonAdminBSLCondition = "SecretSynced"
31+
NonAdminBSLConditionBSLSynced NonAdminBSLCondition = "BackupStorageLocationSynced"
32+
NonAdminBSLConditionApproved NonAdminBSLCondition = "ClusterAdminApproved"
33+
NonAdminBSLConditionSpecUpdateApproved NonAdminBSLCondition = "SpecUpdateApproved"
34+
)
35+
36+
// NonAdminBackupStorageLocationSpec defines the desired state of NonAdminBackupStorageLocation
37+
type NonAdminBackupStorageLocationSpec struct {
38+
BackupStorageLocationSpec *velerov1.BackupStorageLocationSpec `json:"backupStorageLocationSpec"`
39+
}
40+
41+
// VeleroBackupStorageLocation contains information of the related Velero backup object.
42+
type VeleroBackupStorageLocation struct {
43+
// status captures the current status of the Velero backup storage location.
44+
// +optional
45+
Status *velerov1.BackupStorageLocationStatus `json:"status,omitempty"`
46+
47+
// nacuuid references the Velero BackupStorageLocation object by it's label containing same NACUUID.
48+
// +optional
49+
NACUUID string `json:"nacuuid,omitempty"`
50+
51+
// references the Velero BackupStorageLocation object by it's name.
52+
// +optional
53+
Name string `json:"name,omitempty"`
54+
55+
// namespace references the Namespace in which Velero backup storage location exists.
56+
// +optional
57+
Namespace string `json:"namespace,omitempty"`
58+
}
59+
60+
// NonAdminBackupStorageLocationStatus defines the observed state of NonAdminBackupStorageLocation
61+
type NonAdminBackupStorageLocationStatus struct {
62+
// +optional
63+
VeleroBackupStorageLocation *VeleroBackupStorageLocation `json:"veleroBackupStorageLocation,omitempty"`
64+
65+
// phase is a simple one high-level summary of the lifecycle of an NonAdminBackupStorageLocation.
66+
Phase NonAdminPhase `json:"phase,omitempty"`
67+
68+
Conditions []metav1.Condition `json:"conditions,omitempty"`
69+
}
70+
71+
// +kubebuilder:object:root=true
72+
// +kubebuilder:subresource:status
73+
// +kubebuilder:resource:path=nonadminbackupstoragelocations,shortName=nabsl
74+
// +kubebuilder:printcolumn:name="Request-Approved",type="string",JSONPath=".status.conditions[?(@.type=='ClusterAdminApproved')].status"
75+
// +kubebuilder:printcolumn:name="Request-Phase",type="string",JSONPath=".status.phase"
76+
// +kubebuilder:printcolumn:name="Velero-Phase",type="string",JSONPath=".status.veleroBackupStorageLocation.status.phase"
77+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
78+
79+
// NonAdminBackupStorageLocation is the Schema for the nonadminbackupstoragelocations API
80+
type NonAdminBackupStorageLocation struct {
81+
metav1.TypeMeta `json:",inline"`
82+
metav1.ObjectMeta `json:"metadata,omitempty"`
83+
84+
Spec NonAdminBackupStorageLocationSpec `json:"spec,omitempty"`
85+
Status NonAdminBackupStorageLocationStatus `json:"status,omitempty"`
86+
}
87+
88+
// +kubebuilder:object:root=true
89+
90+
// NonAdminBackupStorageLocationList contains a list of NonAdminBackupStorageLocation
91+
type NonAdminBackupStorageLocationList struct {
92+
metav1.TypeMeta `json:",inline"`
93+
metav1.ListMeta `json:"metadata,omitempty"`
94+
Items []NonAdminBackupStorageLocation `json:"items"`
95+
}
96+
97+
func init() {
98+
SchemeBuilder.Register(&NonAdminBackupStorageLocation{}, &NonAdminBackupStorageLocationList{})
99+
}

0 commit comments

Comments
 (0)