Skip to content

Commit

Permalink
KO-328: Backup and Restore service integration (#299)
Browse files Browse the repository at this point in the history
* Added Backup-service, Backup, and Restore CRs and their Reconcile flow
  • Loading branch information
abhishekdwivedi3060 authored Aug 26, 2024
1 parent a97e3e1 commit 84d1471
Show file tree
Hide file tree
Showing 102 changed files with 9,627 additions and 1,577 deletions.
28 changes: 24 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# # /bin/sh does not support source command needed in make test
# # /bin/sh does not support source command needed in make all-test
#SHELL := /bin/bash

ROOT_DIR=$(shell git rev-parse --show-toplevel)
Expand Down Expand Up @@ -113,6 +113,9 @@ help: ## Display this help.
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
cp $(ROOT_DIR)/config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml $(ROOT_DIR)/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikeclusters.asdb.aerospike.com.yaml
cp $(ROOT_DIR)/config/crd/bases/asdb.aerospike.com_aerospikebackupservices.yaml $(ROOT_DIR)/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikebackupservices.asdb.aerospike.com.yaml
cp $(ROOT_DIR)/config/crd/bases/asdb.aerospike.com_aerospikebackups.yaml $(ROOT_DIR)/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikebackups.asdb.aerospike.com.yaml
cp $(ROOT_DIR)/config/crd/bases/asdb.aerospike.com_aerospikerestores.yaml $(ROOT_DIR)/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikerestores.asdb.aerospike.com.yaml

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand All @@ -137,10 +140,27 @@ $(GOLANGCI_LINT): $(LOCALBIN)
go-lint: golanci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
.PHONY: all-test
all-test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out -r --keep-going -show-node-events -v -timeout=12h0m0s --junit-report="junit.xml" -- ${ARGS}

.PHONY: cluster-test
cluster-test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out --keep-separate-coverprofiles -v . ./cluster -show-node-events -timeout=12h0m0s --junit-report="junit.xml" -- ${ARGS}


.PHONY: backup-service-test
backup-service-test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out --keep-separate-coverprofiles -v . ./backup_service -show-node-events -timeout=1h0m0s --junit-report="junit.xml" -- ${ARGS}

.PHONY: backup-test
backup-test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out --keep-separate-coverprofiles -v . ./backup -show-node-events -timeout=1h0m0s --junit-report="junit.xml" -- ${ARGS}

.PHONY: restore-test
restore-test: manifests generate fmt vet envtest ## Run tests.
# KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out -show-node-events -v -timeout=12h0m0s -focus=${FOCUS} --junit-report="junit.xml" -- ${ARGS}
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out --keep-separate-coverprofiles -v . ./restore -show-node-events -timeout=1h0m0s --junit-report="junit.xml" -- ${ARGS}

##@ Build

Expand Down
39 changes: 39 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,43 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: aerospike.com
group: asdb
kind: AerospikeBackup
path: github.com/aerospike/aerospike-kubernetes-operator/api/v1beta1
version: v1beta1
webhooks:
defaulting: false
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: aerospike.com
group: asdb
kind: AerospikeRestore
path: github.com/aerospike/aerospike-kubernetes-operator/api/v1beta1
version: v1beta1
webhooks:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: aerospike.com
group: asdb
kind: AerospikeBackupService
path: github.com/aerospike/aerospike-kubernetes-operator/api/v1beta1
version: v1beta1
webhooks:
defaulting: false
validation: true
webhookVersion: v1
version: "3"
110 changes: 110 additions & 0 deletions api/v1beta1/aerospikebackup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2021.
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 v1beta1

import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// AerospikeBackupSpec defines the desired state of AerospikeBackup for a given AerospikeCluster
// +k8s:openapi-gen=true
type AerospikeBackupSpec struct {
// BackupService is the backup service reference i.e. name and namespace.
// It is used to communicate to the backup service to trigger backups. This field is immutable
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Backup Service"
BackupService BackupService `json:"backupService"`

// Config is the free form configuration for the backup in YAML format.
// This config is used to trigger backups. It includes: aerospike-cluster, backup-routines.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Backup Config"
Config runtime.RawExtension `json:"config"`

// OnDemandBackups is the configuration for on-demand backups.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="On Demand Backups"
// +kubebuilder:validation:MaxItems:=1
OnDemandBackups []OnDemandBackupSpec `json:"onDemandBackups,omitempty"`
}

type BackupService struct {
// Backup service name
Name string `json:"name"`

// Backup service namespace
Namespace string `json:"namespace"`
}

func (b *BackupService) String() string {
return fmt.Sprintf("%s/%s", b.Namespace, b.Name)
}

type OnDemandBackupSpec struct {
// ID is the unique identifier for the on-demand backup.
// +kubebuilder:validation:MinLength=1
ID string `json:"id"`

// RoutineName is the routine name used to trigger on-demand backup.
RoutineName string `json:"routineName"`

// Delay is the interval before starting the on-demand backup.
Delay metav1.Duration `json:"delay,omitempty"`
}

// AerospikeBackupStatus defines the observed state of AerospikeBackup
type AerospikeBackupStatus struct {
// BackupService is the backup service reference i.e. name and namespace.
BackupService BackupService `json:"backupService"`

// Config is the configuration for the backup in YAML format.
// This config is used to trigger backups. It includes: aerospike-cluster, backup-routines.
Config runtime.RawExtension `json:"config"`

// OnDemandBackups is the configuration for on-demand backups.
OnDemandBackups []OnDemandBackupSpec `json:"onDemandBackups,omitempty"`

// TODO: finalize the status and phase
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Backup Service Name",type=string,JSONPath=`.spec.backupService.name`
// +kubebuilder:printcolumn:name="Backup Service Namespace",type=string,JSONPath=`.spec.backupService.namespace`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

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

Spec AerospikeBackupSpec `json:"spec,omitempty"`
Status AerospikeBackupStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&AerospikeBackup{}, &AerospikeBackupList{})
}
Loading

0 comments on commit 84d1471

Please sign in to comment.