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

Add Redis Backup Listing #26

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dist/

# Binaries for programs and plugins
appcat
# But don't ignore the appcat APIS!
!apis/appcat

# temp file, editor and IDE paraphernalia
.idea
Expand All @@ -14,6 +16,7 @@ appcat

# debug
apiserver.local.config
__debug_bin

# Kubebuilder
/apis/generated/
800 changes: 745 additions & 55 deletions apis/appcat/v1/generated.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apis/appcat/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&AppCatList{},
&VSHNPostgresBackup{},
&VSHNPostgresBackupList{},
&VSHNRedisBackup{},
&VSHNRedisBackupList{},
)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
Expand Down
72 changes: 72 additions & 0 deletions apis/appcat/v1/vshn_redis_backup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/apiserver-runtime/pkg/builder/resource"
)

// VSHNRedisBackup needs to implement the builder resource interface
var _ resource.Object = &VSHNRedisBackup{}
var _ resource.ObjectList = &VSHNRedisBackupList{}

// +kubebuilder:object:root=true

type VSHNRedisBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status VSHNRedisBackupStatus `json:"status,omitempty"`
}

type VSHNRedisBackupStatus struct {
ID string `json:"id,omitempty"`
Date metav1.Time `json:"date,omitempty"`
Instance string `json:"instance,omitempty"`
}

// +kubebuilder:object:root=true

type VSHNRedisBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []VSHNRedisBackup `json:"items,omitempty"`
}

// GetGroupVersionResource returns the GroupVersionResource for this resource.
// The resource should be the all lowercase and pluralized kind
func (in *VSHNRedisBackup) GetGroupVersionResource() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: GroupVersion.Group,
Version: GroupVersion.Version,
Resource: "vshnredisbackups",
}
}

func (in *VSHNRedisBackup) GetObjectMeta() *metav1.ObjectMeta {
return &in.ObjectMeta
}

// IsStorageVersion returns true if the object is also the internal version -- i.e. is the type defined for the API group or an alias to this object.
// If false, the resource is expected to implement MultiVersionObject interface.
func (in *VSHNRedisBackup) IsStorageVersion() bool {
return true
}

func (in *VSHNRedisBackup) NamespaceScoped() bool {
return true
}

func (in *VSHNRedisBackup) New() runtime.Object {
return &VSHNRedisBackup{}
}

func (in *VSHNRedisBackup) NewList() runtime.Object {
return &VSHNRedisBackupList{}
}

func (in *VSHNRedisBackupList) GetListMeta() *metav1.ListMeta {
return &in.ListMeta
}
74 changes: 74 additions & 0 deletions apis/appcat/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions apis/vshn/v1/dbaas_vshn_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ type VSHNRedis struct {
Status VSHNRedisStatus `json:"status,omitempty"`
}

// +kubebuilder:object:generate=true
// +kubebuilder:object:root=true
type VSHNRedisList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []VSHNRedis `json:"items,omitempty"`
}

// VSHNRedisSpec defines the desired state of a VSHNRedis.
type VSHNRedisSpec struct {
// Parameters are the configurable fields of a VSHNRedis.
Expand Down
9 changes: 8 additions & 1 deletion apis/vshn/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@ var (
)

func init() {
SchemeBuilder.Register(&VSHNPostgreSQL{}, &VSHNPostgreSQLList{}, &XVSHNPostgreSQL{}, &XVSHNPostgreSQLList{})
SchemeBuilder.Register(
&VSHNPostgreSQL{},
&VSHNPostgreSQLList{},
&XVSHNPostgreSQL{},
&XVSHNPostgreSQLList{},
&VSHNRedis{},
&VSHNRedisList{},
)
}
32 changes: 32 additions & 0 deletions apis/vshn/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 17 additions & 20 deletions cmd/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package cmd
import (
"log"
"os"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/viper"
appcatv1 "github.com/vshn/appcat/apis/appcat/v1"
"github.com/vshn/appcat/pkg/apiserver/appcat"
"github.com/vshn/appcat/pkg/apiserver/vshn/postgres"
"github.com/vshn/appcat/pkg/apiserver/vshn/redis"
"sigs.k8s.io/apiserver-runtime/pkg/builder"
)

Expand All @@ -17,14 +18,22 @@ var apiServerCMDStr = "apiserver"
var APIServerCMD = newAPIServerCMD()

func newAPIServerCMD() *cobra.Command {
var appcatEnabled, vshnBackupsEnabled bool

viper.AutomaticEnv()

var appcatEnabled, vshnPGBackupsEnabled, vshnRedisBackupsEnabled bool

if len(os.Args) < 2 {
return &cobra.Command{}
}

if os.Args[1] == apiServerCMDStr {
appcatEnabled, vshnBackupsEnabled = parseEnvVariables()
appcatEnabled = viper.GetBool("APPCAT_HANDLER_ENABLED")
vshnPGBackupsEnabled = viper.GetBool("VSHN_POSTGRES_BACKUP_HANDLER_ENABLED")
vshnRedisBackupsEnabled = viper.GetBool("VSHN_REDIS_BACKUP_HANDLER_ENABLED")
if !appcatEnabled && !vshnPGBackupsEnabled && !vshnRedisBackupsEnabled {
log.Fatal("Handlers are not enabled, please set at least one of APPCAT_HANDLER_ENABLED | VSHN_POSTGRES_BACKUP_HANDLER_ENABLED | VSHN_REDIS_BACKUP_HANDLER_ENABLED env variables to True")
}
}

b := builder.APIServer
Expand All @@ -33,10 +42,14 @@ func newAPIServerCMD() *cobra.Command {
b.WithResourceAndHandler(&appcatv1.AppCat{}, appcat.New())
}

if vshnBackupsEnabled {
if vshnPGBackupsEnabled {
b.WithResourceAndHandler(&appcatv1.VSHNPostgresBackup{}, postgres.New())
}

if vshnRedisBackupsEnabled {
b.WithResourceAndHandler(&appcatv1.VSHNRedisBackup{}, redis.New())
}

b.WithoutEtcd().
ExposeLoopbackAuthorizer().
ExposeLoopbackMasterClientConfig()
Expand All @@ -50,19 +63,3 @@ func newAPIServerCMD() *cobra.Command {
}
return cmd
}

func parseEnvVariables() (bool, bool) {
appcatEnabled, err := strconv.ParseBool(os.Getenv("APPCAT_HANDLER_ENABLED"))
if err != nil {
log.Fatal("Can't parse APPCAT_HANDLER_ENABLED env variable")
}
vshnBackupsEnabled, err := strconv.ParseBool(os.Getenv("VSHN_POSTGRES_BACKUP_HANDLER_ENABLED"))
if err != nil {
log.Fatal("Can't parse VSHN_POSTGRES_BACKUP_HANDLER_ENABLED env variable")
}

if !appcatEnabled && !vshnBackupsEnabled {
log.Fatal("Handlers are not enabled, please set at least one of APPCAT_HANDLER_ENABLED | VSHN_POSTGRES_BACKUP_HANDLER_ENABLED env variables to True")
}
return appcatEnabled, vshnBackupsEnabled
}
9 changes: 9 additions & 0 deletions config/apiserver/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ rules:
- vshn.appcat.vshn.io
resources:
- xvshnpostgresqls
- vshnredis
verbs:
- get
- list
- watch
- apiGroups:
- k8up.io
resources:
- snapshots
verbs:
- get
- list
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/go-containerregistry v0.9.0
github.com/hashicorp/go-version v1.6.0
github.com/jackc/pgx/v5 v5.3.1
github.com/k8up-io/k8up/v2 v2.7.1
Expand All @@ -34,6 +35,7 @@ require (
go.uber.org/zap v1.24.0
golang.org/x/text v0.9.0
google.golang.org/grpc v1.52.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.0.3
k8s.io/api v0.26.3
k8s.io/apimachinery v0.26.3
Expand Down Expand Up @@ -176,7 +178,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools v2.2.0+incompatible // indirect
helm.sh/helm/v3 v3.10.2 // indirect
k8s.io/apiextensions-apiserver v0.26.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-containerregistry v0.9.0 h1:5Ths7RjxyFV0huKChQTgY6fLzvHhZMpLTFNja8U0/0w=
github.com/google/go-containerregistry v0.9.0/go.mod h1:9eq4BnSufyT1kHNffX+vSXVonaJ7yaIOulrKZejMxnQ=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
Expand Down
Loading