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

Update deps and make more robust #13

Merged
merged 1 commit into from
Jul 10, 2024
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
5 changes: 5 additions & 0 deletions apis/appcat/v1/appcat_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var Resource = "appcats"
// +kubebuilder:object:root=true

// AppCat defines the main object for this API Server
// +k8s:openapi-gen=true
type AppCat struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -49,6 +50,7 @@ type AppCat struct {
// +kubebuilder:object:root=true

// AppCatList defines a list of AppCat
// +k8s:openapi-gen=true
type AppCatList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand All @@ -61,6 +63,7 @@ type Details map[string]string

// VSHNPlan represents a plan for a VSHN service.
// It ignores the scheduling labels and other internal fields.
// +k8s:openapi-gen=true
type VSHNPlan struct {
Note string `json:"note,omitempty"`
// JSize is called JSize because protobuf creates a method Size()
Expand All @@ -70,6 +73,7 @@ type VSHNPlan struct {
// VSHNSize describes the aspects of the actual plan.
// This needs to be a separate struct as the protobuf generator can't handle
// embedded struct apparently.
// +k8s:openapi-gen=true
type VSHNSize struct {
CPU string `json:"cpu,omitempty"`
Disk string `json:"disk,omitempty"`
Expand Down Expand Up @@ -118,6 +122,7 @@ func (in *AppCatList) GetListMeta() *metav1.ListMeta {
}

// AppCatStatus defines the observed state of AppCat
// +k8s:openapi-gen=true
type AppCatStatus struct {
// CompositionName is the name of the composition
CompositionName string `json:"compositionName,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions apis/appcat/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// +groupName=api.appcat.vshn.io
package v1

//go:generate go run k8s.io/kube-openapi/cmd/openapi-gen . k8s.io/apimachinery/pkg/api/resource k8s.io/apimachinery/pkg/apis/meta/v1 k8s.io/apimachinery/pkg/runtime k8s.io/apimachinery/pkg/version --output-dir ../../../pkg/openapi --output-pkg openapi

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
5 changes: 3 additions & 2 deletions apis/appcat/v1/vshn_mariadb_backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ var _ resource.Object = &VSHNMariaDBBackup{}
var _ resource.ObjectList = &VSHNMariaDBBackupList{}

// +kubebuilder:object:root=true

// +k8s:openapi-gen=true
type VSHNMariaDBBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

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

// +k8s:openapi-gen=true
type VSHNMariaDBBackupStatus struct {
ID string `json:"id,omitempty"`
Date metav1.Time `json:"date,omitempty"`
Instance string `json:"instance,omitempty"`
}

// +kubebuilder:object:root=true

// +k8s:openapi-gen=true
type VSHNMariaDBBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions apis/appcat/v1/vshn_postgres_backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type VSHNPostgreSQLNamespace string
// +kubebuilder:object:root=true

// VSHNPostgresBackup defines VSHN managed PostgreSQL backups
// +k8s:openapi-gen=true
type VSHNPostgresBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -45,6 +46,7 @@ type VSHNPostgresBackup struct {
}

// VSHNPostgresBackupStatus defines the desired state of VSHNPostgresBackup
// +k8s:openapi-gen=true
type VSHNPostgresBackupStatus struct {
// Process holds status information of the backup process
Process *runtime.RawExtension `json:"process,omitempty"`
Expand Down Expand Up @@ -92,6 +94,7 @@ func (in *VSHNPostgresBackup) IsStorageVersion() bool {
// +kubebuilder:object:root=true

// VSHNPostgresBackupList defines a list of VSHNPostgresBackup
// +k8s:openapi-gen=true
type VSHNPostgresBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 3 additions & 2 deletions apis/appcat/v1/vshn_redis_backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ var _ resource.Object = &VSHNRedisBackup{}
var _ resource.ObjectList = &VSHNRedisBackupList{}

// +kubebuilder:object:root=true

// +k8s:openapi-gen=true
type VSHNRedisBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

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

// +k8s:openapi-gen=true
type VSHNRedisBackupStatus struct {
ID string `json:"id,omitempty"`
Date metav1.Time `json:"date,omitempty"`
Instance string `json:"instance,omitempty"`
}

// +kubebuilder:object:root=true

// +k8s:openapi-gen=true
type VSHNRedisBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
41 changes: 7 additions & 34 deletions cmd/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,37 @@ package cmd

import (
"log"
"os"

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

var apiServerCMDStr = "apiserver"

var APIServerCMD = newAPIServerCMD()

func newAPIServerCMD() *cobra.Command {

viper.AutomaticEnv()

var appcatEnabled, vshnPGBackupsEnabled, vshnRedisBackupsEnabled, vshnMariaDBBackupEnabled bool

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

if os.Args[1] == apiServerCMDStr {
appcatEnabled = viper.GetBool("APPCAT_HANDLER_ENABLED")
vshnPGBackupsEnabled = viper.GetBool("VSHN_POSTGRES_BACKUP_HANDLER_ENABLED")
vshnRedisBackupsEnabled = viper.GetBool("VSHN_REDIS_BACKUP_HANDLER_ENABLED")
vshnMariaDBBackupEnabled = viper.GetBool("VSHN_MARIADB_BACKUP_HANDLER_ENABLED")
if !appcatEnabled && !vshnPGBackupsEnabled && !vshnRedisBackupsEnabled && !vshnMariaDBBackupEnabled {
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

if appcatEnabled {
b.WithResourceAndHandler(&appcatv1.AppCat{}, appcat.New())
}
b.WithResourceAndHandler(&appcatv1.AppCat{}, appcat.New())

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

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

if vshnMariaDBBackupEnabled {
b.WithResourceAndHandler(&appcatv1.VSHNMariaDBBackup{}, vshnmariadb.New())
}
b.WithResourceAndHandler(&appcatv1.VSHNMariaDBBackup{}, vshnmariadb.New())

b.WithoutEtcd().
Kidswiss marked this conversation as resolved.
Show resolved Hide resolved
ExposeLoopbackAuthorizer().
ExposeLoopbackMasterClientConfig()

b.WithOpenAPIDefinitions("Wardle", "0.1", appcatopenapi.GetOpenAPIDefinitions)

cmd, err := b.Build()
cmd.Use = "apiserver"
cmd.Short = "AppCat API Server"
Expand Down
6 changes: 2 additions & 4 deletions config/apiserver/aggregated-apiserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ spec:
- "--tls-cert-file=/apiserver.local.config/certificates/tls.crt"
- "--tls-private-key-file=/apiserver.local.config/certificates/tls.key"
- "--audit-log-path=-"
- "--feature-gates=APIPriorityAndFairness=false"
- "--enable-priority-and-fairness=false" # k8s 1.29+ only
- "--disable-admission-plugins=ValidatingAdmissionPolicy" # k8s 1.30+ only
- "--audit-log-maxage=0"
- "--audit-log-maxbackup=0"
envFrom:
- configMapRef:
name: apiserver-envs
resources:
requests:
cpu: 100m
Expand Down
11 changes: 0 additions & 11 deletions config/apiserver/apiserver-envs.yaml

This file was deleted.

Loading
Loading