Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(webhook): make webhook config failure policy configurable #1726

Merged
merged 2 commits into from
Jul 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions pkg/webhook/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/klog"
)

const (
Expand Down Expand Up @@ -70,7 +71,9 @@ var (
Ignore = v1beta1.Ignore
// Fail means that an error calling the webhook causes the admission to fail.
Fail = v1beta1.Fail

// WebhookFailurePolicye represents failure policy env name to make it configurable
// via ENV
WebhookFailurePolicy = "ADMISSION_WEBHOOK_FAILURE_POLICY"
// transformation function lists to upgrade webhook resources
transformSecret = []transformSecretFunc{}
transformSvc = []transformSvcFunc{}
Expand Down Expand Up @@ -221,7 +224,7 @@ func createValidatingWebhookConfig(
CABundle: signingCert,
},
TimeoutSeconds: &five,
FailurePolicy: &Fail,
FailurePolicy: failurePolicy(),
}

validator := &v1beta1.ValidatingWebhookConfiguration{
Expand Down Expand Up @@ -635,7 +638,7 @@ func preUpgrade(openebsNamespace string) error {
for _, config := range webhookConfigList.Items {
if config.Labels[string(apis.OpenEBSVersionKey)] != version.Current() {
if config.Labels[string(apis.OpenEBSVersionKey)] == "" ||
util.IsCurrentLessThanNewVersion(config.Labels[string(apis.OpenEBSVersionKey)], "1.10.0") {
util.IsCurrentLessThanNewVersion(config.Labels[string(apis.OpenEBSVersionKey)], "1.12.0") {
kmova marked this conversation as resolved.
Show resolved Hide resolved
err = validate.KubeClient().Delete(config.Name, &metav1.DeleteOptions{})
if err != nil {
return fmt.Errorf("failed to delete older webhook config %s: %s", config.Name, err.Error())
Expand All @@ -656,3 +659,25 @@ func preUpgrade(openebsNamespace string) error {

return nil
}

// failurePolicy returns the admission webhook configuration failurePolicy
// based on the given WebhookFailurePolicy ENV set on admission server
// deployments.
//
// Default failure Policy is `Fail` if not provided.
func failurePolicy() *v1beta1.FailurePolicyType {
var policyType *v1beta1.FailurePolicyType
policy, present := os.LookupEnv(WebhookFailurePolicy)
if !present {
policyType = &Fail
}

switch strings.ToLower(policy) {
default:
policyType = &Fail
case "no", "false", "ignore":
policyType = &Ignore
}
klog.Infof("Using webhook configuration failure policy as %q", *policyType)
return policyType
}