Skip to content

Commit 7536f72

Browse files
committed
Update deps and make more robust
* 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
1 parent a60a2e0 commit 7536f72

30 files changed

+3796
-1050
lines changed

apis/appcat/v1/appcat_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var Resource = "appcats"
3737
// +kubebuilder:object:root=true
3838

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

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

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

120124
// AppCatStatus defines the observed state of AppCat
125+
// +k8s:openapi-gen=true
121126
type AppCatStatus struct {
122127
// CompositionName is the name of the composition
123128
CompositionName string `json:"compositionName,omitempty"`

apis/appcat/v1/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// +groupName=api.appcat.vshn.io
55
package v1
66

7+
//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
8+
79
import (
810
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
911
"k8s.io/apimachinery/pkg/runtime"

apis/appcat/v1/vshn_mariadb_backup_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ var _ resource.Object = &VSHNMariaDBBackup{}
1212
var _ resource.ObjectList = &VSHNMariaDBBackupList{}
1313

1414
// +kubebuilder:object:root=true
15-
15+
// +k8s:openapi-gen=true
1616
type VSHNMariaDBBackup struct {
1717
metav1.TypeMeta `json:",inline"`
1818
metav1.ObjectMeta `json:"metadata,omitempty"`
1919

2020
Status VSHNMariaDBBackupStatus `json:"status,omitempty"`
2121
}
2222

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

2930
// +kubebuilder:object:root=true
30-
31+
// +k8s:openapi-gen=true
3132
type VSHNMariaDBBackupList struct {
3233
metav1.TypeMeta `json:",inline"`
3334
metav1.ListMeta `json:"metadata,omitempty"`

apis/appcat/v1/vshn_postgres_backup_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type VSHNPostgreSQLNamespace string
3636
// +kubebuilder:object:root=true
3737

3838
// VSHNPostgresBackup defines VSHN managed PostgreSQL backups
39+
// +k8s:openapi-gen=true
3940
type VSHNPostgresBackup struct {
4041
metav1.TypeMeta `json:",inline"`
4142
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -45,6 +46,7 @@ type VSHNPostgresBackup struct {
4546
}
4647

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

9496
// VSHNPostgresBackupList defines a list of VSHNPostgresBackup
97+
// +k8s:openapi-gen=true
9598
type VSHNPostgresBackupList struct {
9699
metav1.TypeMeta `json:",inline"`
97100
metav1.ListMeta `json:"metadata,omitempty"`

apis/appcat/v1/vshn_redis_backup_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ var _ resource.Object = &VSHNRedisBackup{}
1212
var _ resource.ObjectList = &VSHNRedisBackupList{}
1313

1414
// +kubebuilder:object:root=true
15-
15+
// +k8s:openapi-gen=true
1616
type VSHNRedisBackup struct {
1717
metav1.TypeMeta `json:",inline"`
1818
metav1.ObjectMeta `json:"metadata,omitempty"`
1919

2020
Status VSHNRedisBackupStatus `json:"status,omitempty"`
2121
}
2222

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

2930
// +kubebuilder:object:root=true
30-
31+
// +k8s:openapi-gen=true
3132
type VSHNRedisBackupList struct {
3233
metav1.TypeMeta `json:",inline"`
3334
metav1.ListMeta `json:"metadata,omitempty"`

cmd/apiserver.go

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,37 @@ package cmd
22

33
import (
44
"log"
5-
"os"
65

76
"github.com/spf13/cobra"
8-
"github.com/spf13/viper"
97
appcatv1 "github.com/vshn/appcat-apiserver/apis/appcat/v1"
108
"github.com/vshn/appcat-apiserver/pkg/apiserver/appcat"
119
vshnmariadb "github.com/vshn/appcat-apiserver/pkg/apiserver/vshn/mariadb"
1210
vshnpostgres "github.com/vshn/appcat-apiserver/pkg/apiserver/vshn/postgres"
1311
vshnredis "github.com/vshn/appcat-apiserver/pkg/apiserver/vshn/redis"
12+
appcatopenapi "github.com/vshn/appcat-apiserver/pkg/openapi"
1413
"sigs.k8s.io/apiserver-runtime/pkg/builder"
1514
)
1615

17-
var apiServerCMDStr = "apiserver"
18-
1916
var APIServerCMD = newAPIServerCMD()
2017

2118
func newAPIServerCMD() *cobra.Command {
2219

23-
viper.AutomaticEnv()
24-
25-
var appcatEnabled, vshnPGBackupsEnabled, vshnRedisBackupsEnabled, vshnMariaDBBackupEnabled bool
26-
27-
if len(os.Args) < 2 {
28-
return &cobra.Command{}
29-
}
30-
31-
if os.Args[1] == apiServerCMDStr {
32-
appcatEnabled = viper.GetBool("APPCAT_HANDLER_ENABLED")
33-
vshnPGBackupsEnabled = viper.GetBool("VSHN_POSTGRES_BACKUP_HANDLER_ENABLED")
34-
vshnRedisBackupsEnabled = viper.GetBool("VSHN_REDIS_BACKUP_HANDLER_ENABLED")
35-
vshnMariaDBBackupEnabled = viper.GetBool("VSHN_MARIADB_BACKUP_HANDLER_ENABLED")
36-
if !appcatEnabled && !vshnPGBackupsEnabled && !vshnRedisBackupsEnabled && !vshnMariaDBBackupEnabled {
37-
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")
38-
}
39-
}
40-
4120
b := builder.APIServer
4221

43-
if appcatEnabled {
44-
b.WithResourceAndHandler(&appcatv1.AppCat{}, appcat.New())
45-
}
22+
b.WithResourceAndHandler(&appcatv1.AppCat{}, appcat.New())
4623

47-
if vshnPGBackupsEnabled {
48-
b.WithResourceAndHandler(&appcatv1.VSHNPostgresBackup{}, vshnpostgres.New())
49-
}
24+
b.WithResourceAndHandler(&appcatv1.VSHNPostgresBackup{}, vshnpostgres.New())
5025

51-
if vshnRedisBackupsEnabled {
52-
b.WithResourceAndHandler(&appcatv1.VSHNRedisBackup{}, vshnredis.New())
53-
}
26+
b.WithResourceAndHandler(&appcatv1.VSHNRedisBackup{}, vshnredis.New())
5427

55-
if vshnMariaDBBackupEnabled {
56-
b.WithResourceAndHandler(&appcatv1.VSHNMariaDBBackup{}, vshnmariadb.New())
57-
}
28+
b.WithResourceAndHandler(&appcatv1.VSHNMariaDBBackup{}, vshnmariadb.New())
5829

5930
b.WithoutEtcd().
6031
ExposeLoopbackAuthorizer().
6132
ExposeLoopbackMasterClientConfig()
6233

34+
b.WithOpenAPIDefinitions("Wardle", "0.1", appcatopenapi.GetOpenAPIDefinitions)
35+
6336
cmd, err := b.Build()
6437
cmd.Use = "apiserver"
6538
cmd.Short = "AppCat API Server"

config/apiserver/aggregated-apiserver.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ spec:
3131
- "--tls-cert-file=/apiserver.local.config/certificates/tls.crt"
3232
- "--tls-private-key-file=/apiserver.local.config/certificates/tls.key"
3333
- "--audit-log-path=-"
34-
- "--feature-gates=APIPriorityAndFairness=false"
34+
- "--enable-priority-and-fairness=false" # k8s 1.29+ only
35+
- "--disable-admission-plugins=ValidatingAdmissionPolicy" # k8s 1.30+ only
3536
- "--audit-log-maxage=0"
3637
- "--audit-log-maxbackup=0"
3738
envFrom:

config/apiserver/apiserver-envs.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)