Skip to content

Commit

Permalink
fixup! feat: Add Non Admin Restore controller
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 committed Apr 29, 2024
1 parent 35f7396 commit 0658b04
Show file tree
Hide file tree
Showing 14 changed files with 759 additions and 93 deletions.
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

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
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
21 changes: 14 additions & 7 deletions api/v1alpha1/nonadminrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@ 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"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// NonAdminRestoreSpec defines the desired state of NonAdminRestore
type NonAdminRestoreSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Specification for a Velero restore.
// +kubebuilder:validation:Required
RestoreSpec *velerov1api.RestoreSpec `json:"restoreSpec,omitempty"`
// TODO add test that NAR can not be created without restoreSpec or restoreSpec.backupName
// TODO need to investigate restoreSpec.namespaceMapping, depends on how NAC tracks the namespace access per user

// Foo is an example field of NonAdminRestore. Edit nonadminrestore_types.go to remove/update
Foo string `json:"foo,omitempty"`
// 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 {
// TODO https://github.com/migtools/oadp-non-admin/pull/23
// TODO https://github.com/migtools/oadp-non-admin/pull/13

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

Expand Down
7 changes: 6 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 2 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:
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
Loading

0 comments on commit 0658b04

Please sign in to comment.