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

Allow Non-Admin user to create Backup Storage Locations - fixes #36 #115

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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: NonAdminBackupStorageLocation
path: github.com/migtools/oadp-non-admin/api/v1alpha1
version: v1alpha1
version: "3"
107 changes: 107 additions & 0 deletions api/v1alpha1/nonadminbackupstoragelocation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
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"
)

// 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.

// NonAdminBackupStorageLocationPhase is a simple one high-level summary of the lifecycle of an NonAdminBackupStorageLocation.
// +kubebuilder:validation:Enum=New;Available;Unavailable;Created;Deleting
type NonAdminBackupStorageLocationPhase string

// NonAdminBackupStorageLocationPhase constants similar to velerov1.BackupStorageLocationPhase
const (
NaBSLPhaseNew NonAdminBackupStorageLocationPhase = "New"
NaBSLPhaseAvailable NonAdminBackupStorageLocationPhase = "Available"
NaBSLPhaseUnavailable NonAdminBackupStorageLocationPhase = "Unavailable"
NaBSLPhaseCreated NonAdminBackupStorageLocationPhase = "Created"
NaBSLPhaseDeleting NonAdminBackupStorageLocationPhase = "Deleting"
)

// NonAdminBSLCondition contains addition conditions to the
// generic ones defined as NonAdminCondition
// +kubebuilder:validation:Enum=SecretSynced;BSLSynced
type NonAdminBSLCondition string

// Predefined NonAdminBSLConditions
const (
NonAdminBSLConditionSecretSynced NonAdminBSLCondition = "SecretSynced"
NonAdminBSLConditionBSLSynced NonAdminBSLCondition = "BackupStorageLocationSynced"
)

// NonAdminBackupStorageLocationSpec defines the desired state of NonAdminBackupStorageLocation
type NonAdminBackupStorageLocationSpec struct {
// Embeds the Velero BackupStorageLocationSpec to inherit all fields
velerov1.BackupStorageLocationSpec `json:",inline"`
}

// VeleroBackupStorageLocation contains information of the related Velero backup object.
type VeleroBackupStorageLocation struct {
// status captures the current status of the Velero backup storage location.
// +optional
Status *velerov1.BackupStorageLocationStatus `json:"status,omitempty"`

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

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

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

// NonAdminBackupStorageLocationStatus defines the observed state of NonAdminBackupStorageLocation
type NonAdminBackupStorageLocationStatus struct {
// Important: Run "make" to regenerate code after modifying this file
// +optional
VeleroBackupStorageLocation *VeleroBackupStorageLocation `json:"veleroBackupStorageLocation,omitempty"`

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

// NonAdminBackupStorageLocation is the Schema for the nonadminbackupstoragelocations API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type NonAdminBackupStorageLocation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NonAdminBackupStorageLocationSpec `json:"spec,omitempty"`
Status NonAdminBackupStorageLocationStatus `json:"status,omitempty"`
}

// NonAdminBackupStorageLocationList contains a list of NonAdminBackupStorageLocation
// +kubebuilder:object:root=true
type NonAdminBackupStorageLocationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NonAdminBackupStorageLocation `json:"items"`
}

func init() {
SchemeBuilder.Register(&NonAdminBackupStorageLocation{}, &NonAdminBackupStorageLocationList{})
}
8 changes: 4 additions & 4 deletions api/v1alpha1/nonadmincontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ package v1alpha1
// +kubebuilder:validation:Enum=Accepted;Queued;Deleting
type NonAdminCondition string

// Predefined conditions for NonAdminBackup.
// One NonAdminBackup object may have multiple conditions.
// It is more granular knowledge of the NonAdminBackup object and represents the
// array of the conditions through which the NonAdminBackup has or has not passed
// Predefined conditions for NonAdminController objects.
// One NonAdminController object may have multiple conditions.
// It is more granular knowledge of the NonAdminController object and represents the
// array of the conditions through which the NonAdminController has or has not passed
const (
NonAdminConditionAccepted NonAdminCondition = "Accepted"
NonAdminConditionQueued NonAdminCondition = "Queued"
Expand Down
122 changes: 122 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: 8 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand Down Expand Up @@ -140,6 +138,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminBackup")
os.Exit(1)
}
if err = (&controller.NonAdminBackupStorageLocationReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
OADPNamespace: oadpNamespace,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminBackupStorageLocation")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Loading
Loading