Skip to content

Commit

Permalink
Add validator for autoscaler (#777)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <arnob@appscode.com>
Signed-off-by: Tamal Saha <tamal@appscode.com>
Co-authored-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
ArnobKumarSaha and tamalsaha committed Jan 10, 2024
1 parent 805c258 commit 04b2def
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 7 deletions.
8 changes: 4 additions & 4 deletions catalog/kubedb/fmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func main() {
}

dbStore := map[DbVersion][]*unstructured.Unstructured{}
pspForDBs := map[DB]sets.String{}
pspForDBs := map[DB]sets.Set[string]{}
pspStore := map[string]*unstructured.Unstructured{}

// active versions
Expand Down Expand Up @@ -256,7 +256,7 @@ func main() {
Kind: ri.Object.GetKind(),
}
if _, ok := pspForDBs[dbKey]; !ok {
pspForDBs[dbKey] = sets.NewString()
pspForDBs[dbKey] = sets.New[string]()
}
pspForDBs[dbKey].Insert(pspName)
}
Expand Down Expand Up @@ -444,7 +444,7 @@ func main() {
}

var buf bytes.Buffer
for i, pspName := range v.List() {
for i, pspName := range sets.List[string](v) {
if i > 0 {
buf.WriteString("\n---\n")
}
Expand Down Expand Up @@ -600,7 +600,7 @@ func main() {
dbKind := strings.TrimSuffix(k.Kind, "Version")

var buf bytes.Buffer
for i, pspName := range v.List() {
for i, pspName := range sets.List[string](v) {
if i > 0 {
buf.WriteString("\n---\n")
}
Expand Down
20 changes: 20 additions & 0 deletions charts/kubedb-webhook-server/templates/apiregistration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ spec:
caBundle: {{ $caCrt }}
groupPriorityMinimum: {{ .Values.apiserver.groupPriorityMinimum }}
versionPriority: {{ .Values.apiserver.versionPriority }}
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1alpha1.validators.autoscaling.kubedb.com
labels:
app.kubernetes.io/component: kubedb-autoscaler
{{- include "kubedb-webhook-server.labels" . | nindent 4 }}
spec:
group: validators.autoscaling.kubedb.com
version: v1alpha1
service:
namespace: {{ .Release.Namespace }}
name: {{ include "kubedb-webhook-server.fullname" . }}
caBundle: {{ $caCrt }}
groupPriorityMinimum: {{ .Values.apiserver.groupPriorityMinimum }}
versionPriority: {{ .Values.apiserver.versionPriority }}
{{- end }}
{{- if list "kubedb-webhook-server" "kubedb-dashboard" | has .Values.server.repository }}
---
{{- end }}
{{- if list "kubedb-webhook-server" "kubedb-dashboard" | has .Values.server.repository }}
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{{ $featureGates := .Values.featureGates }}
{{- if .Values.global }}
{{ $featureGates = mergeOverwrite dict .Values.featureGates .Values.global.featureGates }}
{{- end }}

{{- if .Values.apiserver.enableMutatingWebhook }}
{{- if list "kubedb-webhook-server" "kubedb-autoscaler" | has .Values.server.repository }}

{{- $caCrt := dig "data" "ca.crt" "unknown" (lookup "v1" "ConfigMap" .Release.Namespace "kube-root-ca.crt") | b64enc }}

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validators.autoscaling.kubedb.com
labels:
app.kubernetes.io/component: kubedb-autoscaler
{{- include "kubedb-webhook-server.labels" . | nindent 4 }}
webhooks:
{{- if $featureGates.MongoDB }}
- name: mongodbautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/mongodbautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["mongodbautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.Elasticsearch }}
- name: elasticsearchautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/elasticsearchautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["elasticsearchautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.MariaDB }}
- name: mariadbautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/mariadbautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["mariadbautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.MySQL }}
- name: mysqlautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/mysqlautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["mysqlautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.PerconaXtraDB }}
- name: perconaxtradbautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/perconaxtradbautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["perconaxtradbautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.Postgres }}
- name: postgresautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/postgresautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["postgresautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.PgBouncer }}
- name: pgbouncerautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/pgbouncerautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["pgbouncerautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.ProxySQL }}
- name: proxysqlautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/proxysqlautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["proxysqlautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- if $featureGates.Redis }}
- name: redisautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/redisautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["redisautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
- name: redissentinelautoscalerwebhook.validators.autoscaling.kubedb.com
clientConfig:
service:
namespace: default
name: kubernetes
path: /apis/validators.autoscaling.kubedb.com/v1alpha1/redissentinelautoscalerwebhooks
caBundle: {{ $caCrt }}
rules:
- apiGroups: ["autoscaling.kubedb.com"]
apiVersions: ["*"]
resources: ["redissentinelautoscalers"]
operations: ["CREATE", "UPDATE"]
admissionReviewVersions: ["v1beta1"]
failurePolicy: {{ .Values.apiserver.webhook.failurePolicy }}
sideEffects: None
{{- end }}
{{- end }}
{{- end }}

6 changes: 3 additions & 3 deletions tests/check-charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func checkImages() error {
sh.SetDir(dir)
sh.ShowCMD = true

images := sets.NewString()
images := sets.New[string]()
for _, entry := range entries {
if !entry.IsDir() {
continue
Expand All @@ -77,7 +77,7 @@ func checkImages() error {
}

var missing []string
for _, img := range images.List() {
for _, img := range sets.List[string](images) {
if strings.Contains(img, "${") {
continue
}
Expand All @@ -96,7 +96,7 @@ func checkImages() error {
return nil
}

func collectImages(obj map[string]any, images sets.String) {
func collectImages(obj map[string]any, images sets.Set[string]) {
for k, v := range obj {
if k == "image" {
if s, ok := v.(string); ok {
Expand Down

0 comments on commit 04b2def

Please sign in to comment.