func match(dk *dynatracev1beta1.DynaKube, namespace *corev1.Namespace) (bool, error) {
	matches := false
	if dk.NamespaceSelector() == nil {
		matches = true
	} else {
		selector, err := metav1.LabelSelectorAsSelector(dk.NamespaceSelector())
		if err != nil {
			return matches, errors.WithStack(err)
		}
		matches = selector.Matches(labels.Set(namespace.Labels))
	}
	return matches, nil
}
match uses the namespace selector in the dynakube to check if it matches a given namespace
if the namspace selector is not set on the dynakube its an automatic match
package mapper
import (
	"context"
	"regexp"
	dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/api/v1beta1"
	dtwebhook "github.com/Dynatrace/dynatrace-operator/webhook"
	"github.com/go-logr/logr"
	"github.com/pkg/errors"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/labels"
	"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
	InstanceLabel                = dtwebhook.LabelInstance
	UpdatedViaDynakubeAnnotation = "dynatrace.com/updated-via-operator"
)
type ConflictChecker struct {
	alreadyUsed bool
}
func (c *ConflictChecker) check(dk *dynatracev1beta1.DynaKube) error {
	if !dk.NeedAppInjection() {
		return nil
	}
	if c.alreadyUsed {
		return errors.New("namespace matches two or more DynaKubes which is unsupported. " +
			"refine the labels on your namespace metadata or DynaKube/CodeModules specification")
	}
	c.alreadyUsed = true
	return nil
}
func GetNamespacesForDynakube(ctx context.Context, clt client.Reader, dkName string) ([]corev1.Namespace, error) {
	nsList := &corev1.NamespaceList{}
	listOps := []client.ListOption{
		client.MatchingLabels(map[string]string{InstanceLabel: dkName}),
	}
	err := clt.List(ctx, nsList, listOps...)
	if err != nil {
		return nil, err
	}
	return nsList.Items, err
}
func addNamespaceInjectLabel(dkName string, ns *corev1.Namespace) {
	if ns.Labels == nil {
		ns.Labels = make(map[string]string)
	}
	ns.Labels[InstanceLabel] = dkName
}
func setUpdatedViaDynakubeAnnotation(ns *corev1.Namespace) {
	if ns.Annotations == nil {
		ns.Annotations = make(map[string]string)
	}
	ns.Annotations[UpdatedViaDynakubeAnnotation] = "true"
}