2019-08-27 14:52:56 -07:00
|
|
|
package webhookconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-10-07 11:12:31 -07:00
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
2019-08-27 14:52:56 -07:00
|
|
|
admregapi "k8s.io/api/admissionregistration/v1beta1"
|
|
|
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
2020-11-26 16:07:06 -08:00
|
|
|
func (wrc *Register) contructPolicyValidatingWebhookConfig(caData []byte) *admregapi.ValidatingWebhookConfiguration {
|
2019-08-27 14:52:56 -07:00
|
|
|
|
|
|
|
return &admregapi.ValidatingWebhookConfiguration{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2019-09-04 13:43:12 -07:00
|
|
|
Name: config.PolicyValidatingWebhookConfigurationName,
|
2019-08-27 14:52:56 -07:00
|
|
|
OwnerReferences: []v1.OwnerReference{
|
|
|
|
wrc.constructOwner(),
|
|
|
|
},
|
|
|
|
},
|
2020-03-17 11:05:20 -07:00
|
|
|
Webhooks: []admregapi.ValidatingWebhook{
|
|
|
|
generateValidatingWebhook(
|
2019-08-27 14:52:56 -07:00
|
|
|
config.PolicyValidatingWebhookName,
|
|
|
|
config.PolicyValidatingWebhookServicePath,
|
|
|
|
caData,
|
|
|
|
true,
|
|
|
|
wrc.timeoutSeconds,
|
2020-08-19 21:37:23 +05:30
|
|
|
[]string{"clusterpolicies/*", "policies/*"},
|
2019-08-27 14:52:56 -07:00
|
|
|
"kyverno.io",
|
2019-11-13 13:56:07 -08:00
|
|
|
"v1",
|
2019-08-27 14:52:56 -07:00
|
|
|
[]admregapi.OperationType{admregapi.Create, admregapi.Update},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:07:06 -08:00
|
|
|
func (wrc *Register) contructDebugPolicyValidatingWebhookConfig(caData []byte) *admregapi.ValidatingWebhookConfiguration {
|
2020-03-17 16:25:34 -07:00
|
|
|
logger := wrc.log
|
2019-08-27 14:52:56 -07:00
|
|
|
url := fmt.Sprintf("https://%s%s", wrc.serverIP, config.PolicyValidatingWebhookServicePath)
|
2020-03-17 16:25:34 -07:00
|
|
|
logger.V(4).Info("Debug PolicyValidatingWebhookConfig is registered with url ", "url", url)
|
2019-08-27 14:52:56 -07:00
|
|
|
|
|
|
|
return &admregapi.ValidatingWebhookConfiguration{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2019-09-04 13:43:12 -07:00
|
|
|
Name: config.PolicyValidatingWebhookConfigurationDebugName,
|
2019-08-27 14:52:56 -07:00
|
|
|
},
|
2020-03-17 11:05:20 -07:00
|
|
|
Webhooks: []admregapi.ValidatingWebhook{
|
|
|
|
generateDebugValidatingWebhook(
|
2019-08-27 14:52:56 -07:00
|
|
|
config.PolicyValidatingWebhookName,
|
|
|
|
url,
|
|
|
|
caData,
|
|
|
|
true,
|
|
|
|
wrc.timeoutSeconds,
|
2020-08-19 21:37:23 +05:30
|
|
|
[]string{"clusterpolicies/*", "policies/*"},
|
2019-08-27 14:52:56 -07:00
|
|
|
"kyverno.io",
|
2019-11-13 13:56:07 -08:00
|
|
|
"v1",
|
2019-08-27 16:44:10 -07:00
|
|
|
[]admregapi.OperationType{admregapi.Create, admregapi.Update},
|
2019-08-27 14:52:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:07:06 -08:00
|
|
|
func (wrc *Register) contructPolicyMutatingWebhookConfig(caData []byte) *admregapi.MutatingWebhookConfiguration {
|
2019-08-27 14:52:56 -07:00
|
|
|
return &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2019-09-04 13:43:12 -07:00
|
|
|
Name: config.PolicyMutatingWebhookConfigurationName,
|
2019-08-27 14:52:56 -07:00
|
|
|
OwnerReferences: []v1.OwnerReference{
|
|
|
|
wrc.constructOwner(),
|
|
|
|
},
|
|
|
|
},
|
2020-03-17 11:05:20 -07:00
|
|
|
Webhooks: []admregapi.MutatingWebhook{
|
|
|
|
generateMutatingWebhook(
|
2019-08-27 14:52:56 -07:00
|
|
|
config.PolicyMutatingWebhookName,
|
|
|
|
config.PolicyMutatingWebhookServicePath,
|
|
|
|
caData,
|
|
|
|
true,
|
|
|
|
wrc.timeoutSeconds,
|
2020-08-19 21:37:23 +05:30
|
|
|
[]string{"clusterpolicies/*", "policies/*"},
|
2019-08-27 14:52:56 -07:00
|
|
|
"kyverno.io",
|
2019-11-13 13:56:07 -08:00
|
|
|
"v1",
|
2019-08-27 16:44:10 -07:00
|
|
|
[]admregapi.OperationType{admregapi.Create, admregapi.Update},
|
2019-08-27 14:52:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 16:07:06 -08:00
|
|
|
|
|
|
|
func (wrc *Register) contructDebugPolicyMutatingWebhookConfig(caData []byte) *admregapi.MutatingWebhookConfiguration {
|
2020-03-17 16:25:34 -07:00
|
|
|
logger := wrc.log
|
2019-08-27 16:44:10 -07:00
|
|
|
url := fmt.Sprintf("https://%s%s", wrc.serverIP, config.PolicyMutatingWebhookServicePath)
|
2020-03-17 16:25:34 -07:00
|
|
|
logger.V(4).Info("Debug PolicyMutatingWebhookConfig is registered with url ", "url", url)
|
2019-08-27 14:52:56 -07:00
|
|
|
|
|
|
|
return &admregapi.MutatingWebhookConfiguration{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2019-09-04 13:43:12 -07:00
|
|
|
Name: config.PolicyMutatingWebhookConfigurationDebugName,
|
2019-08-27 14:52:56 -07:00
|
|
|
},
|
2020-03-17 11:05:20 -07:00
|
|
|
Webhooks: []admregapi.MutatingWebhook{
|
|
|
|
generateDebugMutatingWebhook(
|
2019-08-27 14:52:56 -07:00
|
|
|
config.PolicyMutatingWebhookName,
|
|
|
|
url,
|
|
|
|
caData,
|
|
|
|
true,
|
|
|
|
wrc.timeoutSeconds,
|
2020-08-19 21:37:23 +05:30
|
|
|
[]string{"clusterpolicies/*", "policies/*"},
|
2019-08-27 14:52:56 -07:00
|
|
|
"kyverno.io",
|
2019-11-13 13:56:07 -08:00
|
|
|
"v1",
|
2019-08-27 16:44:10 -07:00
|
|
|
[]admregapi.OperationType{admregapi.Create, admregapi.Update},
|
2019-08-27 14:52:56 -07:00
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|