Skip to content

Commit

Permalink
webhook timeout variable (#1387)
Browse files Browse the repository at this point in the history
* Added webhook timeout variable

* made timeout variable to be private

* Fixed chart version

Co-authored-by: Sairaman Kumar <[email protected]>
  • Loading branch information
sairamankumar2 and Sairaman Kumar authored Nov 14, 2021
1 parent 5a1a32a commit 6939cbd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/spark-operator-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: spark-operator
description: A Helm chart for Spark on Kubernetes operator
version: 1.1.11
version: 1.1.12
appVersion: v1beta2-1.2.3-3.1.1
keywords:
- spark
Expand Down
1 change: 1 addition & 0 deletions charts/spark-operator-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ All charts linted successfully
| webhook.enable | bool | `false` | Enable webhook server |
| webhook.namespaceSelector | string | `""` | The webhook server will only operate on namespaces with this label, specified in the form key1=value1,key2=value2. Empty string (default) will operate on all namespaces |
| webhook.port | int | `8080` | Webhook service port |
| webhook.timeout | int | `30` | Webhook timeout in seconds |

## Maintainers

Expand Down
1 change: 1 addition & 0 deletions charts/spark-operator-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ spec:
- -enable-webhook=true
- -webhook-svc-namespace={{ .Release.Namespace }}
- -webhook-port={{ .Values.webhook.port }}
- -webhook-timeout={{ .Values.webhook.timeout }}
- -webhook-svc-name={{ include "spark-operator.fullname" . }}-webhook
- -webhook-config-name={{ include "spark-operator.fullname" . }}-webhook-config
- -webhook-namespace-selector={{ .Values.webhook.namespaceSelector }}
Expand Down
2 changes: 2 additions & 0 deletions charts/spark-operator-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ webhook:
cleanupAnnotations:
"helm.sh/hook": pre-delete, pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
# -- Webhook Timeout in seconds
timeout: 30

metrics:
# -- Enable prometheus metric scraping
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
namespace = flag.String("namespace", apiv1.NamespaceAll, "The Kubernetes namespace to manage. Will manage custom resource objects of the managed CRD types for the whole cluster if unset.")
labelSelectorFilter = flag.String("label-selector-filter", "", "A comma-separated list of key=value, or key labels to filter resources during watch and list based on the specified labels.")
enableWebhook = flag.Bool("enable-webhook", false, "Whether to enable the mutating admission webhook for admitting and patching Spark pods.")
webhookTimeout = flag.Int("webhook-timeout", 30, "Webhook Timeout in seconds before the webhook returns a timeout")
enableResourceQuotaEnforcement = flag.Bool("enable-resource-quota-enforcement", false, "Whether to enable ResourceQuota enforcement for SparkApplication resources. Requires the webhook to be enabled.")
ingressURLFormat = flag.String("ingress-url-format", "", "Ingress URL format.")
enableUIService = flag.Bool("enable-ui-service", true, "Enable Spark service UI.")
Expand Down Expand Up @@ -195,7 +196,7 @@ func main() {
}
var err error
// Don't deregister webhook on exit if leader election enabled (i.e. multiple webhooks running)
hook, err = webhook.New(kubeClient, crInformerFactory, *namespace, !*enableLeaderElection, *enableResourceQuotaEnforcement, coreV1InformerFactory)
hook, err = webhook.New(kubeClient, crInformerFactory, *namespace, !*enableLeaderElection, *enableResourceQuotaEnforcement, coreV1InformerFactory, webhookTimeout)
if err != nil {
glog.Fatal(err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type WebHook struct {
enableResourceQuotaEnforcement bool
resourceQuotaEnforcer resourceusage.ResourceQuotaEnforcer
coreV1InformerFactory informers.SharedInformerFactory
timeoutSeconds *int32
}

// Configuration parsed from command-line flags
Expand Down Expand Up @@ -124,7 +125,8 @@ func New(
jobNamespace string,
deregisterOnExit bool,
enableResourceQuotaEnforcement bool,
coreV1InformerFactory informers.SharedInformerFactory) (*WebHook, error) {
coreV1InformerFactory informers.SharedInformerFactory,
webhookTimeout *int) (*WebHook, error) {

cert, err := NewCertProvider(
userConfig.serverCert,
Expand Down Expand Up @@ -153,6 +155,7 @@ func New(
failurePolicy: arv1beta1.Ignore,
coreV1InformerFactory: coreV1InformerFactory,
enableResourceQuotaEnforcement: enableResourceQuotaEnforcement,
timeoutSeconds: func(b int32) *int32 { return &b }(int32(*webhookTimeout)),
}

if userConfig.webhookFailOnError {
Expand Down Expand Up @@ -387,6 +390,7 @@ func (wh *WebHook) selfRegistration(webhookConfigName string) error {
},
FailurePolicy: &wh.failurePolicy,
NamespaceSelector: wh.selector,
TimeoutSeconds: wh.timeoutSeconds,
}

validatingWebhook := v1beta1.ValidatingWebhook{
Expand All @@ -398,6 +402,7 @@ func (wh *WebHook) selfRegistration(webhookConfigName string) error {
},
FailurePolicy: &wh.failurePolicy,
NamespaceSelector: wh.selector,
TimeoutSeconds: wh.timeoutSeconds,
}

mutatingWebhooks := []v1beta1.MutatingWebhook{mutatingWebhook}
Expand Down

0 comments on commit 6939cbd

Please sign in to comment.