Skip to content

Commit

Permalink
Propose the spec change for CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Mhamane <swapnil.mhamane@sap.com>
  • Loading branch information
Swapnil Mhamane committed Oct 1, 2019
1 parent 1afa13c commit d4df760
Show file tree
Hide file tree
Showing 146 changed files with 16,950 additions and 10,846 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ fmt:

# Run go vet against code
vet:
go vet ./...
PACKAGES="$(shell go list -mod=vendor -e ./... | grep -vE '/api|/api/v1alpha1')"
go vet $(PACKAGES)

# Generate code
generate: controller-gen
Expand All @@ -76,3 +77,13 @@ CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

.PHONY: revendor
revendor:
@env GO111MODULE=on go mod vendor -v
@env GO111MODULE=on go mod tidy -v

.PHONY: update-dependencies
update-dependencies:
@env GO111MODULE=on go get -u
@make revendor
5 changes: 4 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: "2"
domain: sapcloud.io
domain: gardener.cloud
repo: github.com/gardener/etcd-druid
resources:
- group: druid
version: v1
kind: Etcd
- group: druid
version: v1alpha1
kind: Etcd
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ The existing method of deploying etcd and backup-sidecar as a StatefulSet allevi
The etcd CRD should contain the information required to create the etcd and backup-restore sidecar in a pod/statefulset.

```yaml
---
---

apiVersion: druid.sapcloud.io/v1
apiVersion: druid.gardener.cloud/v1
kind: Etcd
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"druid.sapcloud.io/v1","kind":"Etcd","metadata":{"annotations":{},"labels":{"app":"etcd-statefulset","garden.sapcloud.io/role":"controlplane","role":"test"},"name":"test","namespace":"shoot--dev--i308301-1"},"spec":{"annotations":{"app":"etcd-statefulset","garden.sapcloud.io/role":"controlplane","networking.gardener.cloud/to-dns":"allowed","networking.gardener.cloud/to-private-networks":"allowed","networking.gardener.cloud/to-public-networks":"allowed","role":"test"},"backup":{"deltaSnapshotMemoryLimit":104857600,"deltaSnapshotPeriod":"300s","etcdConnectionTimeout":"300s","etcdQuotaBytes":8589934592,"fullSnapshotSchedule":"0 */24 * * *","garbageCollectionPeriod":"43200s","garbageCollectionPolicy":"Exponential","imageRepository":"eu.gcr.io/gardener-project/gardener/etcdbrctl","imageVersion":"0.8.0-dev","port":8080,"pullPolicy":"IfNotPresent","resources":{"limits":{"cpu":"500m","memory":"2Gi"},"requests":{"cpu":"23m","memory":"128Mi"}},"snapstoreTempDir":"/var/etcd/data/temp"},"etcd":{"clientPort":2379,"defragmentationSchedule":"0 */24 * * *","enableTLS":false,"imageRepository":"quay.io/coreos/etcd","imageVersion":"v3.3.13","initialClusterState":"new","initialClusterToken":"new","metrics":"basic","pullPolicy":"IfNotPresent","resources":{"limits":{"cpu":"2500m","memory":"4Gi"},"requests":{"cpu":"500m","memory":"1000Mi"}},"serverPort":2380,"storageCapacity":"80Gi","storageClass":"gardener.cloud-fast"},"labels":{"app":"etcd-statefulset","garden.sapcloud.io/role":"controlplane","networking.gardener.cloud/to-dns":"allowed","networking.gardener.cloud/to-private-networks":"allowed","networking.gardener.cloud/to-public-networks":"allowed","role":"test"},"pvcRetentionPolicy":"DeleteAll","replicas":1,"storageCapacity":"80Gi","storageClass":"gardener.cloud-fast","store":{"storageContainer":"shoot--dev--i308301-1--b3caa","storageProvider":"S3","storePrefix":"etcd-test","storeSecret":"etcd-backup"},"tlsClientSecret":"etcd-client-tls","tlsServerSecret":"etcd-server-tls"}}
{"apiVersion":"druid.gardener.cloud/v1","kind":"Etcd","metadata":{"annotations":{},"labels":{"app":"etcd-statefulset","garden.sapcloud.io/role":"controlplane","role":"test"},"name":"test","namespace":"shoot--dev--i308301-1"},"spec":{"annotations":{"app":"etcd-statefulset","garden.sapcloud.io/role":"controlplane","networking.gardener.cloud/to-dns":"allowed","networking.gardener.cloud/to-private-networks":"allowed","networking.gardener.cloud/to-public-networks":"allowed","role":"test"},"backup":{"deltaSnapshotMemoryLimit":104857600,"deltaSnapshotPeriod":"300s","etcdConnectionTimeout":"300s","etcdQuotaBytes":8589934592,"fullSnapshotSchedule":"0 */24 * * *","garbageCollectionPeriod":"43200s","garbageCollectionPolicy":"Exponential","imageRepository":"eu.gcr.io/gardener-project/gardener/etcdbrctl","imageVersion":"0.8.0-dev","port":8080,"pullPolicy":"IfNotPresent","resources":{"limits":{"cpu":"500m","memory":"2Gi"},"requests":{"cpu":"23m","memory":"128Mi"}},"snapstoreTempDir":"/var/etcd/data/temp"},"etcd":{"clientPort":2379,"defragmentationSchedule":"0 */24 * * *","enableTLS":false,"imageRepository":"quay.io/coreos/etcd","imageVersion":"v3.3.13","initialClusterState":"new","initialClusterToken":"new","metrics":"basic","pullPolicy":"IfNotPresent","resources":{"limits":{"cpu":"2500m","memory":"4Gi"},"requests":{"cpu":"500m","memory":"1000Mi"}},"serverPort":2380,"storageCapacity":"80Gi","storageClass":"gardener.cloud-fast"},"labels":{"app":"etcd-statefulset","garden.sapcloud.io/role":"controlplane","networking.gardener.cloud/to-dns":"allowed","networking.gardener.cloud/to-private-networks":"allowed","networking.gardener.cloud/to-public-networks":"allowed","role":"test"},"pvcRetentionPolicy":"DeleteAll","replicas":1,"storageCapacity":"80Gi","storageClass":"gardener.cloud-fast","store":{"storageContainer":"shoot--dev--i308301-1--b3caa","storageProvider":"S3","storePrefix":"etcd-test","storeSecret":"etcd-backup"},"tlsClientSecret":"etcd-client-tls","tlsServerSecret":"etcd-server-tls"}}
creationTimestamp: 2019-09-12T12:20:04Z
finalizers:
- druid.sapcloud.io/etcd-druid
- druid.gardener.cloud/etcd-druid
generation: 3
labels:
app: etcd-statefulset
Expand All @@ -44,7 +44,7 @@ metadata:
name: test
namespace: shoot--dev--i308301-1
resourceVersion: "75172656"
selfLink: /apis/druid.sapcloud.io/v1/namespaces/shoot--dev--i308301-1/etcds/test
selfLink: /apis/druid.gardener.cloud/v1/namespaces/shoot--dev--i308301-1/etcds/test
uid: a6afc65f-d557-11e9-8ea7-469a1879b8a9
spec:
annotations:
Expand Down
36 changes: 0 additions & 36 deletions api/v1/groupversion_info.go

This file was deleted.

207 changes: 97 additions & 110 deletions api/v1/etcd_types.go → api/v1alpha1/etcd_types.go
Original file line number Diff line number Diff line change
@@ -1,151 +1,127 @@
/*
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
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 v1
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.
//
// 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"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// PVCRetentionPolicy defines policies for deleting/retaining Etcd PVCs
type PVCRetentionPolicy string

const (
// PolicyDeleteAll is a constant for a policy type indicating that all the PVCs of etcd instances has to be deleted.
PolicyDeleteAll PVCRetentionPolicy = "DeleteAll"
// PolicyRetainMaster is a constant for a policy type indicating that all the PVCs except that of master has to be deleted.
PolicyRetainMaster PVCRetentionPolicy = "RetainMaster"
// PolicyRetainAll is a constant for a policy type indicating that all the PVCs of etcd has to be retained.
PolicyRetainAll PVCRetentionPolicy = "RetRetainAllainMaster"
// GarbageCollectionPolicyExponential defines the exponential policy for garbage collecting old backups
GarbageCollectionPolicyExponential = "Exponential"
// GarbageCollectionPolicyLimitBased defines the limit based policy for garbage collecting old backups
GarbageCollectionPolicyLimitBased = "LimitBased"

// Basic is a constant for metrics level basic.
Basic MetricsLevel = "basic"
// Extensive is a constant for metrics level extensive.
Extensive MetricsLevel = "extensive"
)

// MetricLevel defines the level 'basic' or 'extensive'.
type MetricLevel string
// MetricsLevel defines the level 'basic' or 'extensive'.
type MetricsLevel string

// GarbageCollectionPolicy defines the type of policy for snapshot garbage collection.
type GarbageCollectionPolicy string

const (
// Basic is a constant for metric level basic.
Basic MetricLevel = "basic"
// Extensive is a constant for metric level extensive.
Extensive MetricLevel = "extensive"
)
// StorageProvider defines the type of object store provider for storing backups.
type StorageProvider string

// Spec defines the desired state of Etcd
type Spec struct {
// +required
Etcd EtcdSpec `json:"etcd"`
// +required
Backup BackupSpec `json:"backup"`
// StoreSpec defines parameters related to ObjectStore persisting backups
type StoreSpec struct {
// +required
Store StoreSpec `json:"store"`
Container string `json:"storageContainer"`
// +optional
PVCRetentionPolicy PVCRetentionPolicy `json:"pvcRetentionPolicy,omitempty"`
Prefix *string `json:"storePrefix,omitempty"`
// +required
Replicas int `json:"replicas"`
// +optional
Labels map[string]string `json:"labels,omitempty"`
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
Provider StorageProvider `json:"provider"`
// +required
StorageClass string `json:"storageClass"`
// +optional
TLSServerSecretName string `json:"tlsServerSecret,omitempty"`
// +optional
TLSClientSecretName string `json:"tlsClientSecret,omitempty"`
// +optional
StorageCapacity string `json:"storageCapacity,omitempty"`
SecretRef corev1.SecretReference `json:"secretRef"`
}

// StoreSpec defines parameters related to ObjectStore persisting backups
type StoreSpec struct {
// +required
StorageContainer string `json:"storageContainer"`
// +optional
StorePrefix string `json:"storePrefix,omitempty"`
// TLSConfig hold the TLS configuration detials.
type TLSConfig struct {
// +required
StorageProvider string `json:"storageProvider"`
ServerTLSSecretRef corev1.SecretReference
// +required
StoreSecret string `json:"storeSecret"`
ClientTLSSecretRef corev1.SecretReference
}

// BackupSpec defines parametes associated with the full and delta snapshots of etcd
type BackupSpec struct {
// +optional
Port int `json:"port,omitempty"`
// +required
ImageRepository string `json:"imageRepository"`
// +required
ImageVersion string `json:"imageVersion"`
// +optional
FullSnapshotSchedule string `json:"fullSnapshotSchedule,omitempty"`
Port *int `json:"port,omitempty"`
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
PullPolicy corev1.PullPolicy `json:"pullPolicy,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
// +required
Version string `json:"version"`
// +optional
GarbageCollectionPolicy GarbageCollectionPolicy `json:"garbageCollectionPolicy,omitempty"`
Store *StoreSpec `json:"store,omitempty"`
// +optional
GarbageCollectionPeriod string `json:"garbageCollectionPeriod,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
EtcdQuotaBytes int `json:"etcdQuotaBytes,omitempty"`
FullSnapshotSchedule *string `json:"fullSnapshotSchedule,omitempty"`
// +optional
EtcdConnectionTimeout string `json:"etcdConnectionTimeout,omitempty"`
GarbageCollectionPolicy *GarbageCollectionPolicy `json:"garbageCollectionPolicy,omitempty"`
// +optional
SnapstoreTempDir string `json:"snapstoreTempDir,omitempty"`
GarbageCollectionPeriod *metav1.Duration `json:"garbageCollectionPeriod,omitempty"`
// +optional
DeltaSnapshotPeriod string `json:"deltaSnapshotPeriod,omitempty"`
DeltaSnapshotPeriod *metav1.Duration `json:"deltaSnapshotPeriod,omitempty"`
// +optional
DeltaSnapshotMemoryLimit int `json:"deltaSnapshotMemoryLimit,omitempty"`
DeltaSnapshotMemoryLimit *resource.Quantity `json:"deltaSnapshotMemoryLimit,omitempty"`
}

// EtcdSpec defines parametes associated etcd deployed
type EtcdSpec struct {
// EtcdConfig defines parametes associated etcd deployed
type EtcdConfig struct {
// +optional
DefragmentationSchedule string `json:"defragmentationSchedule,omitempty"`
Quota *resource.Quantity `json:"quota,omitempty"`
// +optional
ServerPort int `json:"serverPort,omitempty"`
DefragmentationSchedule *string `json:"defragmentationSchedule,omitempty"`
// +optional
ClientPort int `json:"clientPort,omitempty"`
// +required
ImageRepository string `json:"imageRepository"`
ServerPort *int `json:"serverPort,omitempty"`
// +optional
ClientPort *int `json:"clientPort,omitempty"`
// +required
ImageVersion string `json:"imageVersion"`
Version string `json:"version"`
// +optional
MetricLevel MetricLevel `json:"metrics,omitempty"`
AuthSecretRef *corev1.SecretReference `json:"authSecretRef,omitempty"`
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// +required
EnableTLS bool `json:"enableTLS"`
Metrics MetricsLevel `json:"metrics,omitempty"`
// +optional
PullPolicy corev1.PullPolicy `json:"pullPolicy,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
Username string `json:"username,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
}

// EtcdSpec defines the desired state of Etcd
type EtcdSpec struct {
// Standard object's metadata.
// +optional
Password string `json:"password,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// +required
InitialClusterToken string `json:"initialClusterToken"`
Etcd EtcdConfig `json:"etcd"`
// +required
InitialClusterState string `json:"initialClusterState"`
Backup BackupSpec `json:"backup"`
// +required
Replicas int `json:"replicas"`
// +optional
StorageClass *string `json:"storageClass,omitempty"`
// +optional
StorageCapacity *string `json:"storageCapacity,omitempty"`
}

// CrossVersionObjectReference contains enough information to let you identify the referred resource.
Expand Down Expand Up @@ -249,29 +225,40 @@ type LastOperation struct {
Type LastOperationType `json:"type,omitempty"`
}

// Status defines the observed state of Etcd
type Status struct {
Etcd CrossVersionObjectReference `json:"etcd,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
CurrentReplicas int32 `json:"currentReplicas,omitempty"`
Endpoints []corev1.Endpoints `json:"endpoints,omitempty"`
LastError string `json:"lastError,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
ReadyReplicas int32 `json:"readyReplicas,omitempty"`
Ready bool `json:"ready,omitempty"`
UpdatedReplicas int32 `json:"updatedReplicas,omitempty"`
// EtcdStatus defines the observed state of Etcd
type EtcdStatus struct {
// +optional
Etcd CrossVersionObjectReference `json:"etcd,omitempty"`
// +optional
Conditions []Condition `json:"conditions,omitempty"`
// +optional
CurrentReplicas int32 `json:"currentReplicas,omitempty"`
// +optional
Endpoints []corev1.Endpoints `json:"endpoints,omitempty"`
// +optional
ServiceName *string `json:"serviceName,omitempty"`
// +optional
LastError *string `json:"lastError,omitempty"`
// +optional
Replicas int32 `json:"replicas,omitempty"`
// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`
// +optional
Ready bool `json:"ready,omitempty"`
// +optional
UpdatedReplicas int32 `json:"updatedReplicas,omitempty"`
//LastOperation LastOperation `json:"lastOperation,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

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

Spec Spec `json:"spec,omitempty"`
Status Status `json:"status,omitempty"`
Spec EtcdSpec `json:"spec,omitempty"`
Status EtcdStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1
package v1alpha1

import (
. "github.com/onsi/ginkgo"
Expand Down
Loading

0 comments on commit d4df760

Please sign in to comment.