Compare commits
No commits in common. "906dbd753951834a3335d3fa18e11b8f83d5a6eb" and "0f65f114f60d5ae946cf224819ef464a64617175" have entirely different histories.
906dbd7539
...
0f65f114f6
@ -21,6 +21,14 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/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.
|
||||||
|
|
||||||
|
// Resource references a repsoitory where the backups will be stored
|
||||||
|
type Repository struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
type Step struct {
|
type Step struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Namespace string `json:"namespace"`
|
Namespace string `json:"namespace"`
|
||||||
@ -62,7 +70,11 @@ type Keep struct {
|
|||||||
|
|
||||||
// BackupConfigurationSpec defines the desired state of BackupConfiguration
|
// BackupConfigurationSpec defines the desired state of BackupConfiguration
|
||||||
type BackupConfigurationSpec struct {
|
type BackupConfigurationSpec struct {
|
||||||
Repository string `json:"repository"`
|
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
|
||||||
|
// Important: Run "make" to regenerate code after modifying this file
|
||||||
|
|
||||||
|
// Foo is an example field of BackupConfiguration. Edit BackupConfiguration_types.go to remove/update
|
||||||
|
Repository `json:"repository"`
|
||||||
|
|
||||||
// +optional
|
// +optional
|
||||||
Suspend *bool `json:"suspend,omitempty"`
|
Suspend *bool `json:"suspend,omitempty"`
|
||||||
|
|||||||
@ -104,6 +104,7 @@ func (in *BackupConfigurationList) DeepCopyObject() runtime.Object {
|
|||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *BackupConfigurationSpec) DeepCopyInto(out *BackupConfigurationSpec) {
|
func (in *BackupConfigurationSpec) DeepCopyInto(out *BackupConfigurationSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
out.Repository = in.Repository
|
||||||
if in.Suspend != nil {
|
if in.Suspend != nil {
|
||||||
in, out := &in.Suspend, &out.Suspend
|
in, out := &in.Suspend, &out.Suspend
|
||||||
*out = new(bool)
|
*out = new(bool)
|
||||||
@ -447,6 +448,21 @@ func (in *RepoStatus) DeepCopy() *RepoStatus {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
|
func (in *Repository) DeepCopyInto(out *Repository) {
|
||||||
|
*out = *in
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Repository.
|
||||||
|
func (in *Repository) DeepCopy() *Repository {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := new(Repository)
|
||||||
|
in.DeepCopyInto(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *RestoreSession) DeepCopyInto(out *RestoreSession) {
|
func (in *RestoreSession) DeepCopyInto(out *RestoreSession) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
|||||||
@ -83,9 +83,6 @@ func (r *BackupConfigurationReconciler) deleteSidecarContainer(backupConf *formo
|
|||||||
if err := r.Update(context.Background(), deployment); err != nil {
|
if err := r.Update(context.Background(), deployment); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := formolrbac.DeleteFormolRBAC(r.Client, deployment.Spec.Template.Spec.ServiceAccountName, deployment.Namespace); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
selector, err := metav1.LabelSelectorAsMap(deployment.Spec.Selector)
|
selector, err := metav1.LabelSelectorAsMap(deployment.Spec.Selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -174,7 +171,7 @@ func (r *BackupConfigurationReconciler) addSidecarContainer(backupConf *formolv1
|
|||||||
repo := &formolv1alpha1.Repo{}
|
repo := &formolv1alpha1.Repo{}
|
||||||
if err := r.Get(context.Background(), client.ObjectKey{
|
if err := r.Get(context.Background(), client.ObjectKey{
|
||||||
Namespace: backupConf.Namespace,
|
Namespace: backupConf.Namespace,
|
||||||
Name: backupConf.Spec.Repository,
|
Name: backupConf.Spec.Repository.Name,
|
||||||
}, repo); err != nil {
|
}, repo); err != nil {
|
||||||
log.Error(err, "unable to get Repo from BackupConfiguration")
|
log.Error(err, "unable to get Repo from BackupConfiguration")
|
||||||
return err
|
return err
|
||||||
@ -337,6 +334,7 @@ func (r *BackupConfigurationReconciler) Reconcile(req ctrl.Request) (ctrl.Result
|
|||||||
|
|
||||||
log.V(1).Info("Enter Reconcile with req", "req", req)
|
log.V(1).Info("Enter Reconcile with req", "req", req)
|
||||||
|
|
||||||
|
// your logic here
|
||||||
backupConf := &formolv1alpha1.BackupConfiguration{}
|
backupConf := &formolv1alpha1.BackupConfiguration{}
|
||||||
if err := r.Get(ctx, req.NamespacedName, backupConf); err != nil {
|
if err := r.Get(ctx, req.NamespacedName, backupConf); err != nil {
|
||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
@ -355,7 +353,9 @@ func (r *BackupConfigurationReconciler) Reconcile(req ctrl.Request) (ctrl.Result
|
|||||||
} else {
|
} else {
|
||||||
log.V(0).Info("backupconf being deleted", "backupconf", backupConf.Name)
|
log.V(0).Info("backupconf being deleted", "backupconf", backupConf.Name)
|
||||||
if formolutils.ContainsString(backupConf.ObjectMeta.Finalizers, finalizerName) {
|
if formolutils.ContainsString(backupConf.ObjectMeta.Finalizers, finalizerName) {
|
||||||
_ = r.deleteExternalResources(backupConf)
|
if err := r.deleteExternalResources(backupConf); err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
backupConf.ObjectMeta.Finalizers = formolutils.RemoveString(backupConf.ObjectMeta.Finalizers, finalizerName)
|
backupConf.ObjectMeta.Finalizers = formolutils.RemoveString(backupConf.ObjectMeta.Finalizers, finalizerName)
|
||||||
if err := r.Update(context.Background(), backupConf); err != nil {
|
if err := r.Update(context.Background(), backupConf); err != nil {
|
||||||
@ -363,7 +363,6 @@ func (r *BackupConfigurationReconciler) Reconcile(req ctrl.Request) (ctrl.Result
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
// We have been deleted. Return here
|
// We have been deleted. Return here
|
||||||
log.V(0).Info("backupconf deleted", "backupconf", backupConf.Name)
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +375,7 @@ func (r *BackupConfigurationReconciler) Reconcile(req ctrl.Request) (ctrl.Result
|
|||||||
switch target.Kind {
|
switch target.Kind {
|
||||||
case "Deployment":
|
case "Deployment":
|
||||||
if err := r.addSidecarContainer(backupConf, target); err != nil {
|
if err := r.addSidecarContainer(backupConf, target); err != nil {
|
||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
backupConf.Status.ActiveSidecar = true
|
backupConf.Status.ActiveSidecar = true
|
||||||
case "PersistentVolumeClaim":
|
case "PersistentVolumeClaim":
|
||||||
@ -399,12 +398,31 @@ func (r *BackupConfigurationReconciler) deleteExternalResources(backupConf *form
|
|||||||
for _, target := range backupConf.Spec.Targets {
|
for _, target := range backupConf.Spec.Targets {
|
||||||
switch target.Kind {
|
switch target.Kind {
|
||||||
case "Deployment":
|
case "Deployment":
|
||||||
_ = r.deleteSidecarContainer(backupConf, target)
|
deployment, err := r.getDeployment(backupConf.Namespace, target.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := formolrbac.DeleteFormolRBAC(r.Client, deployment.Spec.Template.Spec.ServiceAccountName, deployment.Namespace); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := formolrbac.DeleteBackupSessionCreatorRBAC(r.Client, backupConf.Namespace); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := r.deleteSidecarContainer(backupConf, target); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: remove the hardcoded "default"
|
// TODO: remove the hardcoded "default"
|
||||||
_ = formolrbac.DeleteFormolRBAC(r.Client, "default", backupConf.Namespace)
|
if err := formolrbac.DeleteFormolRBAC(r.Client, "default", backupConf.Namespace); err != nil {
|
||||||
_ = formolrbac.DeleteBackupSessionCreatorRBAC(r.Client, backupConf.Namespace)
|
return err
|
||||||
|
}
|
||||||
|
if err := formolrbac.DeleteBackupSessionStatusUpdaterRBAC(r.Client, "default", backupConf.Namespace); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := formolrbac.DeleteBackupSessionCreatorRBAC(r.Client, backupConf.Namespace); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
package controllers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"reflect"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
batchv1 "k8s.io/api/batch/v1"
|
|
||||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
|
||||||
|
|
||||||
formolv1alpha1 "github.com/desmo999r/formol/api/v1alpha1"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ = Describe("BackupConfiguration controller", func() {
|
|
||||||
|
|
||||||
})
|
|
||||||
@ -357,7 +357,7 @@ func (r *BackupSessionReconciler) CreateBackupJob(target formolv1alpha1.Target)
|
|||||||
repo := &formolv1alpha1.Repo{}
|
repo := &formolv1alpha1.Repo{}
|
||||||
if err := r.Get(ctx, client.ObjectKey{
|
if err := r.Get(ctx, client.ObjectKey{
|
||||||
Namespace: r.BackupConf.Namespace,
|
Namespace: r.BackupConf.Namespace,
|
||||||
Name: r.BackupConf.Spec.Repository,
|
Name: r.BackupConf.Spec.Repository.Name,
|
||||||
}, repo); err != nil {
|
}, repo); err != nil {
|
||||||
log.Error(err, "unable to get Repo from BackupConfiguration")
|
log.Error(err, "unable to get Repo from BackupConfiguration")
|
||||||
return err
|
return err
|
||||||
@ -415,7 +415,7 @@ func (r *BackupSessionReconciler) deleteExternalResources() error {
|
|||||||
repo := &formolv1alpha1.Repo{}
|
repo := &formolv1alpha1.Repo{}
|
||||||
if err := r.Get(ctx, client.ObjectKey{
|
if err := r.Get(ctx, client.ObjectKey{
|
||||||
Namespace: r.BackupConf.Namespace,
|
Namespace: r.BackupConf.Namespace,
|
||||||
Name: r.BackupConf.Spec.Repository,
|
Name: r.BackupConf.Spec.Repository.Name,
|
||||||
}, repo); err != nil {
|
}, repo); err != nil {
|
||||||
log.Error(err, "unable to get Repo from BackupConfiguration")
|
log.Error(err, "unable to get Repo from BackupConfiguration")
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -92,7 +92,7 @@ func (r *RestoreSessionReconciler) CreateRestoreJob(target formolv1alpha1.Target
|
|||||||
repo := &formolv1alpha1.Repo{}
|
repo := &formolv1alpha1.Repo{}
|
||||||
if err := r.Get(ctx, client.ObjectKey{
|
if err := r.Get(ctx, client.ObjectKey{
|
||||||
Namespace: r.BackupConf.Namespace,
|
Namespace: r.BackupConf.Namespace,
|
||||||
Name: r.BackupConf.Spec.Repository,
|
Name: r.BackupConf.Spec.Repository.Name,
|
||||||
}, repo); err != nil {
|
}, repo); err != nil {
|
||||||
log.Error(err, "unable to get Repo from BackupConfiguration")
|
log.Error(err, "unable to get Repo from BackupConfiguration")
|
||||||
return err
|
return err
|
||||||
@ -221,7 +221,7 @@ func (r *RestoreSessionReconciler) CreateRestoreInitContainer(target formolv1alp
|
|||||||
repo := &formolv1alpha1.Repo{}
|
repo := &formolv1alpha1.Repo{}
|
||||||
if err := r.Get(ctx, client.ObjectKey{
|
if err := r.Get(ctx, client.ObjectKey{
|
||||||
Namespace: r.BackupConf.Namespace,
|
Namespace: r.BackupConf.Namespace,
|
||||||
Name: r.BackupConf.Spec.Repository,
|
Name: r.BackupConf.Spec.Repository.Name,
|
||||||
}, repo); err != nil {
|
}, repo); err != nil {
|
||||||
log.Error(err, "unable to get Repo from BackupConfiguration")
|
log.Error(err, "unable to get Repo from BackupConfiguration")
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -5,7 +5,8 @@ metadata:
|
|||||||
name: backup-demo
|
name: backup-demo
|
||||||
namespace: demo
|
namespace: demo
|
||||||
spec:
|
spec:
|
||||||
repository: repo-minio
|
repository:
|
||||||
|
name: repo-minio
|
||||||
schedule: "15 * * * *"
|
schedule: "15 * * * *"
|
||||||
targets:
|
targets:
|
||||||
- kind: Deployment
|
- kind: Deployment
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user