diff --git a/charts/rancher-turtles/templates/rancher-turtles-exp-etcdrestore-components.yaml b/charts/rancher-turtles/templates/rancher-turtles-exp-etcdrestore-components.yaml index 709be9a7..d5a2981e 100644 --- a/charts/rancher-turtles/templates/rancher-turtles-exp-etcdrestore-components.yaml +++ b/charts/rancher-turtles/templates/rancher-turtles-exp-etcdrestore-components.yaml @@ -51,14 +51,11 @@ spec: type: string machineName: type: string - manual: - type: boolean required: - clusterName - configRef - location - machineName - - manual type: object status: default: {} @@ -110,6 +107,8 @@ spec: - type type: object type: array + manual: + type: boolean phase: description: ETCDSnapshotPhase is a string representation of the phase of the etcd snapshot diff --git a/exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go b/exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go index 1285db6c..6b73fca1 100644 --- a/exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go +++ b/exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go @@ -44,7 +44,6 @@ type EtcdMachineSnapshotSpec struct { ClusterName string `json:"clusterName"` MachineName string `json:"machineName"` ConfigRef string `json:"configRef"` - Manual bool `json:"manual"` Location string `json:"location"` } @@ -52,6 +51,7 @@ type EtcdMachineSnapshotSpec struct { type EtcdMachineSnapshotStatus struct { Phase ETCDSnapshotPhase `json:"phase,omitempty"` Conditions clusterv1.Conditions `json:"conditions,omitempty"` + Manual bool `json:"manual,omitempty"` } // EtcdMachineSnapshot is the Schema for the EtcdMachineSnapshot API. diff --git a/exp/etcdrestore/config/crd/bases/turtles-capi.cattle.io_etcdmachinesnapshots.yaml b/exp/etcdrestore/config/crd/bases/turtles-capi.cattle.io_etcdmachinesnapshots.yaml index 6fcd1ef6..c978aa12 100644 --- a/exp/etcdrestore/config/crd/bases/turtles-capi.cattle.io_etcdmachinesnapshots.yaml +++ b/exp/etcdrestore/config/crd/bases/turtles-capi.cattle.io_etcdmachinesnapshots.yaml @@ -48,14 +48,11 @@ spec: type: string machineName: type: string - manual: - type: boolean required: - clusterName - configRef - location - machineName - - manual type: object status: description: EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore @@ -106,6 +103,8 @@ spec: - type type: object type: array + manual: + type: boolean phase: description: ETCDSnapshotPhase is a string representation of the phase of the etcd snapshot diff --git a/exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go b/exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go index 4ce613d0..435c2edd 100644 --- a/exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go +++ b/exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go @@ -24,6 +24,7 @@ import ( k3sv1 "github.com/rancher/turtles/api/rancher/k3s/v1" snapshotrestorev1 "github.com/rancher/turtles/exp/etcdrestore/api/v1alpha1" + turtlesannotations "github.com/rancher/turtles/util/annotations" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" kerrors "k8s.io/apimachinery/pkg/util/errors" @@ -80,7 +81,7 @@ func (r *EtcdMachineSnapshotReconciler) Reconcile(ctx context.Context, req ctrl. return ctrl.Result{}, err } - if !etcdMachineSnapshot.Spec.Manual { + if turtlesannotations.HasAnnotation(etcdMachineSnapshot, turtlesannotations.EtcdAutomaticSnapshot) { log.V(5).Info("Skipping snapshot creation for non-manual EtcdMachineSnapshot") return ctrl.Result{}, nil } @@ -123,7 +124,6 @@ func (r *EtcdMachineSnapshotReconciler) Reconcile(ctx context.Context, req ctrl. func (r *EtcdMachineSnapshotReconciler) reconcileNormal( ctx context.Context, etcdMachineSnapshot *snapshotrestorev1.EtcdMachineSnapshot, ) (ctrl.Result, error) { - // Handle different phases of the etcdmachinesnapshot creation process switch etcdMachineSnapshot.Status.Phase { case "": diff --git a/exp/etcdrestore/controllers/snapshotters/rke2snapshotter.go b/exp/etcdrestore/controllers/snapshotters/rke2snapshotter.go index 89e86f8b..51e85d7b 100644 --- a/exp/etcdrestore/controllers/snapshotters/rke2snapshotter.go +++ b/exp/etcdrestore/controllers/snapshotters/rke2snapshotter.go @@ -22,6 +22,7 @@ import ( k3sv1 "github.com/rancher/turtles/api/rancher/k3s/v1" snapshotrestorev1 "github.com/rancher/turtles/exp/etcdrestore/api/v1alpha1" + turtlesannotations "github.com/rancher/turtles/util/annotations" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -125,6 +126,9 @@ func (s *RKE2Snapshotter) Sync(ctx context.Context) error { ObjectMeta: metav1.ObjectMeta{ Name: snapshotFile.Name, Namespace: s.cluster.Namespace, + Annotations: map[string]string{ + turtlesannotations.EtcdAutomaticSnapshot: "true", + }, }, Spec: snapshotrestorev1.EtcdMachineSnapshotSpec{ ClusterName: s.cluster.Name, diff --git a/util/annotations/helpers.go b/util/annotations/helpers.go index 2dfda282..0d77e1c0 100644 --- a/util/annotations/helpers.go +++ b/util/annotations/helpers.go @@ -23,6 +23,8 @@ import ( const ( // ClusterImportedAnnotation represents cluster imported annotation. ClusterImportedAnnotation = "imported" + // EtcdAutomaticSnapshot represents automatically generated etcd snapshot. + EtcdAutomaticSnapshot = "etcd.turtles.cattle.io/automatic-snapshot" ) // HasClusterImportAnnotation returns true if the object has the `imported` annotation.