2019-08-27 21:52:56 +00:00
|
|
|
package webhookconfig
|
|
|
|
|
|
|
|
import (
|
2022-05-02 10:58:04 +00:00
|
|
|
"context"
|
2021-12-02 10:22:34 +00:00
|
|
|
"errors"
|
2022-05-08 11:47:49 +00:00
|
|
|
"fmt"
|
2021-10-05 07:15:09 +00:00
|
|
|
"reflect"
|
2021-12-02 10:22:34 +00:00
|
|
|
"strings"
|
2019-08-27 21:52:56 +00:00
|
|
|
|
2020-10-07 18:12:31 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
2021-03-16 18:31:04 +00:00
|
|
|
"github.com/kyverno/kyverno/pkg/tls"
|
2021-10-05 07:15:09 +00:00
|
|
|
admregapi "k8s.io/api/admissionregistration/v1"
|
2022-05-02 10:58:04 +00:00
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
2022-05-09 14:31:35 +00:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
rbacv1 "k8s.io/api/rbac/v1"
|
2022-05-02 10:58:04 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2019-08-27 21:52:56 +00:00
|
|
|
)
|
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
var (
|
|
|
|
noneOnDryRun = admregapi.SideEffectClassNoneOnDryRun
|
|
|
|
never = admregapi.NeverReinvocationPolicy
|
|
|
|
ifNeeded = admregapi.IfNeededReinvocationPolicy
|
|
|
|
policyRule = admregapi.Rule{
|
|
|
|
Resources: []string{"clusterpolicies/*", "policies/*"},
|
|
|
|
APIGroups: []string{"kyverno.io"},
|
|
|
|
APIVersions: []string{"v1"},
|
|
|
|
}
|
|
|
|
verifyRule = admregapi.Rule{
|
|
|
|
Resources: []string{"leases"},
|
|
|
|
APIGroups: []string{"coordination.k8s.io"},
|
|
|
|
APIVersions: []string{"v1"},
|
|
|
|
}
|
|
|
|
vertifyObjectSelector = &metav1.LabelSelector{
|
|
|
|
MatchLabels: map[string]string{
|
|
|
|
"app.kubernetes.io/name": "kyverno",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
update = []admregapi.OperationType{admregapi.Update}
|
|
|
|
createUpdate = []admregapi.OperationType{admregapi.Create, admregapi.Update}
|
|
|
|
all = []admregapi.OperationType{admregapi.Create, admregapi.Update, admregapi.Delete, admregapi.Connect}
|
|
|
|
)
|
|
|
|
|
2020-11-27 00:07:06 +00:00
|
|
|
func (wrc *Register) readCaData() []byte {
|
2021-03-16 18:31:04 +00:00
|
|
|
logger := wrc.log.WithName("readCaData")
|
2019-08-27 21:52:56 +00:00
|
|
|
var caData []byte
|
2021-03-16 18:31:04 +00:00
|
|
|
var err error
|
|
|
|
|
2019-08-27 21:52:56 +00:00
|
|
|
// Check if ca is defined in the secret tls-ca
|
|
|
|
// assume the key and signed cert have been defined in secret tls.kyverno
|
2022-04-26 20:18:14 +00:00
|
|
|
if caData, err = tls.ReadRootCASecret(wrc.clientConfig, wrc.kubeClient); err == nil {
|
2020-03-17 23:25:34 +00:00
|
|
|
logger.V(4).Info("read CA from secret")
|
2019-08-27 21:52:56 +00:00
|
|
|
return caData
|
|
|
|
}
|
2021-03-16 18:31:04 +00:00
|
|
|
|
2020-03-17 23:25:34 +00:00
|
|
|
logger.V(4).Info("failed to read CA from kubeconfig")
|
2019-08-27 21:52:56 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-09 15:54:20 +00:00
|
|
|
func getHealthyPodsIP(pods []corev1.Pod) []string {
|
|
|
|
var ips []string
|
2022-05-09 14:31:35 +00:00
|
|
|
for _, pod := range pods {
|
|
|
|
if pod.Status.Phase == "Running" {
|
|
|
|
ips = append(ips, pod.Status.PodIP)
|
|
|
|
}
|
2021-08-14 00:07:40 +00:00
|
|
|
}
|
2022-05-09 15:54:20 +00:00
|
|
|
return ips
|
2021-08-14 00:07:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:31:35 +00:00
|
|
|
func (wrc *Register) GetKubePolicyClusterRoleName() (*rbacv1.ClusterRole, error) {
|
2022-05-02 10:58:04 +00:00
|
|
|
selector := &metav1.LabelSelector{
|
|
|
|
MatchLabels: map[string]string{
|
|
|
|
"app.kubernetes.io/name": "kyverno",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
clusterRoles, err := wrc.kubeClient.RbacV1().ClusterRoles().List(context.TODO(), metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(selector)})
|
2021-08-14 00:07:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-12-02 10:22:34 +00:00
|
|
|
for _, cr := range clusterRoles.Items {
|
|
|
|
if strings.HasSuffix(cr.GetName(), "webhook") {
|
|
|
|
return &cr, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, errors.New("failed to get cluster role with suffix webhook")
|
2021-08-14 00:07:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 19:37:19 +00:00
|
|
|
// GetKubePolicyDeployment gets Kyverno deployment using the resource cache
|
|
|
|
// it does not initialize any client call
|
2022-05-02 10:58:04 +00:00
|
|
|
func (wrc *Register) GetKubePolicyDeployment() (*appsv1.Deployment, error) {
|
2022-01-18 15:52:48 +00:00
|
|
|
deploy, err := wrc.kDeplLister.Deployments(config.KyvernoNamespace).Get(config.KyvernoDeploymentName)
|
2021-02-05 17:58:10 +00:00
|
|
|
if err != nil {
|
2022-05-02 10:58:04 +00:00
|
|
|
return nil, err
|
2021-02-05 17:58:10 +00:00
|
|
|
}
|
2022-05-02 10:58:04 +00:00
|
|
|
return deploy, nil
|
2021-02-05 17:58:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:31:35 +00:00
|
|
|
func (wrc *Register) constructOwner() metav1.OwnerReference {
|
|
|
|
logger := wrc.log
|
|
|
|
kubeClusterRoleName, err := wrc.GetKubePolicyClusterRoleName()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err, "failed to get cluster role")
|
|
|
|
return metav1.OwnerReference{}
|
|
|
|
}
|
|
|
|
return metav1.OwnerReference{
|
|
|
|
APIVersion: config.ClusterRoleAPIVersion,
|
|
|
|
Kind: config.ClusterRoleKind,
|
|
|
|
Name: kubeClusterRoleName.GetName(),
|
|
|
|
UID: kubeClusterRoleName.GetUID(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
// webhook utils
|
|
|
|
|
|
|
|
func generateRules(rule admregapi.Rule, operationTypes []admregapi.OperationType) []admregapi.RuleWithOperations {
|
|
|
|
if !reflect.DeepEqual(rule, admregapi.Rule{}) {
|
|
|
|
return []admregapi.RuleWithOperations{{Operations: operationTypes, Rule: rule}}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-08-05 16:11:23 +00:00
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
func generateDebugMutatingWebhook(name, url string, caData []byte, timeoutSeconds int32, rule admregapi.Rule, operationTypes []admregapi.OperationType, failurePolicy admregapi.FailurePolicyType) admregapi.MutatingWebhook {
|
|
|
|
return admregapi.MutatingWebhook{
|
|
|
|
ReinvocationPolicy: &never,
|
2020-08-05 16:11:23 +00:00
|
|
|
Name: name,
|
2019-08-27 21:52:56 +00:00
|
|
|
ClientConfig: admregapi.WebhookClientConfig{
|
|
|
|
URL: &url,
|
|
|
|
CABundle: caData,
|
|
|
|
},
|
2022-05-08 11:47:49 +00:00
|
|
|
SideEffects: &noneOnDryRun,
|
2019-12-05 01:28:39 +00:00
|
|
|
AdmissionReviewVersions: []string{"v1beta1"},
|
|
|
|
TimeoutSeconds: &timeoutSeconds,
|
2020-01-16 02:01:50 +00:00
|
|
|
FailurePolicy: &failurePolicy,
|
2022-05-08 11:47:49 +00:00
|
|
|
Rules: generateRules(rule, operationTypes),
|
2019-08-27 21:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
func generateDebugValidatingWebhook(name, url string, caData []byte, timeoutSeconds int32, rule admregapi.Rule, operationTypes []admregapi.OperationType, failurePolicy admregapi.FailurePolicyType) admregapi.ValidatingWebhook {
|
|
|
|
return admregapi.ValidatingWebhook{
|
2020-03-17 18:05:20 +00:00
|
|
|
Name: name,
|
|
|
|
ClientConfig: admregapi.WebhookClientConfig{
|
|
|
|
URL: &url,
|
|
|
|
CABundle: caData,
|
|
|
|
},
|
2022-05-08 11:47:49 +00:00
|
|
|
SideEffects: &noneOnDryRun,
|
2020-03-17 18:05:20 +00:00
|
|
|
AdmissionReviewVersions: []string{"v1beta1"},
|
|
|
|
TimeoutSeconds: &timeoutSeconds,
|
|
|
|
FailurePolicy: &failurePolicy,
|
2022-05-08 11:47:49 +00:00
|
|
|
Rules: generateRules(rule, operationTypes),
|
2020-03-17 18:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
func generateMutatingWebhook(name, servicePath string, caData []byte, timeoutSeconds int32, rule admregapi.Rule, operationTypes []admregapi.OperationType, failurePolicy admregapi.FailurePolicyType) admregapi.MutatingWebhook {
|
|
|
|
return admregapi.MutatingWebhook{
|
|
|
|
ReinvocationPolicy: &ifNeeded,
|
2020-08-05 16:11:23 +00:00
|
|
|
Name: name,
|
2020-03-17 18:05:20 +00:00
|
|
|
ClientConfig: admregapi.WebhookClientConfig{
|
|
|
|
Service: &admregapi.ServiceReference{
|
2020-11-27 00:07:06 +00:00
|
|
|
Namespace: config.KyvernoNamespace,
|
|
|
|
Name: config.KyvernoServiceName,
|
2020-03-17 18:05:20 +00:00
|
|
|
Path: &servicePath,
|
|
|
|
},
|
|
|
|
CABundle: caData,
|
|
|
|
},
|
2022-05-08 11:47:49 +00:00
|
|
|
SideEffects: &noneOnDryRun,
|
2020-03-17 18:05:20 +00:00
|
|
|
AdmissionReviewVersions: []string{"v1beta1"},
|
|
|
|
TimeoutSeconds: &timeoutSeconds,
|
|
|
|
FailurePolicy: &failurePolicy,
|
2022-05-08 11:47:49 +00:00
|
|
|
Rules: generateRules(rule, operationTypes),
|
2020-03-17 18:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
func generateValidatingWebhook(name, servicePath string, caData []byte, timeoutSeconds int32, rule admregapi.Rule, operationTypes []admregapi.OperationType, failurePolicy admregapi.FailurePolicyType) admregapi.ValidatingWebhook {
|
|
|
|
return admregapi.ValidatingWebhook{
|
2019-08-27 21:52:56 +00:00
|
|
|
Name: name,
|
|
|
|
ClientConfig: admregapi.WebhookClientConfig{
|
|
|
|
Service: &admregapi.ServiceReference{
|
2020-11-27 00:07:06 +00:00
|
|
|
Namespace: config.KyvernoNamespace,
|
|
|
|
Name: config.KyvernoServiceName,
|
2019-08-27 21:52:56 +00:00
|
|
|
Path: &servicePath,
|
|
|
|
},
|
|
|
|
CABundle: caData,
|
|
|
|
},
|
2022-05-08 11:47:49 +00:00
|
|
|
SideEffects: &noneOnDryRun,
|
2019-12-05 01:28:39 +00:00
|
|
|
AdmissionReviewVersions: []string{"v1beta1"},
|
|
|
|
TimeoutSeconds: &timeoutSeconds,
|
2020-01-16 02:01:50 +00:00
|
|
|
FailurePolicy: &failurePolicy,
|
2022-05-08 11:47:49 +00:00
|
|
|
Rules: generateRules(rule, operationTypes),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateObjectMeta(name string, owner ...metav1.OwnerReference) metav1.ObjectMeta {
|
|
|
|
return metav1.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
OwnerReferences: owner,
|
2019-08-27 21:52:56 +00:00
|
|
|
}
|
2022-05-08 11:47:49 +00:00
|
|
|
}
|
2021-10-05 07:15:09 +00:00
|
|
|
|
2022-05-08 11:47:49 +00:00
|
|
|
// policy webhook configuration utils
|
|
|
|
|
|
|
|
func getPolicyMutatingWebhookConfigName(serverIP string) string {
|
|
|
|
if serverIP != "" {
|
|
|
|
return config.PolicyMutatingWebhookConfigurationDebugName
|
|
|
|
}
|
|
|
|
return config.PolicyMutatingWebhookConfigurationName
|
|
|
|
}
|
|
|
|
|
|
|
|
func getPolicyValidatingWebhookConfigName(serverIP string) string {
|
|
|
|
if serverIP != "" {
|
|
|
|
return config.PolicyValidatingWebhookConfigurationDebugName
|
|
|
|
}
|
|
|
|
return config.PolicyValidatingWebhookConfigurationName
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructPolicyValidatingWebhookConfig(caData []byte, timeoutSeconds int32, owner metav1.OwnerReference) *admregapi.ValidatingWebhookConfiguration {
|
|
|
|
name, path := config.PolicyValidatingWebhookName, config.PolicyValidatingWebhookServicePath
|
|
|
|
return &admregapi.ValidatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.PolicyValidatingWebhookConfigurationName, owner),
|
|
|
|
Webhooks: []admregapi.ValidatingWebhook{
|
|
|
|
generateValidatingWebhook(name, path, caData, timeoutSeconds, policyRule, createUpdate, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDebugPolicyValidatingWebhookConfig(serverIP string, caData []byte, timeoutSeconds int32, owner metav1.OwnerReference) *admregapi.ValidatingWebhookConfiguration {
|
|
|
|
name, url := config.PolicyValidatingWebhookName, fmt.Sprintf("https://%s%s", serverIP, config.PolicyValidatingWebhookServicePath)
|
|
|
|
return &admregapi.ValidatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.PolicyValidatingWebhookConfigurationDebugName, owner),
|
|
|
|
Webhooks: []admregapi.ValidatingWebhook{
|
|
|
|
generateDebugValidatingWebhook(name, url, caData, timeoutSeconds, policyRule, createUpdate, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructPolicyMutatingWebhookConfig(caData []byte, timeoutSeconds int32, owner metav1.OwnerReference) *admregapi.MutatingWebhookConfiguration {
|
|
|
|
name, path := config.PolicyMutatingWebhookName, config.PolicyMutatingWebhookServicePath
|
|
|
|
return &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.PolicyMutatingWebhookConfigurationName, owner),
|
|
|
|
Webhooks: []admregapi.MutatingWebhook{
|
|
|
|
generateMutatingWebhook(name, path, caData, timeoutSeconds, policyRule, createUpdate, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDebugPolicyMutatingWebhookConfig(serverIP string, caData []byte, timeoutSeconds int32, owner metav1.OwnerReference) *admregapi.MutatingWebhookConfiguration {
|
|
|
|
name, url := config.PolicyMutatingWebhookName, fmt.Sprintf("https://%s%s", serverIP, config.PolicyMutatingWebhookServicePath)
|
|
|
|
return &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.PolicyMutatingWebhookConfigurationDebugName, owner),
|
|
|
|
Webhooks: []admregapi.MutatingWebhook{
|
|
|
|
generateDebugMutatingWebhook(name, url, caData, timeoutSeconds, policyRule, createUpdate, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// resource webhook configuration utils
|
|
|
|
|
|
|
|
func getResourceMutatingWebhookConfigName(serverIP string) string {
|
|
|
|
if serverIP != "" {
|
|
|
|
return config.MutatingWebhookConfigurationDebugName
|
|
|
|
}
|
|
|
|
return config.MutatingWebhookConfigurationName
|
|
|
|
}
|
|
|
|
|
|
|
|
func getResourceValidatingWebhookConfigName(serverIP string) string {
|
|
|
|
if serverIP != "" {
|
|
|
|
return config.ValidatingWebhookConfigurationDebugName
|
|
|
|
}
|
|
|
|
return config.ValidatingWebhookConfigurationName
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultResourceWebhookRule(autoUpdate bool) admregapi.Rule {
|
|
|
|
if autoUpdate {
|
|
|
|
return admregapi.Rule{}
|
|
|
|
}
|
|
|
|
return admregapi.Rule{
|
|
|
|
APIGroups: []string{"*"},
|
|
|
|
APIVersions: []string{"*"},
|
|
|
|
Resources: []string{"*/*"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDefaultDebugMutatingWebhookConfig(serverIP string, caData []byte, timeoutSeconds int32, autoUpdate bool, owner metav1.OwnerReference) *admregapi.MutatingWebhookConfiguration {
|
|
|
|
name, url := config.MutatingWebhookName, fmt.Sprintf("https://%s%s", serverIP, config.MutatingWebhookServicePath)
|
|
|
|
webhook := &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.MutatingWebhookConfigurationDebugName, owner),
|
|
|
|
Webhooks: []admregapi.MutatingWebhook{
|
|
|
|
generateDebugMutatingWebhook(name+"-ignore", url, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), createUpdate, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if autoUpdate {
|
|
|
|
webhook.Webhooks = append(webhook.Webhooks, generateDebugMutatingWebhook(name+"-fail", url, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), createUpdate, admregapi.Fail))
|
|
|
|
}
|
|
|
|
return webhook
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDefaultMutatingWebhookConfig(caData []byte, timeoutSeconds int32, autoUpdate bool, owner metav1.OwnerReference) *admregapi.MutatingWebhookConfiguration {
|
|
|
|
name, path := config.MutatingWebhookName, config.MutatingWebhookServicePath
|
|
|
|
webhook := &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.MutatingWebhookConfigurationName, owner),
|
|
|
|
Webhooks: []admregapi.MutatingWebhook{
|
|
|
|
generateMutatingWebhook(name+"-ignore", path, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), createUpdate, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if autoUpdate {
|
|
|
|
webhook.Webhooks = append(webhook.Webhooks, generateMutatingWebhook(name+"-fail", path, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), createUpdate, admregapi.Fail))
|
|
|
|
}
|
|
|
|
return webhook
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDefaultDebugValidatingWebhookConfig(serverIP string, caData []byte, timeoutSeconds int32, autoUpdate bool, owner metav1.OwnerReference) *admregapi.ValidatingWebhookConfiguration {
|
|
|
|
name, url := config.ValidatingWebhookName, fmt.Sprintf("https://%s%s", serverIP, config.ValidatingWebhookServicePath)
|
|
|
|
webhook := &admregapi.ValidatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.ValidatingWebhookConfigurationDebugName, owner),
|
|
|
|
Webhooks: []admregapi.ValidatingWebhook{
|
|
|
|
generateDebugValidatingWebhook(name+"-ignore", url, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), all, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if autoUpdate {
|
|
|
|
webhook.Webhooks = append(webhook.Webhooks, generateDebugValidatingWebhook(name+"-fail", url, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), all, admregapi.Fail))
|
|
|
|
}
|
|
|
|
return webhook
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDefaultValidatingWebhookConfig(caData []byte, timeoutSeconds int32, autoUpdate bool, owner metav1.OwnerReference) *admregapi.ValidatingWebhookConfiguration {
|
|
|
|
name, path := config.ValidatingWebhookName, config.ValidatingWebhookServicePath
|
|
|
|
webhook := &admregapi.ValidatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.ValidatingWebhookConfigurationName, owner),
|
|
|
|
Webhooks: []admregapi.ValidatingWebhook{
|
|
|
|
generateValidatingWebhook(name+"-ignore", path, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), all, admregapi.Ignore),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if autoUpdate {
|
|
|
|
webhook.Webhooks = append(webhook.Webhooks, generateValidatingWebhook(name+"-fail", path, caData, timeoutSeconds, defaultResourceWebhookRule(autoUpdate), all, admregapi.Fail))
|
|
|
|
}
|
|
|
|
return webhook
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify webhook configuration utils
|
|
|
|
|
|
|
|
func getVerifyMutatingWebhookConfigName(serverIP string) string {
|
|
|
|
if serverIP != "" {
|
|
|
|
return config.VerifyMutatingWebhookConfigurationDebugName
|
|
|
|
}
|
|
|
|
return config.VerifyMutatingWebhookConfigurationName
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructVerifyMutatingWebhookConfig(caData []byte, timeoutSeconds int32, owner metav1.OwnerReference) *admregapi.MutatingWebhookConfiguration {
|
|
|
|
name, path := config.VerifyMutatingWebhookName, config.VerifyMutatingWebhookServicePath
|
|
|
|
webhook := generateMutatingWebhook(name, path, caData, timeoutSeconds, verifyRule, update, admregapi.Ignore)
|
|
|
|
webhook.ObjectSelector = vertifyObjectSelector
|
|
|
|
return &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.VerifyMutatingWebhookConfigurationName, owner),
|
|
|
|
Webhooks: []admregapi.MutatingWebhook{webhook},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func constructDebugVerifyMutatingWebhookConfig(serverIP string, caData []byte, timeoutSeconds int32, owner metav1.OwnerReference) *admregapi.MutatingWebhookConfiguration {
|
|
|
|
name, url := config.VerifyMutatingWebhookName, fmt.Sprintf("https://%s%s", serverIP, config.VerifyMutatingWebhookServicePath)
|
|
|
|
webhook := generateDebugMutatingWebhook(name, url, caData, timeoutSeconds, verifyRule, update, admregapi.Ignore)
|
|
|
|
webhook.ObjectSelector = vertifyObjectSelector
|
|
|
|
return &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: generateObjectMeta(config.VerifyMutatingWebhookConfigurationDebugName, owner),
|
|
|
|
Webhooks: []admregapi.MutatingWebhook{webhook},
|
2021-10-05 07:15:09 +00:00
|
|
|
}
|
2019-08-27 21:52:56 +00:00
|
|
|
}
|