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 May 15, 2024
1 parent 47605cd commit ba8553e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 67 deletions.
4 changes: 1 addition & 3 deletions api/v1alpha1/nonadminrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
// NonAdminRestoreSpec defines the desired state of NonAdminRestore
type NonAdminRestoreSpec struct {
// 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
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.
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/nac.oadp.openshift.io_nonadminrestores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ spec:
required:
- backupName
type: object
required:
- restoreSpec
type: object
status:
description: NonAdminRestoreStatus defines the observed state of NonAdminRestore
Expand Down
64 changes: 0 additions & 64 deletions internal/controller/nonadminrestore_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ import (
"github.com/migtools/oadp-non-admin/internal/common/constant"
)

type clusterScenario struct {
namespace string
nonAdminRestore string
}

type nonAdminRestoreReconcileScenario struct {
restoreSpec *v1.RestoreSpec
namespace string
Expand All @@ -56,65 +51,6 @@ func createTestNonAdminRestore(name string, namespace string, restoreSpec v1.Res
}
}

// TODO this does not work with envtest :question:
var _ = ginkgo.Describe("Test NonAdminRestore in cluster validation", func() {
var (
ctx = context.Background()
currentTestScenario clusterScenario
updateTestScenario = func(scenario clusterScenario) {
currentTestScenario = scenario
}
)

ginkgo.AfterEach(func() {
nonAdminRestore := &nacv1alpha1.NonAdminRestore{}
if k8sClient.Get(
ctx,
types.NamespacedName{
Name: currentTestScenario.nonAdminRestore,
Namespace: currentTestScenario.namespace,
},
nonAdminRestore,
) == nil {
gomega.Expect(k8sClient.Delete(ctx, nonAdminRestore)).To(gomega.Succeed())
}

namespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: currentTestScenario.namespace,
},
}
gomega.Expect(k8sClient.Delete(ctx, namespace)).To(gomega.Succeed())
})

ginkgo.DescribeTable("Validation is false",
func(scenario clusterScenario) {
updateTestScenario(scenario)

namespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: scenario.namespace,
},
}
gomega.Expect(k8sClient.Create(ctx, namespace)).To(gomega.Succeed())

nonAdminRestore := &nacv1alpha1.NonAdminRestore{
ObjectMeta: metav1.ObjectMeta{
Name: scenario.nonAdminRestore,
Namespace: scenario.namespace,
},
// Spec: nacv1alpha1.NonAdminRestoreSpec{},
}
gomega.Expect(k8sClient.Create(ctx, nonAdminRestore)).To(gomega.Not(gomega.Succeed()))
},
ginkgo.Entry("Should NOT create NonAdminRestore without spec.restoreSpec", clusterScenario{
namespace: "test-nonadminrestore-cluster-1",
nonAdminRestore: "test-nonadminrestore-cluster-1-cr",
}),
// TODO Should NOT create NonAdminRestore without spec.restoreSpec.backupName
)
})

var _ = ginkgo.Describe("Test NonAdminRestore Reconcile function", func() {
var (
ctx = context.Background()
Expand Down

0 comments on commit ba8553e

Please sign in to comment.