rename the variable for resource validation webhook (#653)

This commit is contained in:
Nima Kaviani 2019-09-11 15:40:29 +02:00 committed by Knative Prow Robot
parent 7b67118970
commit c39ee25c42
4 changed files with 13 additions and 13 deletions

View File

@ -141,10 +141,10 @@ func (ac *ResourceAdmissionController) Register(ctx context.Context, kubeClient
webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{ webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: ac.options.WebhookName, Name: ac.options.ResourceMutatingWebhookName,
}, },
Webhooks: []admissionregistrationv1beta1.Webhook{{ Webhooks: []admissionregistrationv1beta1.Webhook{{
Name: ac.options.WebhookName, Name: ac.options.ResourceMutatingWebhookName,
Rules: rules, Rules: rules,
ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{ ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{
Service: &admissionregistrationv1beta1.ServiceReference{ Service: &admissionregistrationv1beta1.ServiceReference{
@ -173,7 +173,7 @@ func (ac *ResourceAdmissionController) Register(ctx context.Context, kubeClient
return fmt.Errorf("failed to create a webhook: %v", err) return fmt.Errorf("failed to create a webhook: %v", err)
} }
logger.Info("Webhook already exists") logger.Info("Webhook already exists")
configuredWebhook, err := client.Get(ac.options.WebhookName, metav1.GetOptions{}) configuredWebhook, err := client.Get(ac.options.ResourceMutatingWebhookName, metav1.GetOptions{})
if err != nil { if err != nil {
return fmt.Errorf("error retrieving webhook: %v", err) return fmt.Errorf("error retrieving webhook: %v", err)
} }

View File

@ -537,10 +537,10 @@ func TestUpdatingWebhook(t *testing.T) {
ac := c.(*ResourceAdmissionController) ac := c.(*ResourceAdmissionController)
webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{ webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: ac.options.WebhookName, Name: ac.options.ResourceMutatingWebhookName,
}, },
Webhooks: []admissionregistrationv1beta1.Webhook{{ Webhooks: []admissionregistrationv1beta1.Webhook{{
Name: ac.options.WebhookName, Name: ac.options.ResourceMutatingWebhookName,
Rules: []admissionregistrationv1beta1.RuleWithOperations{{}}, Rules: []admissionregistrationv1beta1.RuleWithOperations{{}},
ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{}, ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{},
}}, }},
@ -553,7 +553,7 @@ func TestUpdatingWebhook(t *testing.T) {
t.Fatalf("Failed to create webhook: %s", err) t.Fatalf("Failed to create webhook: %s", err)
} }
currentWebhook, _ := kubeClient.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Get(ac.options.WebhookName, metav1.GetOptions{}) currentWebhook, _ := kubeClient.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Get(ac.options.ResourceMutatingWebhookName, metav1.GetOptions{})
if reflect.DeepEqual(currentWebhook.Webhooks, webhook.Webhooks) { if reflect.DeepEqual(currentWebhook.Webhooks, webhook.Webhooks) {
t.Fatalf("Expected webhook to be updated") t.Fatalf("Expected webhook to be updated")
} }

View File

@ -52,9 +52,9 @@ var (
// ControllerOptions contains the configuration for the webhook // ControllerOptions contains the configuration for the webhook
type ControllerOptions struct { type ControllerOptions struct {
// WebhookName is the name of the webhook we create to handle // ResourceMutatingWebhookName is the name of the webhook we create to handle
// mutations before they get stored in the storage. // mutations before they get stored in the storage.
WebhookName string ResourceMutatingWebhookName string
// ServiceName is the service name of the webhook. // ServiceName is the service name of the webhook.
ServiceName string ServiceName string

View File

@ -42,7 +42,7 @@ func newDefaultOptions() ControllerOptions {
ServiceName: "webhook", ServiceName: "webhook",
Port: 443, Port: 443,
SecretName: "webhook-certs", SecretName: "webhook-certs",
WebhookName: "webhook.knative.dev", ResourceMutatingWebhookName: "webhook.knative.dev",
ResourceAdmissionControllerPath: "/", ResourceAdmissionControllerPath: "/",
} }
} }
@ -73,11 +73,11 @@ func TestRegistrationStopChanFire(t *testing.T) {
kubeClient, ac := newNonRunningTestWebhook(t, opts) kubeClient, ac := newNonRunningTestWebhook(t, opts)
webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{ webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: ac.Options.WebhookName, Name: ac.Options.ResourceMutatingWebhookName,
}, },
Webhooks: []admissionregistrationv1beta1.Webhook{ Webhooks: []admissionregistrationv1beta1.Webhook{
{ {
Name: ac.Options.WebhookName, Name: ac.Options.ResourceMutatingWebhookName,
Rules: []admissionregistrationv1beta1.RuleWithOperations{{}}, Rules: []admissionregistrationv1beta1.RuleWithOperations{{}},
ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{}, ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{},
}, },
@ -108,11 +108,11 @@ func TestRegistrationForAlreadyExistingWebhook(t *testing.T) {
kubeClient, ac := newNonRunningTestWebhook(t, newDefaultOptions()) kubeClient, ac := newNonRunningTestWebhook(t, newDefaultOptions())
webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{ webhook := &admissionregistrationv1beta1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: ac.Options.WebhookName, Name: ac.Options.ResourceMutatingWebhookName,
}, },
Webhooks: []admissionregistrationv1beta1.Webhook{ Webhooks: []admissionregistrationv1beta1.Webhook{
{ {
Name: ac.Options.WebhookName, Name: ac.Options.ResourceMutatingWebhookName,
Rules: []admissionregistrationv1beta1.RuleWithOperations{{}}, Rules: []admissionregistrationv1beta1.RuleWithOperations{{}},
ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{}, ClientConfig: admissionregistrationv1beta1.WebhookClientConfig{},
}, },