Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KO-328: Backup and Restore service integration #299

Merged
merged 23 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
afc1f0d
Initial commit
abhishekdwivedi3060 Jun 12, 2024
1d49482
Working
abhishekdwivedi3060 Jun 18, 2024
8b2ed6e
Added Backup-service, Backup and Restore reconcile flow
abhishekdwivedi3060 Jun 20, 2024
002fc0f
Added Webhooks
abhishekdwivedi3060 Jul 3, 2024
1278150
Adding func comments and created constant.go for all constants
abhishekdwivedi3060 Jul 3, 2024
428eadf
Added Printer columns
abhishekdwivedi3060 Jul 9, 2024
8fefd94
Added Backup Service test-suite
abhishekdwivedi3060 Jul 10, 2024
90c2644
Refactored existing Cluster test-suite and added Backup test-suite
abhishekdwivedi3060 Jul 17, 2024
7cfb79d
Added Backup webhook validation and comments
abhishekdwivedi3060 Jul 19, 2024
1980b62
Incorporate review comments
abhishekdwivedi3060 Jul 23, 2024
5a9c574
Added suite cleanup
abhishekdwivedi3060 Jul 24, 2024
82b8fc7
Incorporate review comments
abhishekdwivedi3060 Jul 24, 2024
ef96920
Added backup service SA in test-suite
abhishekdwivedi3060 Jul 24, 2024
c598852
Added backup routine removal flow
abhishekdwivedi3060 Jul 25, 2024
df5d1d9
Added backup test-case with s3 storage
abhishekdwivedi3060 Jul 29, 2024
a8f3570
Added cluster name update validation
abhishekdwivedi3060 Jul 29, 2024
3ec0b68
Added restore suite
abhishekdwivedi3060 Jul 31, 2024
c948117
Added on-demand backup check
abhishekdwivedi3060 Jul 31, 2024
c8095ff
Incorporate review comments
abhishekdwivedi3060 Aug 5, 2024
40b47f9
Merge branch 'master' into KO-328
abhishekdwivedi3060 Aug 14, 2024
b3c72c3
Fixed merge-conflict
abhishekdwivedi3060 Aug 14, 2024
392abcb
Incorporate review comments
abhishekdwivedi3060 Aug 22, 2024
6bfe93b
Changed yaml unmarshal to strict type for structs
abhishekdwivedi3060 Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tanmayja marked this conversation as resolved.
Show resolved Hide resolved
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.
sud82 marked this conversation as resolved.
Show resolved Hide resolved
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.
tanmayja marked this conversation as resolved.
Show resolved Hide resolved

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"`
tanmayja marked this conversation as resolved.
Show resolved Hide resolved

// 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"`
sud82 marked this conversation as resolved.
Show resolved Hide resolved

// 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
Loading