Skip to content

Commit

Permalink
feat: improve ux on auto/manual etcd snapshots
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Salas <[email protected]>
  • Loading branch information
salasberryfin committed Oct 7, 2024
1 parent 39f90d1 commit 0311d32
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ type EtcdMachineSnapshotSpec struct {
ClusterName string `json:"clusterName"`
MachineName string `json:"machineName"`
ConfigRef string `json:"configRef"`
Manual bool `json:"manual"`
Location string `json:"location"`
}

// EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 "":
Expand Down
4 changes: 4 additions & 0 deletions exp/etcdrestore/controllers/snapshotters/rke2snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions util/annotations/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0311d32

Please sign in to comment.