-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ScheduledVolumeSnapshot): Create new controller which determines…
… when to create a VolumeSnapshot (#159)
- Loading branch information
Showing
27 changed files
with
751 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2022 Strangelove Ventures 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 ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ScheduledVolumeSnapshot{}, &ScheduledVolumeSnapshotList{}) | ||
} | ||
|
||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// ScheduledVolumeSnapshotSpec defines the desired state of ScheduledVolumeSnapshot | ||
// Creates recurring VolumeSnapshots of a PVC managed by a CosmosFullNode. | ||
// A VolumeSnapshot is a CRD (installed in GKE by default). | ||
// See: https://kubernetes.io/docs/concepts/storage/volume-snapshots/ | ||
// This enables recurring, consistent backups. | ||
// To prevent data corruption, a pod is temporarily deleted while the snapshot takes place which could take | ||
// several minutes. | ||
// Therefore, if you create a ScheduledVolumeSnapshot, you must use replica count >= 2 to prevent downtime. | ||
// If <= 1 pod in a ready state, the controller will not temporarily delete the pod. The controller makes every | ||
// effort to prevent downtime. | ||
// Only 1 VolumeSnapshot is created at a time, so at most only 1 pod is temporarily deleted. | ||
// Multiple, parallel VolumeSnapshots are not supported. | ||
type ScheduledVolumeSnapshotSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
// A crontab schedule using the standard as described in https://en.wikipedia.org/wiki/Cron. | ||
// See https://crontab.guru for format. | ||
// Kubernetes providers rate limit VolumeSnapshot creation. Therefore, setting a crontab that's | ||
// too frequent may result in rate limiting errors. | ||
Schedule string `json:"schedule"` | ||
|
||
// The number of recent VolumeSnapshots to keep. | ||
// Default is 3. | ||
// +optional | ||
Limit int32 `json:"limit"` | ||
} | ||
|
||
// ScheduledVolumeSnapshotStatus defines the observed state of ScheduledVolumeSnapshot | ||
type ScheduledVolumeSnapshotStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
// The most recent generation observed by the controller. | ||
ObservedGeneration int64 `json:"observedGeneration"` | ||
|
||
// A generic message for the user. May contain errors. | ||
// +optional | ||
StatusMessage *string `json:"status"` | ||
|
||
// The date when the CRD was created. | ||
// Used as a reference when calculating the next time to create a snapshot. | ||
CreatedAt metav1.Time `json:"createdAt"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// ScheduledVolumeSnapshot is the Schema for the scheduledvolumesnapshots API | ||
type ScheduledVolumeSnapshot struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec ScheduledVolumeSnapshotSpec `json:"spec,omitempty"` | ||
Status ScheduledVolumeSnapshotStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// ScheduledVolumeSnapshotList contains a list of ScheduledVolumeSnapshot | ||
type ScheduledVolumeSnapshotList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ScheduledVolumeSnapshot `json:"items"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
config/crd/bases/cosmos.strange.love_scheduledvolumesnapshots.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.9.0 | ||
creationTimestamp: null | ||
name: scheduledvolumesnapshots.cosmos.strange.love | ||
spec: | ||
group: cosmos.strange.love | ||
names: | ||
kind: ScheduledVolumeSnapshot | ||
listKind: ScheduledVolumeSnapshotList | ||
plural: scheduledvolumesnapshots | ||
singular: scheduledvolumesnapshot | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: ScheduledVolumeSnapshot is the Schema for the scheduledvolumesnapshots | ||
API | ||
properties: | ||
apiVersion: | ||
description: 'APIVersion defines the versioned schema of this representation | ||
of an object. Servers should convert recognized schemas to the latest | ||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
kind: | ||
description: 'Kind is a string value representing the REST resource this | ||
object represents. Servers may infer this from the endpoint the client | ||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
description: 'ScheduledVolumeSnapshotSpec defines the desired state of | ||
ScheduledVolumeSnapshot Creates recurring VolumeSnapshots of a PVC managed | ||
by a CosmosFullNode. A VolumeSnapshot is a CRD (installed in GKE by | ||
default). See: https://kubernetes.io/docs/concepts/storage/volume-snapshots/ | ||
This enables recurring, consistent backups. To prevent data corruption, | ||
a pod is temporarily deleted while the snapshot takes place which could | ||
take several minutes. Therefore, if you create a ScheduledVolumeSnapshot, | ||
you must use replica count >= 2 to prevent downtime. If <= 1 pod in | ||
a ready state, the controller will not temporarily delete the pod. The | ||
controller makes every effort to prevent downtime. Only 1 VolumeSnapshot | ||
is created at a time, so at most only 1 pod is temporarily deleted. | ||
Multiple, parallel VolumeSnapshots are not supported.' | ||
properties: | ||
limit: | ||
description: The number of recent VolumeSnapshots to keep. Default | ||
is 3. | ||
format: int32 | ||
type: integer | ||
schedule: | ||
description: A crontab schedule using the standard as described in | ||
https://en.wikipedia.org/wiki/Cron. See https://crontab.guru for | ||
format. Kubernetes providers rate limit VolumeSnapshot creation. | ||
Therefore, setting a crontab that's too frequent may result in rate | ||
limiting errors. | ||
type: string | ||
required: | ||
- schedule | ||
type: object | ||
status: | ||
description: ScheduledVolumeSnapshotStatus defines the observed state | ||
of ScheduledVolumeSnapshot | ||
properties: | ||
createdAt: | ||
description: The date when the CRD was created. Used as a reference | ||
when calculating the next time to create a snapshot. | ||
format: date-time | ||
type: string | ||
observedGeneration: | ||
description: The most recent generation observed by the controller. | ||
format: int64 | ||
type: integer | ||
status: | ||
description: A generic message for the user. May contain errors. | ||
type: string | ||
required: | ||
- createdAt | ||
- observedGeneration | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
config/crd/patches/cainjection_in_scheduledvolumesnapshots.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# The following patch adds a directive for certmanager to inject CA into the CRD | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) | ||
name: scheduledvolumesnapshots.cosmos.strange.love |
16 changes: 16 additions & 0 deletions
16
config/crd/patches/webhook_in_scheduledvolumesnapshots.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# The following patch enables a conversion webhook for the CRD | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: scheduledvolumesnapshots.cosmos.strange.love | ||
spec: | ||
conversion: | ||
strategy: Webhook | ||
webhook: | ||
clientConfig: | ||
service: | ||
namespace: system | ||
name: webhook-service | ||
path: /convert | ||
conversionReviewVersions: | ||
- v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.