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

NonAdminDownloadRequests implementation #233

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
afd75df
kubebuilder create api --group oadp --version v1alpha1 --kind NonAdmi…
kaovilai Feb 25, 2025
410d964
api init
kaovilai Feb 25, 2025
e55db8b
Scaffolds objectReconciler
kaovilai Feb 25, 2025
9c416e4
crd updates
kaovilai Feb 25, 2025
30cd71f
impl + lint
kaovilai Feb 26, 2025
66b5da2
doc adds new api
kaovilai Feb 26, 2025
c915153
predicates
kaovilai Feb 27, 2025
52f5013
update
kaovilai Feb 27, 2025
b33255b
sseago comments
kaovilai Feb 27, 2025
67ded68
udpate
kaovilai Feb 27, 2025
7a6a269
revert patch changes
kaovilai Feb 27, 2025
6243c69
only watch VDR in OADP NS
kaovilai Feb 27, 2025
bb74769
helper funcs
kaovilai Feb 27, 2025
59d7183
Reconcile update
kaovilai Feb 27, 2025
a692b85
VDR predicate watch ns condition
kaovilai Feb 27, 2025
71fe1b9
update
kaovilai Feb 28, 2025
0047514
gitignore
kaovilai Feb 28, 2025
b30401c
lints and feedbacks
kaovilai Feb 28, 2025
bc2ae35
typed condition
kaovilai Feb 28, 2025
fe848df
https://github.com/migtools/oadp-non-admin/pull/233#discussion_r19754…
kaovilai Feb 28, 2025
5da7782
comment
kaovilai Feb 28, 2025
084da9b
update sample
kaovilai Feb 28, 2025
bc1ed1c
comment
kaovilai Feb 28, 2025
c73675a
test
kaovilai Feb 28, 2025
0376539
downloadrequests rbac
kaovilai Feb 28, 2025
c11e394
Add condition true when succeed
kaovilai Feb 28, 2025
59c7e99
lint
kaovilai Feb 28, 2025
e46a240
remove scaffolding comments
kaovilai Feb 28, 2025
4ec23ce
Leave spec validation to velero markers
kaovilai Mar 3, 2025
654b146
log fail to delete
kaovilai Mar 3, 2025
30763a7
simplify logs
kaovilai Mar 3, 2025
2aad50a
removes VDR deletion
kaovilai Mar 3, 2025
bf77a68
Use phase backingoff for NonAdminBackupStorageLocationNotUsed condition
kaovilai Mar 3, 2025
947a198
envtest
kaovilai Mar 3, 2025
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ go.work
*.swp
*.swo
*~

# debug
__debug_bin*
debug.test*
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ resources:
kind: NonAdminBackupStorageLocation
path: github.com/migtools/oadp-non-admin/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openshift.io
group: oadp
kind: NonAdminDownloadRequest
path: github.com/migtools/oadp-non-admin/api/v1alpha1
version: v1alpha1
version: "3"
2 changes: 1 addition & 1 deletion api/v1alpha1/nonadmin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

package v1alpha1

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

Expand Down
17 changes: 17 additions & 0 deletions api/v1alpha1/nonadminbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1alpha1
import (
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/migtools/oadp-non-admin/internal/common/constant"
)

// NonAdminBackupSpec defines the desired state of NonAdminBackup
Expand Down Expand Up @@ -188,3 +190,18 @@ type NonAdminBackupList struct {
func init() {
SchemeBuilder.Register(&NonAdminBackup{}, &NonAdminBackupList{})
}

// Helper Functions to avoid digging into NAB controller to understand how to get desired values

// VeleroBackupName returns the name of the VeleroBackup object.
func (nab *NonAdminBackup) VeleroBackupName() string {
if nab.Status.VeleroBackup == nil {
return constant.EmptyString
}
return nab.Status.VeleroBackup.Name
}

// UsesNaBSL returns true if backup is using NonAdminBackupStorageLocation
func (nab *NonAdminBackup) UsesNaBSL() bool {
return nab.Spec.BackupSpec != nil && nab.Spec.BackupSpec.StorageLocation != constant.EmptyString
}
112 changes: 112 additions & 0 deletions api/v1alpha1/nonadmindownloadrequest_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
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 (
"fmt"

velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NonAdminDownloadRequestSpec defines the desired state of NonAdminDownloadRequest.
// Mirrors velero DownloadRequestSpec to allow non admins to download information for a non admin backup/restore
type NonAdminDownloadRequestSpec struct {
// Target is what to download (e.g. logs for a backup).
Target velerov1.DownloadTarget `json:"target"`
}

// VeleroDownloadRequest represents VeleroDownloadRequest
type VeleroDownloadRequest struct {
// VeleroDownloadRequestStatus represents VeleroDownloadRequestStatus
// +optional
Status *velerov1.DownloadRequestStatus `json:"status,omitempty"`
}

// NonAdminDownloadRequestStatus defines the observed state of NonAdminDownloadRequest.
type NonAdminDownloadRequestStatus struct {
// +optional
VeleroDownloadRequest VeleroDownloadRequest `json:"velero,omitempty"`
// phase is a simple one high-level summary of the lifecycle of an NonAdminDownloadRequest
Phase NonAdminPhase `json:"phase,omitempty"`

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

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=nonadmindownloadrequests,shortName=nadr
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"

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

Spec NonAdminDownloadRequestSpec `json:"spec,omitempty"`
Status NonAdminDownloadRequestStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&NonAdminDownloadRequest{}, &NonAdminDownloadRequestList{})
}

// NonAdminDownloadRequestConditionType prevents untyped strings for NADR conditions functions
type NonAdminDownloadRequestConditionType string

const (
// ConditionNonAdminBackupStorageLocationNotUsed block download requests processing if NaBSL is not used
ConditionNonAdminBackupStorageLocationNotUsed NonAdminDownloadRequestConditionType = "NonAdminBackupStorageLocationNotUsed"
// ConditionNonAdminBackupNotAvailable indicates backup is not available, and will backoff download request
ConditionNonAdminBackupNotAvailable NonAdminDownloadRequestConditionType = "NonAdminBackupNotAvailable"
// ConditionNonAdminRestoreNotAvailable indicates restore is not available, and will backoff download request
ConditionNonAdminRestoreNotAvailable NonAdminDownloadRequestConditionType = "NonAdminRestoreNotAvailable"
// ConditionNonAdminProcessed indicates that the NADR is in a terminal state
ConditionNonAdminProcessed NonAdminDownloadRequestConditionType = "Processed"
)

// ReadyForProcessing returns if this NonAdminDownloadRequests is in a state ready for processing
//
// Terminal conditions include
// - NonAdminBackupStorageLocationNotUsed: we currently require NaBSL usage on the NAB/NAR to process this download request
// returns true if ready for processing, false otherwise
func (nadr *NonAdminDownloadRequest) ReadyForProcessing() bool {
// if nadr has ConditionNonAdminBackupStorageLocationUsed return false
if nadr.Status.Conditions != nil {
for _, condition := range nadr.Status.Conditions {
if condition.Type == string(ConditionNonAdminBackupStorageLocationNotUsed) &&
condition.Status == metav1.ConditionTrue {
return false
}
}
}
return true // required fields are set via velero validation markers
}

// VeleroDownloadRequestName defines velero download request name for this NonAdminDownloadRequest
func (nadr *NonAdminDownloadRequest) VeleroDownloadRequestName() string {
return fmt.Sprintf("nadr-%s", string(nadr.GetUID()))
}
17 changes: 17 additions & 0 deletions api/v1alpha1/nonadminrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1alpha1
import (
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/migtools/oadp-non-admin/internal/common/constant"
)

// NonAdminRestoreSpec defines the desired state of NonAdminRestore
Expand Down Expand Up @@ -157,3 +159,18 @@ type NonAdminRestoreList struct {
func init() {
SchemeBuilder.Register(&NonAdminRestore{}, &NonAdminRestoreList{})
}

// Helper Functions to avoid digging into NAR controller to understand how to get desired values

// VeleroRestoreName returns the name of the VeleroRestore object.
func (nar *NonAdminRestore) VeleroRestoreName() string {
if nar.Status.VeleroRestore == nil {
return constant.EmptyString
}
return nar.Status.VeleroRestore.Name
}

// NonAdminBackupName returns NonAdminBackup name of this NAR
func (nar *NonAdminRestore) NonAdminBackupName() string {
return nar.Spec.RestoreSpec.BackupName
}
118 changes: 118 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 @@ -208,6 +208,14 @@ func main() {
setupLog.Error(err, "unable to setup NonAdminBackupStorageLocation controller with manager")
os.Exit(1)
}
if err = (&controller.NonAdminDownloadRequestReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
OADPNamespace: oadpNamespace,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminDownloadRequest")
os.Exit(1)
}
// +kubebuilder:scaffold:builder
if dpaConfiguration.BackupSyncPeriod.Duration > 0 {
if err = (&controller.NonAdminBackupSynchronizerReconciler{
Expand Down
Loading
Loading