Skip to content

Commit

Permalink
Implement aggregated ETCDSnashot
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Nov 7, 2024
1 parent e031f84 commit 1758e5b
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,77 +45,51 @@ spec:
properties:
clusterName:
type: string
configRef:
type: string
location:
type: string
machineName:
type: string
required:
- clusterName
- configRef
- location
- machineName
type: object
x-kubernetes-validations:
- message: ETCD snapshot location can't be empty.
rule: size(self.location)>0
rule: size(self.clusterName)>0
status:
default: {}
description: EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore
properties:
conditions:
description: Conditions provide observations of the operational state
of a Cluster API resource.
phase:
description: ETCDSnapshotPhase is a string representation of the phase
of the etcd snapshot
type: string
s3Snapshots:
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: |-
Last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
location:
type: string
message:
description: |-
A human readable message indicating details about the transition.
This field may be empty.
type: string
reason:
description: |-
The reason for the condition's last transition in CamelCase.
The specific API may choose whether or not this field is considered a guaranteed API.
This field may not be empty.
name:
type: string
severity:
description: |-
Severity provides an explicit classification of Reason code, so the users or machines can immediately
understand the current situation and act accordingly.
The Severity field MUST be set only when Status=False.
required:
- location
- name
type: object
type: array
snapshots:
items:
properties:
location:
type: string
status:
description: Status of the condition, one of True, False, Unknown.
machineName:
type: string
type:
description: |-
Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
can be useful (see .node.status.conditions), the ability to deconflict is important.
name:
type: string
required:
- lastTransitionTime
- status
- type
- location
- machineName
- name
type: object
type: array
manual:
type: boolean
phase:
description: ETCDSnapshotPhase is a string representation of the phase
of the etcd snapshot
type: string
type: object
type: object
served: true
Expand Down Expand Up @@ -306,8 +280,6 @@ spec:
type: string
insecure:
type: boolean
location:
type: string
region:
type: string
s3CredentialSecret:
Expand Down
30 changes: 21 additions & 9 deletions exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// ETCDSnapshotPhase is a string representation of the phase of the etcd snapshot
Expand All @@ -39,21 +37,35 @@ const (
ETCDMachineSnapshotFinalizer = "etcdmachinesnapshot.turtles.cattle.io"
)

// +kubebuilder:validation:XValidation:message="ETCD snapshot location can't be empty.",rule="size(self.location)>0"
// +kubebuilder:validation:XValidation:message="ETCD snapshot location can't be empty.",rule="size(self.clusterName)>0"
//
// ETCDMachineSnapshotSpec defines the desired state of EtcdMachineSnapshot
type ETCDMachineSnapshotSpec struct {
ClusterName string `json:"clusterName"`
MachineName string `json:"machineName"`
ConfigRef string `json:"configRef"`
Location string `json:"location"`
MachineName string `json:"machineName,omitempty"`
Location string `json:"location,omitempty"`
}

// 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"`
Phase ETCDSnapshotPhase `json:"phase,omitempty"`

// +optional
Snapshots []ETCDMachineSnapshotFile `json:"snapshots,omitempty"`

// +optional
S3Snapshots []S3SnapshotFile `json:"s3Snapshots,omitempty"`
}

type ETCDMachineSnapshotFile struct {
Name string `json:"name"`
MachineName string `json:"machineName"`
Location string `json:"location"`
}

type S3SnapshotFile struct {
Name string `json:"name"`
Location string `json:"location"`
}

// ETCDMachineSnapshot is the Schema for the ETCDMachineSnapshot API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type S3Config struct {
Region string `json:"region,omitempty"`
Folder string `json:"folder,omitempty"`
Insecure bool `json:"insecure,omitempty"`
Location string `json:"location,omitempty"`
}

// RKE2EtcdMachineSnapshotConfig is the schema for the snapshot config.
Expand Down
45 changes: 39 additions & 6 deletions exp/etcdrestore/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,76 +42,50 @@ spec:
properties:
clusterName:
type: string
configRef:
type: string
location:
type: string
machineName:
type: string
required:
- clusterName
- configRef
- location
- machineName
type: object
x-kubernetes-validations:
- message: ETCD snapshot location can't be empty.
rule: size(self.location)>0
rule: size(self.clusterName)>0
status:
description: EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore
properties:
conditions:
description: Conditions provide observations of the operational state
of a Cluster API resource.
phase:
description: ETCDSnapshotPhase is a string representation of the phase
of the etcd snapshot
type: string
s3Snapshots:
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: |-
Last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
A human readable message indicating details about the transition.
This field may be empty.
location:
type: string
reason:
description: |-
The reason for the condition's last transition in CamelCase.
The specific API may choose whether or not this field is considered a guaranteed API.
This field may not be empty.
name:
type: string
severity:
description: |-
Severity provides an explicit classification of Reason code, so the users or machines can immediately
understand the current situation and act accordingly.
The Severity field MUST be set only when Status=False.
required:
- location
- name
type: object
type: array
snapshots:
items:
properties:
location:
type: string
status:
description: Status of the condition, one of True, False, Unknown.
machineName:
type: string
type:
description: |-
Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
can be useful (see .node.status.conditions), the ability to deconflict is important.
name:
type: string
required:
- lastTransitionTime
- status
- type
- location
- machineName
- name
type: object
type: array
manual:
type: boolean
phase:
description: ETCDSnapshotPhase is a string representation of the phase
of the etcd snapshot
type: string
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ spec:
type: string
insecure:
type: boolean
location:
type: string
region:
type: string
s3CredentialSecret:
Expand Down
18 changes: 0 additions & 18 deletions exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,6 @@ func (r *ETCDMachineSnapshotReconciler) reconcileDelete(
// Log the start of the deletion process
log.Info("Starting deletion of EtcdMachineSnapshot", "name", etcdMachineSnapshot.Name)

// Perform any necessary cleanup of associated resources here
// Example: Delete associated snapshot resources
snapshotList := &snapshotrestorev1.ETCDMachineSnapshotList{}
if err := r.Client.List(ctx, snapshotList, client.InNamespace(etcdMachineSnapshot.Namespace)); err != nil {
log.Error(err, "Failed to list associated EtcdMachineSnapshots")
return err
}

for _, snapshot := range snapshotList.Items {
if snapshot.Spec.MachineName == etcdMachineSnapshot.Spec.MachineName {
if err := r.Client.Delete(ctx, &snapshot); err != nil {
log.Error(err, "Failed to delete associated EtcdMachineSnapshot", "snapshotName", snapshot.Name)
return err
}
log.Info("Deleted associated EtcdMachineSnapshot", "snapshotName", snapshot.Name)
}
}

// Remove the finalizer so the EtcdMachineSnapshot can be garbage collected by Kubernetes.
controllerutil.RemoveFinalizer(etcdMachineSnapshot, snapshotrestorev1.ETCDMachineSnapshotFinalizer)

Expand Down
Loading

0 comments on commit 1758e5b

Please sign in to comment.