Skip to content

Commit

Permalink
Add mongodb & postgres archiver (#1016)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammad Fahim Abrar <fahimabrar@appscode.com>
Co-authored-by: Rakibul-Hossain <rakibul.hossain@appscode.com>
Co-authored-by: Arnob Kumar Saha <arnob@appscode.com>
Co-authored-by: Tamal Saha <tamal@appscode.com>
Co-authored-by: Mehedi Hasan <mehedi.hasan@appscode.com>
Co-authored-by: hmsayem <hmsayem@appscode.com>
  • Loading branch information
6 people authored Nov 28, 2023
1 parent 47793c9 commit 2b06b6e
Show file tree
Hide file tree
Showing 198 changed files with 193,926 additions and 747 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BIN := apimachinery
CRD_OPTIONS ?= "crd:maxDescLen=0,generateEmbeddedObjectMeta=true,allowDangerousTypes=true"
# https://github.com/appscodelabs/gengo-builder
CODE_GENERATOR_IMAGE ?= ghcr.io/appscode/gengo:release-1.25
CORE_API_GROUPS ?= kubedb:v1alpha1 kubedb:v1alpha2 postgres:v1alpha1 catalog:v1alpha1 config:v1alpha1 ops:v1alpha1 autoscaling:v1alpha1 dashboard:v1alpha1 schema:v1alpha1
CORE_API_GROUPS ?= kubedb:v1alpha1 kubedb:v1alpha2 postgres:v1alpha1 catalog:v1alpha1 config:v1alpha1 ops:v1alpha1 autoscaling:v1alpha1 dashboard:v1alpha1 schema:v1alpha1 archiver:v1alpha1
API_GROUPS ?= $(CORE_API_GROUPS) ui:v1alpha1

# This version-strategy uses git tags to set the version string
Expand Down
36 changes: 36 additions & 0 deletions apis/archiver/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright AppsCode Inc. and Contributors
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 fuzzer

import (
"kubedb.dev/apimachinery/apis/archiver/v1alpha1"

fuzz "github.com/google/gofuzz"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
)

// Funcs returns the fuzzer functions for this api group.
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
func(s *v1alpha1.MongoDBArchiver, c fuzz.Continue) {
c.FuzzNoCustom(s) // fuzz self without calling this function again
},
func(s *v1alpha1.PostgresArchiver, c fuzz.Continue) {
c.FuzzNoCustom(s) // fuzz self without calling this function again
},
}
}
30 changes: 30 additions & 0 deletions apis/archiver/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright AppsCode Inc. and Contributors
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 install

import (
"kubedb.dev/apimachinery/apis/archiver/v1alpha1"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1alpha1.SchemeGroupVersion))
}
36 changes: 36 additions & 0 deletions apis/archiver/install/pruning_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright AppsCode Inc. and Contributors
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 install

import (
"testing"

"kubedb.dev/apimachinery/apis/archiver/fuzzer"
"kubedb.dev/apimachinery/apis/archiver/v1alpha1"

clientsetscheme "k8s.io/client-go/kubernetes/scheme"
crdfuzz "kmodules.xyz/crd-schema-fuzz"
)

func TestPruneTypes(t *testing.T) {
Install(clientsetscheme.Scheme)

// CRD v1
if crd := (v1alpha1.MongoDBArchiver{}).CustomResourceDefinition(); crd.V1 != nil {
crdfuzz.SchemaFuzzTestForV1CRD(t, clientsetscheme.Scheme, crd.V1, fuzzer.Funcs)
}
}
27 changes: 27 additions & 0 deletions apis/archiver/install/roundtrip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright AppsCode Inc. and Contributors
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 install

import (
"testing"

"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
)

func TestRoundTripTypes(t *testing.T) {
roundtrip.RoundTripTestForAPIGroup(t, Install, nil)
}
50 changes: 50 additions & 0 deletions apis/archiver/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright AppsCode Inc. and Contributors
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 contains API Schema definitions for the archiver v1alpha1 API group

// +k8s:deepcopy-gen=package,register
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +kubebuilder:object:generate=true
// +groupName=archiver.kubedb.com
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "archiver.kubedb.com", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
35 changes: 35 additions & 0 deletions apis/archiver/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright AppsCode Inc. and Contributors
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 (
"kubedb.dev/apimachinery/crds"

"kmodules.xyz/client-go/apiextensions"
)

func GetFinalizer() string {
return SchemeGroupVersion.Group
}

func (_ MongoDBArchiver) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralMongoDBArchiver))
}

func (_ PostgresArchiver) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralPostgresArchiver))
}
95 changes: 95 additions & 0 deletions apis/archiver/v1alpha1/mongodbarchiver_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2022.
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 (
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmapi "kmodules.xyz/client-go/api/v1"
)

const (
ResourceKindMongoDBArchiver = "MongoDBArchiver"
ResourceSingularMongoDBArchiver = "mongodbarchiver"
ResourcePluralMongoDBArchiver = "mongodbarchivers"
)

// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=mongodbarchivers,singular=mongodbarchiver,shortName=mgarchiver,categories={archiver,kubedb,appscode}
// +kubebuilder:subresource:status
type MongoDBArchiver struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MongoDBArchiverSpec `json:"spec,omitempty"`
Status MongoDBArchiverStatus `json:"status,omitempty"`
}

// MongoDBArchiverSpec defines the desired state of MongoDBArchiver
type MongoDBArchiverSpec struct {
// Databases define which MongoDB databases are allowed to consume this archiver
Databases *dbapi.AllowedConsumers `json:"databases"`
// Pause defines if the backup process should be paused or not
// +optional
Pause bool `json:"pause,omitempty"`
// RetentionPolicy field is the RetentionPolicy of the backupConfiguration's backend
// +optional
RetentionPolicy *kmapi.ObjectReference `json:"retentionPolicy"`
// FullBackup defines the sessionConfig of the fullBackup
// This options will eventually go to the full-backup job's yaml
// +optional
FullBackup *FullBackupOptions `json:"fullBackup"`
// WalBackup defines the config of the WalBackup
// +optional
WalBackup *WalBackupOptions `json:"walBackup"`
// ManifestBackup defines the sessionConfig of the manifestBackup
// This options will eventually go to the manifest-backup job's yaml
// +optional
ManifestBackup *ManifestBackupOptions `json:"manifestBackup"`
// +optional
EncryptionSecret *kmapi.ObjectReference `json:"encryptionSecret"`
// BackupStorage is the backend storageRef of the BackupConfiguration
// +optional
BackupStorage *BackupStorage `json:"backupStorage"`
// DeletionPolicy defines the created repository's deletionPolicy
// +optional
DeletionPolicy *DeletionPolicy `json:"deletionPolicy"`
}

// MongoDBArchiverStatus defines the observed state of MongoDBArchiver
type MongoDBArchiverStatus struct {
// Specifies the information of all the databases managed by this archiver
// +optional
DatabaseRefs []ArchiverDatabaseRef `json:"databaseRefs,omitempty"`
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type MongoDBArchiverList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MongoDBArchiver `json:"items"`
}

func init() {
SchemeBuilder.Register(&MongoDBArchiver{}, &MongoDBArchiverList{})
}
Loading

0 comments on commit 2b06b6e

Please sign in to comment.