in controller/webhook.go [216:261]
func (whsvr *WebhookServer) shouldMutate(nsLabels map[string]string, podMetadata *metav1.ObjectMeta) bool {
annotations := podMetadata.GetAnnotations()
if annotations == nil {
annotations = map[string]string{}
}
if annotations[signingProxyWebhookAnnotationStatusKey] == "injected" {
return false
}
if annotations[signingProxyWebhookAnnotationHostKey] == "" && nsLabels[signingProxyWebhookLabelHostKey] == "" {
return false
}
var annotationInject bool
var annotationReject bool
switch strings.ToLower(annotations[signingProxyWebhookAnnotationInjectKey]) {
case "y", "yes", "true", "on":
annotationInject = true
case "n", "no", "false", "off":
annotationReject = true
}
var labelInject bool
for _, nsSelector := range namespaceSelector {
selector, err := metav1.LabelSelectorAsSelector(&nsSelector)
if err != nil {
fmt.Errorf("Invalid selector for NamespaceSelector")
return false
} else if !selector.Empty() && selector.Matches(labels.Set(nsLabels)) {
labelInject = true
} else if !annotationInject {
return false
}
}
if labelInject {
return !annotationReject
}
return annotationInject
}