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

Using admission server in e2e test instead of applying webhook.yaml #1377

Merged
merged 19 commits into from
Dec 20, 2019

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Dec 19, 2019

What problem does this PR solve?

  1. Using the admission webhook server in e2e instead of applying manifests/webhook.yaml.

  2. fix some admission webhook template bugs and add update statefulset webhook configuration in admission webhook template.

  3. Upgrading Operator from disable webhook to enable webhook wouldn't restart tidb-controller-manager until we add webhook switch in it.

  4. moving statefulset webhook configuration into admission webhook template and add a switch for each hook.

What is changed?

  • go code
  • chart template
  • e2e test

@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 19, 2019

/run-e2e-in-kind

@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 19, 2019

/run-e2e-in-kind

@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 19, 2019

/run-e2e-in-kind

@Yisaer Yisaer added area/webhook Related to webhook test/e2e e2e test labels Dec 19, 2019
@Yisaer Yisaer changed the title [WIP] Use admission server in e2e Using admission server in e2e test instead of applying webhook.yaml Dec 19, 2019
tests/webhook.go Outdated
}
klog.Infof("success to execute helm operator upgrade")

//// ensure pods unchanged when upgrading operator
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, Upgrade Operator from disable webhook to enable webhook would only create a new deployment admission webhook. After we add webhook-enabled switch in tidb-controller-manager, it would be necessary to check whether upgrading Operator would cause tidbcluster restarted as tidb-controller-manager would restart.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should the check be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, upgrading Operator from disable admission to enable admission won't restart the tidb-controller-manager so it is not necessary to check the tidbcluster.

After we add admission-webhook switch in tidb-controller-manager, the checking would be necessary.

@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 19, 2019

/run-e2e-in-kind

@Yisaer Yisaer closed this Dec 19, 2019
@Yisaer Yisaer reopened this Dec 19, 2019
@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 20, 2019

/run-e2e-in-kind

tests/webhook.go Outdated
cmd := fmt.Sprintf(`helm upgrade %s %s --set-string %s `,
info.ReleaseName,
oa.operatorChartPath(info.Tag),
setString)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add webhook settings in OperatorCfg and use UpgradeOperator?

Copy link
Contributor

@cofyc cofyc Dec 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to configure caBundle via --set-string? if it is, we can configure caBundle in OperatorConfig and update OperatorConfig.OperatorHelmSetString to use it if it exists, e.g.

  • configure webhook configurations in OperatorConfig
  • (if < 1.13) get caBundle from kube-system.extension-apiserver-authentication
  • (if < 1.13) configure caBundle in OperatorConfig
  • UpgradeOperator(OperatorConfig)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Copy link
Contributor Author

@Yisaer Yisaer Dec 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set cabundle by --set-string at first and encounter a multi-line problem as the cabundle content is multi-line. I used -f to avoid this problem.

Now, I add these webhook enable switch into OperatorConfig and UpgradeOperator would call SwitchAdmissionWebhook to update the admission webhook .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can fix the multi-line problem by escaping the value of the --set-string flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code is fragile because it does not escape the shell arguments. another way is pass command and its arguments to exec.Command (don't use sh, then no need to escape shell arguments).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, for now, the switch of each hook and admission server and the cabundle if managed by OperatorConfig.

statefulSets: false
## pods hook would check requests for creating and deleting tidbcluster's pods
## if enabled it, the pods of tidbcluster would safely created or deleted by webhook instead of controller
pods: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we will always deploy webhook eventually because many features must be implemented in webhook (defaulting & validating, etc). Maybe we can have only one gate hooksEnabled?

cc @aylei

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with these fine-grained control, but I think the default value is better to be true. The UX I expect is that when I enable webhook by setting admission.create=true, I get all the admissions out-of-box, and could disable some of them based on my customized requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, the podsWebhook is true in default while the stsWebhook is false as stsWebhook is a special feature.

@@ -1,4 +1,4 @@
{{- if eq .Values.admissionWebhook.create true }}
{{- if .Values.admissionWebhook.create }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we have to change the criteria

Copy link
Contributor Author

@Yisaer Yisaer Dec 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cause {{- if eq .Values.admissionWebhook.create true }} didn't work well when I configure the setting by helm upgrade <name> <path> --set-string key=value which would casue a comparing type error, so I use {{- if .Values.admissionWebhook.create }} to avoid it.

By the way, {{- if .Values.key.create }} is more common used in our templates. It is better to unify the compare style.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is should be our helm BP

statefulSets: false
## pods hook would check requests for creating and deleting tidbcluster's pods
## if enabled it, the pods of tidbcluster would safely created or deleted by webhook instead of controller
pods: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with these fine-grained control, but I think the default value is better to be true. The UX I expect is that when I enable webhook by setting admission.create=true, I get all the admissions out-of-box, and could disable some of them based on my customized requirement.

tests/webhook.go Outdated Show resolved Hide resolved
tests/webhook.go Outdated
}
}

klog.Info(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

@Yisaer Yisaer Dec 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log helps to print the command we would execute, so it didn't need any extra info except itself.

tests/webhook.go Outdated Show resolved Hide resolved
tests/webhook.go Outdated
}
klog.Infof("success to execute helm operator upgrade")

//// ensure pods unchanged when upgrading operator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should the check be commented out?

tests/webhook.go Outdated Show resolved Hide resolved
@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 20, 2019

/run-e2e-in-test

@Yisaer Yisaer requested review from cofyc and aylei December 20, 2019 04:03
@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 20, 2019

/run-e2e-test

@Yisaer

This comment has been minimized.

@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 20, 2019

/run-e2e-in-kind

@Yisaer Yisaer added the status/PTAL PR needs to be reviewed label Dec 20, 2019
Copy link
Contributor

@cofyc cofyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@aylei aylei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1,4 +1,4 @@
{{- if eq .Values.admissionWebhook.create true }}
{{- if .Values.admissionWebhook.create }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is should be our helm BP

@Yisaer
Copy link
Contributor Author

Yisaer commented Dec 20, 2019

/run-e2e-in-kind

@Yisaer Yisaer merged commit f046d12 into pingcap:master Dec 20, 2019
yahonda pushed a commit that referenced this pull request Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/webhook Related to webhook status/PTAL PR needs to be reviewed test/e2e e2e test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants