Skip to content

Commit

Permalink
Reintroduce option webhook.enable (kubeflow#2142)
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Chen <[email protected]>
  • Loading branch information
ChenYi015 authored Aug 24, 2024
1 parent 63bbe4f commit 9e88049
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions charts/spark-operator-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall) for command docum
| controller.sidecars | list | `[]` | Sidecar containers for controller pods. |
| controller.podDisruptionBudget.enable | bool | `false` | Specifies whether to create pod disruption budget for controller. Ref: [Specifying a Disruption Budget for your Application](https://kubernetes.io/docs/tasks/run-application/configure-pdb/) |
| controller.podDisruptionBudget.minAvailable | int | `1` | The number of pods that must be available. Require `controller.replicas` to be greater than 1 |
| webhook.enable | bool | `true` | Specifies whether to enable webhook. |
| webhook.replicas | int | `1` | Number of replicas of webhook server. |
| webhook.logLevel | string | `"info"` | Configure the verbosity of logging, can be one of `debug`, `info`, `error`. |
| webhook.port | int | `9443` | Specifies webhook port. |
Expand Down
2 changes: 2 additions & 0 deletions charts/spark-operator-chart/templates/webhook/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -153,3 +154,4 @@ spec:
- {{ mergeOverwrite . $labelSelectorDict | toYaml | nindent 8 | trim }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
Expand Down Expand Up @@ -114,3 +115,4 @@ webhooks:
{{- with .Values.webhook.timeoutSeconds }}
timeoutSeconds: {{ . }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
{{- if .Values.webhook.podDisruptionBudget.enable }}
{{- if le (int .Values.webhook.replicas) 1 }}
{{- fail "webhook.replicas must be greater than 1 to enable pod disruption budget for webhook" }}
Expand All @@ -32,3 +33,4 @@ spec:
minAvailable: {{ . }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/spark-operator-chart/templates/webhook/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
{{- if .Values.webhook.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -169,3 +170,4 @@ roleRef:
kind: Role
name: {{ include "spark-operator.webhook.name" . }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions charts/spark-operator-chart/templates/webhook/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -27,3 +28,4 @@ spec:
- port: {{ .Values.webhook.port }}
targetPort: {{ .Values.webhook.portName | quote }}
name: {{ .Values.webhook.portName }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
{{- if .Values.webhook.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
Expand All @@ -26,3 +27,4 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.webhook.enable }}
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
Expand Down Expand Up @@ -81,3 +82,4 @@ webhooks:
{{- with .Values.webhook.timeoutSeconds }}
timeoutSeconds: {{ . }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ tests:
kind: Deployment
name: spark-operator-webhook

- it: Should not create webhook deployment if `webhook.enable` is `false`
set:
webhook:
enable: false
asserts:
- hasDocuments:
count: 0

- it: Should set replicas if `webhook.replicas` is set
set:
webhook:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ tests:
kind: MutatingWebhookConfiguration
name: spark-operator-webhook

- it: Should not create the mutating webhook configuration if `webhook.enable` is `false`
set:
webhook:
enable: false
asserts:
- hasDocuments:
count: 0

- it: Should use the specified webhook port
set:
webhook:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ release:
namespace: spark-operator

tests:
- it: Should not render podDisruptionBudget if `webhook.enable` is `false`
set:
webhook:
enable: false
asserts:
- hasDocuments:
count: 0

- it: Should not render podDisruptionBudget if `webhook.podDisruptionBudget.enable` is false
set:
webhook:
Expand All @@ -40,7 +48,7 @@ tests:
podDisruptionBudget:
enable: true
asserts:
- failedTemplate:
- failedTemplate:
errorMessage: "webhook.replicas must be greater than 1 to enable pod disruption budget for webhook"

- it: Should render spark operator podDisruptionBudget if `webhook.podDisruptionBudget.enable` is true
Expand Down
8 changes: 8 additions & 0 deletions charts/spark-operator-chart/tests/webhook/service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ release:
namespace: spark-operator

tests:
- it: Should not create webhook service if `webhook.enable` is `false`
set:
webhook:
enable: false
asserts:
- hasDocuments:
count: 0

- it: Should create the webhook service correctly
set:
webhook:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ tests:
kind: ValidatingWebhookConfiguration
name: spark-operator-webhook

- it: Should not create the validating webhook configuration if `webhook.enable` is `false`
set:
webhook:
enable: false
asserts:
- hasDocuments:
count: 0

- it: Should use the specified webhook port
set:
webhook:
Expand Down
3 changes: 3 additions & 0 deletions charts/spark-operator-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ controller:
minAvailable: 1

webhook:
# -- Specifies whether to enable webhook.
enable: true

# -- Number of replicas of webhook server.
replicas: 1

Expand Down

0 comments on commit 9e88049

Please sign in to comment.