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

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

package externalsecrets

import (
	"github.com/golingon/lingon/pkg/kubeutil"
	admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/intstr"
)

var WebhookSVC = &corev1.Service{
	TypeMeta:   kubeutil.TypeServiceV1,
	ObjectMeta: kubeutil.ObjectMeta(webhookName, Namespace, WebhookLabels, nil),
	Spec: corev1.ServiceSpec{
		Ports: []corev1.ServicePort{
			{
				Name:       "webhook",
				Port:       int32(443),
				Protocol:   corev1.ProtocolTCP,
				TargetPort: intstr.IntOrString{IntVal: int32(10250)},
			},
		},
		Selector: WebhookMatchLabels,
		Type:     corev1.ServiceTypeClusterIP,
	},
}

var SecretstoreValidateValidatingWH = &admissionregistrationv1.ValidatingWebhookConfiguration{
	TypeMeta: kubeutil.TypeValidatingWebhookConfigurationV1,
	ObjectMeta: metav1.ObjectMeta{
		Labels: map[string]string{"external-secrets.io/component": "webhook"},
		Name:   "secretstore-validate",
	},
	Webhooks: []admissionregistrationv1.ValidatingWebhook{
		{
			AdmissionReviewVersions: []string{"v1", "v1beta1"},
			ClientConfig: admissionregistrationv1.WebhookClientConfig{
				Service: &admissionregistrationv1.ServiceReference{
					Name:      "external-secrets-webhook",
					Namespace: "external-secrets",
					Path:      P("/validate-external-secrets-io-v1beta1-secretstore"),
				},
			},
			Name: "validate.secretstore.external-secrets.io",
			Rules: []admissionregistrationv1.RuleWithOperations{
				{
					Operations: []admissionregistrationv1.OperationType{
						admissionregistrationv1.OperationType("CREATE"),
						admissionregistrationv1.OperationType("UPDATE"),
						admissionregistrationv1.OperationType("DELETE"),
					},
					Rule: admissionregistrationv1.Rule{
						APIGroups:   []string{"external-secrets.io"},
						APIVersions: []string{"v1beta1"},
						Resources:   []string{"secretstores"},
						Scope:       P(admissionregistrationv1.NamespacedScope),
					},
				},
			},
			SideEffects:    P(admissionregistrationv1.SideEffectClassNone),
			TimeoutSeconds: P(int32(5)),
		}, {
			AdmissionReviewVersions: []string{"v1", "v1beta1"},
			ClientConfig: admissionregistrationv1.WebhookClientConfig{
				Service: &admissionregistrationv1.ServiceReference{
					Name:      "external-secrets-webhook",
					Namespace: "external-secrets",
					Path:      P("/validate-external-secrets-io-v1beta1-clustersecretstore"),
				},
			},
			Name: "validate.clustersecretstore.external-secrets.io",
			Rules: []admissionregistrationv1.RuleWithOperations{
				{
					Operations: []admissionregistrationv1.OperationType{
						admissionregistrationv1.OperationType("CREATE"),
						admissionregistrationv1.OperationType("UPDATE"),
						admissionregistrationv1.OperationType("DELETE"),
					},
					Rule: admissionregistrationv1.Rule{
						APIGroups:   []string{"external-secrets.io"},
						APIVersions: []string{"v1beta1"},
						Resources:   []string{"clustersecretstores"},
						Scope:       P(admissionregistrationv1.ScopeType("Cluster")),
					},
				},
			},
			SideEffects:    P(admissionregistrationv1.SideEffectClass("None")),
			TimeoutSeconds: P(int32(5)),
		},
	},
}

var ExternalsecretValidateValidatingWH = &admissionregistrationv1.ValidatingWebhookConfiguration{
	TypeMeta: kubeutil.TypeValidatingWebhookConfigurationV1,
	ObjectMeta: metav1.ObjectMeta{
		Labels: map[string]string{"external-secrets.io/component": "webhook"},
		Name:   "externalsecret-validate",
	},

	Webhooks: []admissionregistrationv1.ValidatingWebhook{
		{
			AdmissionReviewVersions: []string{"v1", "v1beta1"},
			ClientConfig: admissionregistrationv1.WebhookClientConfig{
				Service: &admissionregistrationv1.ServiceReference{
					Name:      "external-secrets-webhook",
					Namespace: "external-secrets",
					Path:      P("/validate-external-secrets-io-v1beta1-externalsecret"),
				},
			},
			FailurePolicy: P(admissionregistrationv1.FailurePolicyType("Fail")),
			Name:          "validate.externalsecret.external-secrets.io",
			Rules: []admissionregistrationv1.RuleWithOperations{
				{
					Operations: []admissionregistrationv1.OperationType{
						admissionregistrationv1.Create,
						admissionregistrationv1.Update,
						admissionregistrationv1.Delete,
					},
					Rule: admissionregistrationv1.Rule{
						APIGroups:   []string{"external-secrets.io"},
						APIVersions: []string{"v1beta1"},
						Resources:   []string{"externalsecrets"},
						Scope:       P(admissionregistrationv1.NamespacedScope),
					},
				},
			},
			SideEffects:    P(admissionregistrationv1.SideEffectClassNone),
			TimeoutSeconds: P(int32(5)),
		},
	},
}
