// Copyright (c) 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0

// Code generated by lingon. EDIT AS MUCH AS YOU LIKE.

package certmanager

import (
	ku "github.com/golingon/lingon/pkg/kubeutil"
	"github.com/golingon/lingoneks/meta"
	admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var WebhookMutatingWC = &admissionregistrationv1.MutatingWebhookConfiguration{
	TypeMeta: ku.TypeMutatingWebhookConfigurationV1,
	ObjectMeta: meta.SetAnnotations(
		CM.Webhook.ObjectMeta(), map[string]string{
			"cert-manager.io/inject-ca-from-secret": "cert-manager/cert-manager-webhook-ca",
		},
	),
	// ObjectMeta: metav1.ObjectMeta{
	// 	Annotations: map[string]string{"cert-manager.io/inject-ca-from-secret": "cert-manager/cert-manager-webhook-ca"},
	// 	Labels: map[string]string{
	// 		"app":                          "webhook",
	// 		"app.kubernetes.io/component":  "webhook",
	// 		"app.kubernetes.io/instance":   "cert-manager",
	// 		"app.kubernetes.io/managed-by": "Helm",
	// 		"app.kubernetes.io/name":       "webhook",
	// 		"app.kubernetes.io/version":    "v1.12.2",
	// 		"helm.sh/chart":                "cert-manager-v1.12.2",
	// 	},
	// 	Name: "cert-manager-webhook",
	// },
	Webhooks: []admissionregistrationv1.MutatingWebhook{
		{
			AdmissionReviewVersions: []string{"v1"},
			ClientConfig: admissionregistrationv1.WebhookClientConfig{
				Service: &admissionregistrationv1.ServiceReference{
					Name:      "cert-manager-webhook",
					Namespace: "cert-manager",
					Path:      P("/mutate"),
				},
			},
			FailurePolicy: P(admissionregistrationv1.Fail),
			MatchPolicy:   P(admissionregistrationv1.Equivalent),
			Name:          "webhook.cert-manager.io",
			Rules: []admissionregistrationv1.RuleWithOperations{
				{
					Operations: []admissionregistrationv1.OperationType{
						admissionregistrationv1.Create,
						admissionregistrationv1.Update,
					},
					Rule: admissionregistrationv1.Rule{
						APIGroups: []string{
							"cert-manager.io",
							"acme.cert-manager.io",
						},
						APIVersions: []string{"v1"},
						Resources:   []string{"*/*"},
					},
				},
			},
			SideEffects:    P(admissionregistrationv1.SideEffectClassNone),
			TimeoutSeconds: P(int32(10)),
		},
	},
}

var WebhookValidatingWC = &admissionregistrationv1.ValidatingWebhookConfiguration{
	TypeMeta: ku.TypeValidatingWebhookConfigurationV1,
	ObjectMeta: meta.SetAnnotations(
		CM.Webhook.ObjectMeta(), map[string]string{
			"cert-manager.io/inject-ca-from-secret": "cert-manager/cert-manager-webhook-ca",
		},
	),
	// ObjectMeta: metav1.ObjectMeta{
	// 	Labels: map[string]string{
	// 		"app":                          "webhook",
	// 		"app.kubernetes.io/component":  "webhook",
	// 		"app.kubernetes.io/instance":   "cert-manager",
	// 		"app.kubernetes.io/managed-by": "Helm",
	// 		"app.kubernetes.io/name":       "webhook",
	// 		"app.kubernetes.io/version":    "v1.12.2",
	// 		"helm.sh/chart":                "cert-manager-v1.12.2",
	// 	},
	// 	Name: "cert-manager-webhook",
	// },
	Webhooks: []admissionregistrationv1.ValidatingWebhook{
		{
			AdmissionReviewVersions: []string{"v1"},
			ClientConfig: admissionregistrationv1.WebhookClientConfig{
				Service: &admissionregistrationv1.ServiceReference{
					Name:      "cert-manager-webhook",
					Namespace: "cert-manager",
					Path:      P("/validate"),
				},
			},
			FailurePolicy: P(admissionregistrationv1.Fail),
			MatchPolicy:   P(admissionregistrationv1.Equivalent),
			Name:          "webhook.cert-manager.io",
			NamespaceSelector: &metav1.LabelSelector{
				MatchExpressions: []metav1.LabelSelectorRequirement{
					{
						Key:      "cert-manager.io/disable-validation",
						Operator: metav1.LabelSelectorOpNotIn,
						Values:   []string{"true"},
					}, {
						Key:      "name",
						Operator: metav1.LabelSelectorOpNotIn,
						Values:   []string{"cert-manager"},
					},
				},
			},
			Rules: []admissionregistrationv1.RuleWithOperations{
				{
					Operations: []admissionregistrationv1.OperationType{
						admissionregistrationv1.Create,
						admissionregistrationv1.Update,
					},
					Rule: admissionregistrationv1.Rule{
						APIGroups: []string{
							"cert-manager.io",
							"acme.cert-manager.io",
						},
						APIVersions: []string{"v1"},
						Resources:   []string{"*/*"},
					},
				},
			},
			SideEffects:    P(admissionregistrationv1.SideEffectClassNone),
			TimeoutSeconds: P(int32(10)),
		},
	},
}
