Skip to content

Commit

Permalink
Merge pull request #773 from salasberryfin/etcd-snapshot-improve-ux-o…
Browse files Browse the repository at this point in the history
…n-manual-field

feat: improve ux on auto/manual etcd snapshots
  • Loading branch information
salasberryfin authored Oct 9, 2024
2 parents 54fc8ff + 195f0a2 commit a620e34
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ spec:
type: string
machineName:
type: string
manual:
type: boolean
required:
- clusterName
- configRef
- location
- machineName
- manual
type: object
x-kubernetes-validations:
- message: ETCD snapshot location can't be empty.
Expand Down Expand Up @@ -113,6 +110,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
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 @@ -46,14 +46,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
x-kubernetes-validations:
- message: ETCD snapshot location can't be empty.
Expand Down Expand Up @@ -109,6 +106,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 a620e34

Please sign in to comment.