Skip to content

Commit

Permalink
Implement etcd snapshot restore skeleton
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 Sep 26, 2024
1 parent 1f0e17f commit d79df7c
Show file tree
Hide file tree
Showing 16 changed files with 525 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ metadata:
spec:
group: turtles-capi.cattle.io
names:
kind: EtcdMachineSnapshot
listKind: EtcdMachineSnapshotList
kind: ETCDMachineSnapshot
listKind: ETCDMachineSnapshotList
plural: etcdmachinesnapshots
singular: etcdmachinesnapshot
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: EtcdMachineSnapshot is the Schema for the EtcdMachineSnapshot
description: ETCDMachineSnapshot is the Schema for the ETCDMachineSnapshot
API.
properties:
apiVersion:
Expand All @@ -41,7 +41,7 @@ spec:
metadata:
type: object
spec:
description: EtcdMachineSnapshotSpec defines the desired state of EtcdMachineSnapshot
description: ETCDMachineSnapshotSpec defines the desired state of EtcdMachineSnapshot
properties:
clusterName:
type: string
Expand All @@ -60,6 +60,9 @@ spec:
- machineName
- manual
type: object
x-kubernetes-validations:
- message: ETCD snapshot location can't be empty.
rule: size(self.location)>0
status:
default: {}
description: EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore
Expand Down Expand Up @@ -133,16 +136,16 @@ metadata:
spec:
group: turtles-capi.cattle.io
names:
kind: EtcdSnapshotRestore
listKind: EtcdSnapshotRestoreList
kind: ETCDSnapshotRestore
listKind: ETCDSnapshotRestoreList
plural: etcdsnapshotrestores
singular: etcdsnapshotrestore
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: EtcdSnapshotRestore is the schema for the EtcdSnapshotRestore
description: ETCDSnapshotRestore is the schema for the ETCDSnapshotRestore
API.
properties:
apiVersion:
Expand All @@ -163,84 +166,24 @@ spec:
metadata:
type: object
spec:
description: EtcdSnapshotRestoreSpec defines the desired state of EtcdSnapshotRestore.
description: ETCDSnapshotRestoreSpec defines the desired state of EtcdSnapshotRestore.
properties:
clusterName:
type: string
configRef:
description: |-
ObjectReference contains enough information to let you inspect or modify the referred object.
---
New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs.
1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage.
2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular
restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted".
Those cannot be well described when embedded.
3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen.
4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity
during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple
and the version of the actual struct is irrelevant.
5. We cannot easily change it. Because this type is embedded in many locations, updates to this type
will affect numerous schemas. Don't make new APIs embed an underspecified API type they do not control.
Instead of using this type, create a locally provided and used type that is well-focused on your reference.
For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 .
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: |-
If referring to a piece of an object instead of an entire object, this string
should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within a pod, this would take on a value like:
"spec.containers{name}" (where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined way of
referencing a part of an object.
TODO: this design is not final and this field is subject to change in the future.
type: string
kind:
description: |-
Kind of the referent.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
namespace:
description: |-
Namespace of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
type: string
resourceVersion:
description: |-
Specific resourceVersion to which this reference is made, if any.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
type: string
uid:
description: |-
UID of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
type: string
type: object
x-kubernetes-map-type: atomic
etcdMachineSnapshotName:
type: string
ttlSecondsAfterFinished:
type: integer
required:
- clusterName
- configRef
- etcdMachineSnapshotName
- ttlSecondsAfterFinished
type: object
x-kubernetes-validations:
- message: Cluster Name can't be empty.
rule: size(self.clusterName)>0
- message: ETCD machine snapshot name can't be empty.
rule: size(self.etcdMachineSnapshotName)>0
status:
default: {}
description: EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore.
description: ETCDSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore.
properties:
conditions:
description: Conditions provide observations of the operational state
Expand Down Expand Up @@ -289,6 +232,7 @@ spec:
type: object
type: array
phase:
default: Pending
description: ETCDSnapshotPhase is a string representation of the phase
of the etcd snapshot
type: string
Expand Down
24 changes: 13 additions & 11 deletions exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ const (
ETCDMachineSnapshotFinalizer = "etcdmachinesnapshot.turtles.cattle.io"
)

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

// EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore
type EtcdMachineSnapshotStatus struct {
type ETCDMachineSnapshotStatus struct {
Phase ETCDSnapshotPhase `json:"phase,omitempty"`
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

// EtcdMachineSnapshot is the Schema for the EtcdMachineSnapshot API.
// ETCDMachineSnapshot is the Schema for the ETCDMachineSnapshot API.
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type EtcdMachineSnapshot struct {
type ETCDMachineSnapshot struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec EtcdMachineSnapshotSpec `json:"spec,omitempty"`
Status EtcdMachineSnapshotStatus `json:"status,omitempty"`
Spec ETCDMachineSnapshotSpec `json:"spec,omitempty"`
Status ETCDMachineSnapshotStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// EtcdMachineSnapshotList contains a list of EtcdMachineSnapshots.
type EtcdMachineSnapshotList struct {
// ETCDMachineSnapshotList contains a list of EtcdMachineSnapshots.
type ETCDMachineSnapshotList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EtcdMachineSnapshot `json:"items"`
Items []ETCDMachineSnapshot `json:"items"`
}

func init() {
objectTypes = append(objectTypes, &EtcdMachineSnapshot{}, &EtcdMachineSnapshotList{})
objectTypes = append(objectTypes, &ETCDMachineSnapshot{}, &ETCDMachineSnapshotList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type RKE2EtcdMachineSnapshotConfig struct {
type RKE2EtcdMachineSnapshotConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EtcdSnapshotRestore `json:"items"`
Items []ETCDSnapshotRestore `json:"items"`
}

func init() {
Expand Down
49 changes: 30 additions & 19 deletions exp/etcdrestore/api/v1alpha1/etcdsnapshotrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
Expand All @@ -44,41 +43,53 @@ const (
ETCDSnapshotRestorePhaseFinished ETCDSnapshotRestorePhase = "Done"
)

// EtcdSnapshotRestoreSpec defines the desired state of EtcdSnapshotRestore.
type EtcdSnapshotRestoreSpec struct {
ClusterName string `json:"clusterName"`
EtcdMachineSnapshotName string `json:"etcdMachineSnapshotName"`
TTLSecondsAfterFinished int `json:"ttlSecondsAfterFinished"`
ConfigRef corev1.ObjectReference `json:"configRef"`
// +kubebuilder:validation:XValidation:message="Cluster Name can't be empty.",rule="size(self.clusterName)>0"
// +kubebuilder:validation:XValidation:message="ETCD machine snapshot name can't be empty.",rule="size(self.etcdMachineSnapshotName)>0"
//
// ETCDSnapshotRestoreSpec defines the desired state of EtcdSnapshotRestore.
type ETCDSnapshotRestoreSpec struct {
// +required
ClusterName string `json:"clusterName"`

// +required
ETCDMachineSnapshotName string `json:"etcdMachineSnapshotName"`

// TTLSecondsAfterFinished int `json:"ttlSecondsAfterFinished"`

// // +required
// ConfigRef corev1.LocalObjectReference `json:"configRef"`
}

// EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore.
type EtcdSnapshotRestoreStatus struct {
Phase ETCDSnapshotPhase `json:"phase,omitempty"`
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
// ETCDSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore.
type ETCDSnapshotRestoreStatus struct {
// +kubebuilder:default=Pending
Phase ETCDSnapshotRestorePhase `json:"phase,omitempty"`
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

// EtcdSnapshotRestore is the schema for the EtcdSnapshotRestore API.
// ETCDSnapshotRestore is the schema for the ETCDSnapshotRestore API.
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type EtcdSnapshotRestore struct {
type ETCDSnapshotRestore struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec EtcdSnapshotRestoreSpec `json:"spec,omitempty"`
Status EtcdSnapshotRestoreStatus `json:"status,omitempty"`
Spec ETCDSnapshotRestoreSpec `json:"spec,omitempty"`

// +kubebuilder:default={}
Status ETCDSnapshotRestoreStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// EtcdSnapshotRestoreList contains a list of EtcdSnapshotRestores.
type EtcdSnapshotRestoreList struct {
// ETCDSnapshotRestoreList contains a list of EtcdSnapshotRestores.
type ETCDSnapshotRestoreList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EtcdSnapshotRestore `json:"items"`
Items []ETCDSnapshotRestore `json:"items"`
}

func init() {
objectTypes = append(objectTypes, &EtcdSnapshotRestore{}, &EtcdSnapshotRestoreList{})
objectTypes = append(objectTypes, &ETCDSnapshotRestore{}, &ETCDSnapshotRestoreList{})
}
Loading

0 comments on commit d79df7c

Please sign in to comment.