Skip to content

Commit

Permalink
Update deps and make more robust
Browse files Browse the repository at this point in the history
* The API Server now requires now configuration at all, it will detect
  what's available at runtime
* Dependencies have been updated
* New OpenAPI code generation is required
  • Loading branch information
Kidswiss committed Jul 8, 2024
1 parent a60a2e0 commit 95c1d92
Show file tree
Hide file tree
Showing 28 changed files with 3,800 additions and 1,024 deletions.
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
33 changes: 13 additions & 20 deletions cmd/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
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"
)

Expand All @@ -28,38 +29,30 @@ func newAPIServerCMD() *cobra.Command {
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")
}
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().
ExposeLoopbackAuthorizer().
ExposeLoopbackMasterClientConfig()

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

cmd, err := b.Build()
cmd.Use = "apiserver"
cmd.Short = "AppCat API Server"
Expand Down
Loading

0 comments on commit 95c1d92

Please sign in to comment.