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

feat: improve ux on auto/manual etcd snapshots #773

Merged
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
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
status:
default: {}
Expand Down Expand Up @@ -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
Expand Down
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
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