Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Non Admin Restore controller #114

Merged
merged 14 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ resources:
kind: NonAdminBackup
path: github.com/migtools/oadp-non-admin/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openshift.io
group: oadp
kind: NonAdminRestore
path: github.com/migtools/oadp-non-admin/api/v1alpha1
version: v1alpha1
version: "3"
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ To use NAC functionality:
```

Check the application was successful deployed by accessing its route.

Create and update items in application UI, to later check if application was successfully restored.
- create NonAdminBackup

For example, use one of the sample NonAdminBackup available in `hack/samples/backups/` folder, by running
Expand All @@ -47,7 +49,28 @@ To use NAC functionality:
| oc create -f -
```
<!-- TODO how to track status -->
- TODO NonAdminRestore
- delete sample application

For example, delete one of the sample applications available in `hack/samples/apps/` folder, by running
```sh
oc process -f ./hack/samples/apps/<name> \
-p NAMESPACE=<non-admin-user-namespace> \
| oc delete -f -
```

Check that application was successful deleted by accessing its route.
- create NonAdminRestore

For example, use one of the sample NonAdminRestore available in `hack/samples/restores/` folder, by running
```sh
oc process -f ./hack/samples/restores/<type> \
-p NAMESPACE=<non-admin-user-namespace> \
-p NAME=<NonAdminBackup-name> \
| oc create -f -
```
<!-- TODO how to track status -->

After NonAdminRestore completes, check if the application was successful restored by accessing its route and seeing its items in application UI.

## Contributing

Expand Down
26 changes: 14 additions & 12 deletions api/v1alpha1/nonadminbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NonAdminBackupPhase is a simple one high-level summary of the lifecycle of an NonAdminBackup.
// NonAdminPhase is a simple one high-level summary of the lifecycle of an NonAdminBackup.
// +kubebuilder:validation:Enum=New;BackingOff;Created;Deleting
type NonAdminBackupPhase string
type NonAdminPhase string

const (
// NonAdminBackupPhaseNew - NonAdminBackup resource was accepted by the OpenShift cluster, but it has not yet been processed by the NonAdminController
NonAdminBackupPhaseNew NonAdminBackupPhase = "New"
// NonAdminBackupPhaseBackingOff - Velero Backup object was not created due to NonAdminBackup error (configuration or similar)
NonAdminBackupPhaseBackingOff NonAdminBackupPhase = "BackingOff"
// NonAdminBackupPhaseCreated - Velero Backup was created. The Phase will not have additional informations about the Backup.
NonAdminBackupPhaseCreated NonAdminBackupPhase = "Created"
// NonAdminBackupPhaseDeleting - Velero Backup is pending deletion. The Phase will not have additional informations about the Backup.
NonAdminBackupPhaseDeleting NonAdminBackupPhase = "Deleting"
// NonAdminPhaseNew - NonAdmin object was accepted by the OpenShift cluster, but it has not yet been processed by the NonAdminController
NonAdminPhaseNew NonAdminPhase = "New"
// NonAdminPhaseBackingOff - Velero object was not created due to NonAdmin object error (configuration or similar)
NonAdminPhaseBackingOff NonAdminPhase = "BackingOff"
// NonAdminPhaseCreated - Velero object was created. The Phase will not have additional information about it.
NonAdminPhaseCreated NonAdminPhase = "Created"
// NonAdminPhaseDeleting - Velero object is pending deletion. The Phase will not have additional information about it.
NonAdminPhaseDeleting NonAdminPhase = "Deleting"
)

// NonAdminBackupSpec defines the desired state of NonAdminBackup
Expand Down Expand Up @@ -106,8 +106,10 @@ type NonAdminBackupStatus struct {
// +optional
QueueInfo *QueueInfo `json:"queueInfo,omitempty"`

Phase NonAdminBackupPhase `json:"phase,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
// phase is a simple one high-level summary of the lifecycle of an NonAdminBackup.
Phase NonAdminPhase `json:"phase,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// QueueInfo holds the queue position for a specific VeleroBackup.
Expand Down
31 changes: 0 additions & 31 deletions api/v1alpha1/nonadmincontroller_types.go

This file was deleted.

84 changes: 84 additions & 0 deletions api/v1alpha1/nonadminrestore_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
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 (
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NonAdminRestoreSpec defines the desired state of NonAdminRestore
type NonAdminRestoreSpec struct {
// restoreSpec defines the specification for a Velero restore.
RestoreSpec *velerov1.RestoreSpec `json:"restoreSpec"`
shubham-pampattiwar marked this conversation as resolved.
Show resolved Hide resolved
}

// VeleroRestore contains information of the related Velero restore object.
type VeleroRestore struct {
// status captures the current status of the Velero restore.
// +optional
Status *velerov1.RestoreStatus `json:"status,omitempty"`

// references the Velero Restore object by it's name.
// +optional
Name string `json:"name,omitempty"`

// nacuuid references the Velero Restore object by it's label containing same NACUUID.
// +optional
NACUUID string `json:"nacuuid,omitempty"`

// namespace references the Namespace in which Velero Restore exists.
// +optional
Namespace string `json:"namespace,omitempty"`
}

// NonAdminRestoreStatus defines the observed state of NonAdminRestore
type NonAdminRestoreStatus struct {
// +optional
VeleroRestore *VeleroRestore `json:"veleroRestore,omitempty"`

// phase is a simple one high-level summary of the lifecycle of an NonAdminRestore.
Phase NonAdminPhase `json:"phase,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=nonadminrestores,shortName=nar

// NonAdminRestore is the Schema for the nonadminrestores API
type NonAdminRestore struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NonAdminRestoreSpec `json:"spec,omitempty"`
Status NonAdminRestoreStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// NonAdminRestoreList contains a list of NonAdminRestore
type NonAdminRestoreList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NonAdminRestore `json:"items"`
}

func init() {
SchemeBuilder.Register(&NonAdminRestore{}, &NonAdminRestoreList{})
}
126 changes: 126 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminBackup")
os.Exit(1)
}
if err = (&controller.NonAdminRestoreReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
OADPNamespace: oadpNamespace,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminRestore")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/oadp.openshift.io_nonadminbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ spec:
type: object
type: array
phase:
description: NonAdminBackupPhase is a simple one high-level summary
of the lifecycle of an NonAdminBackup.
description: phase is a simple one high-level summary of the lifecycle
of an NonAdminBackup.
enum:
- New
- BackingOff
Expand Down
Loading
Loading