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 #42

Closed
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ help: ## Display this help.
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=non-admin-controller-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
sed -i 's/Velero backup/NonAdminBackup/' ./config/crd/bases/nac.oadp.openshift.io_nonadminrestores.yaml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for better user experience


.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
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: oadp.openshift.io
group: nac
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 -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO


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

## Contributing

Expand Down
20 changes: 10 additions & 10 deletions api/v1alpha1/nonadminbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ 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 a non admin object.
// +kubebuilder:validation:Enum=New;BackingOff;Created
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"
// NonAdminPhaseNew - non admin resource 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 error in non admin object (configuration or similar)
NonAdminPhaseBackingOff NonAdminPhase = "BackingOff"
// NonAdminPhaseCreated - Velero object was created. The Phase will not have additional information about the Velero object.
NonAdminPhaseCreated NonAdminPhase = "Created"
)

// NonAdminBackupSpec defines the desired state of NonAdminBackup
Expand Down Expand Up @@ -60,8 +60,8 @@ type NonAdminBackupStatus struct {
// +optional
VeleroBackupStatus *velerov1api.BackupStatus `json:"veleroBackupStatus,omitempty"`

Phase NonAdminBackupPhase `json:"phase,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
Phase NonAdminPhase `json:"phase,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
75 changes: 75 additions & 0 deletions api/v1alpha1/nonadminrestore_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
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 (
velerov1api "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 {
// Specification for a Velero restore.
RestoreSpec *velerov1api.RestoreSpec `json:"restoreSpec"`
// TODO need to investigate restoreSpec.namespaceMapping, depends on how NAC tracks the namespace access per user

// TODO NonAdminRestore log level, by default TODO.
// +optional
// +kubebuilder:validation:Enum=trace;debug;info;warning;error;fatal;panic
LogLevel string `json:"logLevel,omitempty"`
// TODO ALSO ADD TEST FOR DIFFERENT LOG LEVELS
}

// NonAdminRestoreStatus defines the observed state of NonAdminRestore
type NonAdminRestoreStatus struct {
// Related Velero Restore name.
// +optional
VeleroRestoreName string `json:"veleroRestoreName,omitempty"`

mateusoliveira43 marked this conversation as resolved.
Show resolved Hide resolved
// Related Velero Restore status.
// +optional
VeleroRestoreStatus *velerov1api.RestoreStatus `json:"veleroRestoreStatus,omitempty"`

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

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
mateusoliveira43 marked this conversation as resolved.
Show resolved Hide resolved
// +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{})
}
106 changes: 106 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.

10 changes: 9 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func main() {
TLSOpts: tlsOpts,
})

if len(constant.OadpNamespace) == 0 {
// TODO create get function in common :question:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

if len(os.Getenv(constant.NamespaceEnvVar)) == 0 {
setupLog.Error(fmt.Errorf("%v environment variable is empty", constant.NamespaceEnvVar), "environment variable must be set")
os.Exit(1)
}
Expand Down Expand Up @@ -138,6 +139,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminBackup")
os.Exit(1)
}
if err = (&controller.NonAdminRestoreReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).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/nac.oadp.openshift.io_nonadminbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ spec:
type: object
type: array
phase:
description: NonAdminBackupPhase is a simple one high-level summary
of the lifecycle of an NonAdminBackup.
description: NonAdminPhase is a simple one high-level summary of the
mateusoliveira43 marked this conversation as resolved.
Show resolved Hide resolved
lifecycle of a non admin object.
enum:
- New
- BackingOff
Expand Down
Loading
Loading