Skip to content

Commit

Permalink
Merge pull request #690 from Danil-Grigorev/etcd-backup-restore-api
Browse files Browse the repository at this point in the history
Add ETCD snapshot restore API types per proposal
  • Loading branch information
alexander-demicev committed Aug 28, 2024
2 parents 35d9e06 + c38703e commit 14f74b8
Show file tree
Hide file tree
Showing 8 changed files with 932 additions and 20 deletions.

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,36 @@ package v1alpha1

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

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

// ETCDSnapshotPhase is a string representation of the phase of the etcd snapshot
type ETCDSnapshotPhase string

const (
// ETCDSnapshotPhasePending is the phase when the snapshot was submitted but was not registered
ETCDSnapshotPhasePending ETCDSnapshotPhase = "Pending"
// ETCDSnapshotPhaseRunning is the phase when the snapshot creation has started
ETCDSnapshotPhaseRunning ETCDSnapshotPhase = "Running"
// ETCDSnapshotPhaseFailed is the phase when the snapshot creation has failed
ETCDSnapshotPhaseFailed ETCDSnapshotPhase = "Failed"
// ETCDSnapshotPhaseDone is the phase when the snapshot creation has finished
ETCDSnapshotPhaseDone ETCDSnapshotPhase = "Done"
)

// EtcdMachineSnapshotSpec defines the desired state of EtcdMachineSnapshot.
// EtcdMachineSnapshotSpec defines the desired state of EtcdMachineSnapshot
type EtcdMachineSnapshotSpec struct {
Foo string `json:"foo,omitempty""`
ClusterName string `json:"clusterName"`
MachineName string `json:"machineName"`
ConfigRef corev1.ObjectReference `json:"configRef"`
}

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

// EtcdMachineSnapshot is the Schema for the EtcdMachineSnapshot API.
Expand Down
69 changes: 69 additions & 0 deletions exp/etcdrestore/api/v1alpha1/etcdmachinesnapshotconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright © 2023 - 2024 SUSE LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// RKE2EtcdMachineSnapshotConfigSpec defines the desired state of RKE2EtcdMachineSnapshotConfig
type RKE2EtcdMachineSnapshotConfigSpec struct {
Manual bool `json:"manual"`
S3 S3Config `json:"s3"`
Local LocalConfig `json:"local"`
}

type LocalConfig struct {
DataDir string `json:"dataDir"`
}

type S3Config struct {
Endpoint string `json:"endpoint"`
EndpointCASecret *corev1.ObjectReference `json:"endpointCAsecret,omitempty"`
EnforceSSLVerify bool `json:"enforceSslVerify,omitempty"`
S3CredentialSecret corev1.ObjectReference `json:"s3CredentialSecret"`
Bucket string `json:"bucket,omitempty"`
Region string `json:"region,omitempty"`
Folder string `json:"folder,omitempty"`
}

// RKE2EtcdMachineSnapshotConfig is the schema for the snapshot config.
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// RKE2EtcdMachineSnapshotConfig is the config for the RKE2EtcdMachineSnapshotConfig API
type RKE2EtcdMachineSnapshotConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RKE2EtcdMachineSnapshotConfigSpec `json:"spec,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
objectTypes = append(objectTypes, &RKE2EtcdMachineSnapshotConfig{}, &RKE2EtcdMachineSnapshotConfigList{})
}
32 changes: 30 additions & 2 deletions exp/etcdrestore/api/v1alpha1/etcdsnapshotrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,45 @@ 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"
)

// ETCDSnapshotPhase is a string representation of the phase of the etcd snapshot
type ETCDSnapshotRestorePhase string

const (
// ETCDSnapshotRestorePhasePending is the phase when the snapshot was submitted but was not registered
ETCDSnapshotRestorePhasePending ETCDSnapshotRestorePhase = "Pending"
// ETCDSnapshotRestorePhaseStarted is the phase when the snapshot creation has started
ETCDSnapshotRestorePhaseStarted ETCDSnapshotRestorePhase = "Started"
// ETCDSnapshotRestorePhaseShutdown is the phase when the etcd cluster is being shutdown
ETCDSnapshotRestorePhaseShutdown ETCDSnapshotRestorePhase = "Shutdown"
// ETCDSnapshotRestorePhaseRunning is the phase when the snapshot is being restored
ETCDSnapshotRestorePhaseRunning ETCDSnapshotRestorePhase = "Running"
// ETCDSnapshotRestorePhaseAgentRestart is the phase when the cluster is being restarted
ETCDSnapshotRestorePhaseAgentRestart ETCDSnapshotRestorePhase = "Restart"
// ETCDSnapshotRestorePhaseJoinAgents is the phase when the snapshot creation has finished
ETCDSnapshotRestorePhaseJoinAgents ETCDSnapshotRestorePhase = "Joining"
// ETCDSnapshotRestorePhaseFailed is the phase when the snapshot creation has failed
ETCDSnapshotRestorePhaseFailed ETCDSnapshotRestorePhase = "Failed"
// ETCDSnapshotRestorePhaseFinished is the phase when the snapshot creation has finished
ETCDSnapshotRestorePhaseFinished ETCDSnapshotRestorePhase = "Done"
)

// EtcdSnapshotRestoreSpec defines the desired state of EtcdSnapshotRestore.
type EtcdSnapshotRestoreSpec struct {
Foo string `json:"foo,omitempty""`
ClusterName string `json:"clusterName"`
EtcdMachineSnapshotName string `json:"etcdMachineSnapshotName"`
TTLSecondsAfterFinished int `json:"ttlSecondsAfterFinished"`
ConfigRef corev1.ObjectReference `json:"configRef"`
}

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

// EtcdSnapshotRestore is the schema for the EtcdSnapshotRestore API.
Expand Down
133 changes: 131 additions & 2 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.

Loading

0 comments on commit 14f74b8

Please sign in to comment.