Skip to content

Commit

Permalink
Use common feature gates across charts
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Jan 7, 2024
1 parent 4856a14 commit 21d11ae
Show file tree
Hide file tree
Showing 299 changed files with 4,011 additions and 992 deletions.
29 changes: 1 addition & 28 deletions apis/installer/v1alpha1/kubedb_catalog_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type KubedbCatalogSpec struct {
FullnameOverride string `json:"fullnameOverride"`
//+optional
Proxies RegistryProxies `json:"proxies"`
Catalog Catalog `json:"catalog"`
FeatureGates map[string]bool `json:"featureGates"`
Psp PSP `json:"psp"`
SkipDeprecated bool `json:"skipDeprecated"`
}
Expand All @@ -69,33 +69,6 @@ type RegistryProxies struct {
AppsCode string `json:"appscode"`
}

type Catalog struct {
//+optional
Elasticsearch bool `json:"elasticsearch"`
//+optional
Etcd bool `json:"etcd"`
//+optional
Memcached bool `json:"memcached"`
//+optional
MongoDB bool `json:"mongodb"`
//+optional
Mysql bool `json:"mysql"`
//+optional
MariaDB bool `json:"mariadb"`
//+optional
Perconaxtradb bool `json:"perconaxtradb"`
//+optional
Pgbouncer bool `json:"pgbouncer"`
//+optional
Postgres bool `json:"postgres"`
//+optional
Proxysql bool `json:"proxysql"`
//+optional
Redis bool `json:"redis"`
//+optional
Kafka bool `json:"kafka"`
}

type PSP struct {
Enabled bool `json:"enabled"`
//+optional
Expand Down
7 changes: 1 addition & 6 deletions apis/installer/v1alpha1/kubedb_kubestash_catalog_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type KubedbKubestashCatalog struct {
type KubedbKubestashCatalogSpec struct {
//+optional
Proxies RegistryProxies `json:"proxies"`
FeatureGates map[string]bool `json:"featureGates"`
WaitTimeout int64 `json:"waitTimeout"`
Elasticsearch StashElasticsearchSpec `json:"elasticsearch"`
Opensearch StashOpensearchSpec `json:"opensearch"`
Expand All @@ -57,7 +58,6 @@ type KubedbKubestashCatalogSpec struct {

// StashElasticsearchSpec is the schema for Stash Elasticsearch values file
type StashElasticsearchSpec struct {
Enabled bool `json:"enabled"`
Backup ElasticsearchBackup `json:"backup"`
Restore ElasticsearchRestore `json:"restore"`
}
Expand All @@ -74,7 +74,6 @@ type ElasticsearchRestore struct {

// StashOpensearchSpec is the schema for Stash Opensearch values file
type StashOpensearchSpec struct {
Enabled bool `json:"enabled"`
Backup OpensearchBackup `json:"backup"`
Restore OpensearchRestore `json:"restore"`
}
Expand Down Expand Up @@ -106,7 +105,6 @@ type KubeDumpBackup struct {

// StashMongodbSpec is the schema for Stash MongoDB values file
type StashMongodbSpec struct {
Enabled bool `json:"enabled"`
MaxConcurrency int32 `json:"maxConcurrency"`
Backup MongoDBBackup `json:"backup"`
Restore MongoDBRestore `json:"restore"`
Expand All @@ -124,7 +122,6 @@ type MongoDBRestore struct {

// StashMysqlSpec is the schema for Stash MySQL values file
type StashMysqlSpec struct {
Enabled bool `json:"enabled"`
Backup MySQLBackup `json:"backup"`
Restore MySQLRestore `json:"restore"`
}
Expand All @@ -141,7 +138,6 @@ type MySQLRestore struct {

// StashRedisSpec is the schema for Stash Redis values file
type StashRedisSpec struct {
Enabled bool `json:"enabled"`
Backup RedisBackup `json:"backup"`
Restore RedisRestore `json:"restore"`
}
Expand All @@ -158,7 +154,6 @@ type RedisRestore struct {

// StashPostgresSpec is the schema for Stash Postgres values file
type StashPostgresSpec struct {
Enabled bool `json:"enabled"`
Backup PostgresBackup `json:"backup"`
Restore PostgresRestore `json:"restore"`
}
Expand Down
9 changes: 9 additions & 0 deletions apis/installer/v1alpha1/kubedb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Kubedb struct {
type KubedbSpec struct {
Global GlobalValues `json:"global"`

//+optional
KubedbCrdManager KubedbCrdManagerValues `json:"kubedb-crd-manager"`

//+optional
KubedbProvisioner KubedbProvisionerValues `json:"kubedb-provisioner"`

Expand Down Expand Up @@ -71,6 +74,11 @@ type KubedbSpec struct {
KubedbMetrics KubedbMetricsValues `json:"kubedb-metrics"`
}

type KubedbCrdManagerValues struct {
Enabled *bool `json:"enabled"`
*KubedbCrdManagerSpec `json:",inline,omitempty"`
}

type KubedbProvisionerValues struct {
Enabled *bool `json:"enabled"`
*KubedbProvisionerSpec `json:",inline,omitempty"`
Expand Down Expand Up @@ -123,6 +131,7 @@ type GlobalValues struct {
InsecureRegistries []string `json:"insecureRegistries"`
//+optional
ImagePullSecrets []core.LocalObjectReference `json:"imagePullSecrets"`
FeatureGates map[string]bool `json:"featureGates"`
Monitoring EASMonitoring `json:"monitoring"`
}

Expand Down
73 changes: 52 additions & 21 deletions apis/installer/v1alpha1/zz_generated.deepcopy.go

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

55 changes: 35 additions & 20 deletions catalog/kubedb/fmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ func main() {
{
for k, v := range dbStore {
dbKind := strings.TrimSuffix(k.Kind, "Version")
var buf bytes.Buffer

for i, obj := range v {
copies := make([]map[string]any, 0, len(v))
for _, obj := range v {
objCopy := obj.DeepCopy()

spec, _, err := unstructured.NestedMap(objCopy.Object, "spec")
Expand Down Expand Up @@ -538,23 +538,38 @@ func main() {
templatizeRegistry("yqImage")
templatizeRegistry("walg", "image")
}

if i > 0 {
buf.WriteString("\n---\n")
}

data := map[string]interface{}{
"key": strings.ToLower(dbKind),
"object": objCopy.Object,
}
funcMap := sprig.TxtFuncMap()
funcMap["toYaml"] = toYAML
funcMap["toJson"] = toJSON
tpl := template.Must(template.New("").Funcs(funcMap).Parse(templates.DBVersion))
err = tpl.Execute(&buf, &data)
if err != nil {
panic(err)
}
copies = append(copies, objCopy.UnstructuredContent())

//if i > 0 {
// buf.WriteString("\n---\n")
//}

//data := map[string]interface{}{
// "kind": dbKind,
// "object": objCopy.Object,
//}
//funcMap := sprig.TxtFuncMap()
//funcMap["toYaml"] = toYAML
//funcMap["toJson"] = toJSON
//tpl := template.Must(template.New("").Funcs(funcMap).Parse(templates.DBVersion))
//err = tpl.Execute(&buf, &data)
//if err != nil {
// panic(err)
//}
}

data := map[string]interface{}{
"kind": dbKind,
"objects": copies,
}
funcMap := sprig.TxtFuncMap()
funcMap["toYaml"] = toYAML
funcMap["toJson"] = toJSON
tpl := template.Must(template.New("").Funcs(funcMap).Parse(templates.DBVersion))
var buf bytes.Buffer
err = tpl.Execute(&buf, &data)
if err != nil {
panic(err)
}

var filenameparts []string
Expand Down Expand Up @@ -598,7 +613,7 @@ func main() {
unstructured.RemoveNestedField(content, "spec", "allowPrivilegeEscalation")
unstructured.RemoveNestedField(content, "spec", "privileged")
data := map[string]interface{}{
"key": strings.ToLower(dbKind),
"kind": dbKind,
"object": content,
}
funcMap := sprig.TxtFuncMap()
Expand Down
28 changes: 20 additions & 8 deletions catalog/kubedb/fmt/templates/dbver.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{{ if .object.spec.deprecated }}
{{- "{{ if and .Values.catalog."}}{{ .key }}{{" (not .Values.skipDeprecated) }}" -}}
{{ else }}
{{- "{{ if .Values.catalog."}}{{ .key }}{{" }}" -}}
{{ "{{ $featureGates := .Values.featureGates }}" }}
{{ "{{- if .Values.global }}" }}
{{ " {{ $featureGates = mergeOverwrite dict .Values.featureGates .Values.global.featureGates }}" }}
{{ "{{- end }}" }}

{{ "{{ if $featureGates."}}{{ .kind }}{{" }}" }}
{{- range $idx, $object := .objects }}
{{ if gt $idx 0 }}
---
{{ end }}
apiVersion: {{ .object.apiVersion }}
kind: {{ .object.kind }}
{{- if $object.spec.deprecated }}
{{- "{{ if not .Values.skipDeprecated }}" -}}
{{- end }}
apiVersion: {{ $object.apiVersion }}
kind: {{ $object.kind }}
metadata:
name: '{{ .object.metadata.name }}'
name: '{{ $object.metadata.name }}'
labels:
{{"{{- include \"kubedb-catalog.labels\" . | nindent 4 }}"}}
spec:
{{- .object.spec | toYaml | nindent 2 }}
{{- $object.spec | toYaml | nindent 2 }}
{{- if $object.spec.deprecated }}
{{ "{{ end }}" }}
{{- end -}}
{{- end }}
{{"{{ end }}"}}
Loading

0 comments on commit 21d11ae

Please sign in to comment.