<commit_before>package k8s

import (
	"errors"
	"fmt"

	"github.com/nginxinc/kubernetes-ingress/internal/configs"
	networking "k8s.io/api/networking/v1beta1"
	"k8s.io/apimachinery/pkg/util/sets"
	"k8s.io/apimachinery/pkg/util/validation/field"
)

const (
	mergeableIngressTypeAnnotation       = "nginx.org/mergeable-ingress-type"
	lbMethodAnnotation                   = "nginx.org/lb-method"
	healthChecksAnnotation               = "nginx.com/health-checks"
	healthChecksMandatoryAnnotation      = "nginx.com/health-checks-mandatory"
	healthChecksMandatoryQueueAnnotation = "nginx.com/health-checks-mandatory-queue"
)

type annotationValidationContext struct {
	annotations map[string]string
	name        string
	value       string
	isPlus      bool
	fieldPath   *field.Path
}

type annotationValidationFunc func(context *annotationValidationContext) field.ErrorList
type validatorFunc func(val string) error

var annotationValidations = map[string][]annotationValidationFunc{
	mergeableIngressTypeAnnotation: {
		validateRequiredAnnotation,
		validateMergeableIngressTypeAnnotation,
	},
	lbMethodAnnotation: {
		validateRequiredAnnotation,
		validateLBMethodAnnotation,
	},
	healthChecksAnnotation: {
		validateRequiredAnnotation,
		validatePlusOnlyAnnotation,
		validateBoolAnnotation,
	},
	healthChecksMandatoryAnnotation: {
		validateRelatedAnnotation(healthChecksAnnotation, validateIsTrue),
		validateRequiredAnnotation,
		validateBoolAnnotation,
	},
	healthChecksMandatoryQueueAnnotation: {
		validateRelatedAnnotation(healthChecksMandatoryAnnotation, validateIsTrue),
		validateRequiredAnnotation,
		validateNonNegativeIntAnnotation,
	},
}<commit_msg>Add a comment describing how annotation validations are run<commit_after>package k8s

import (
	"errors"
	"fmt"

	"github.com/nginxinc/kubernetes-ingress/internal/configs"
	networking "k8s.io/api/networking/v1beta1"
	"k8s.io/apimachinery/pkg/util/sets"
	"k8s.io/apimachinery/pkg/util/validation/field"
)

const (
	mergeableIngressTypeAnnotation       = "nginx.org/mergeable-ingress-type"
	lbMethodAnnotation                   = "nginx.org/lb-method"
	healthChecksAnnotation               = "nginx.com/health-checks"
	healthChecksMandatoryAnnotation      = "nginx.com/health-checks-mandatory"
	healthChecksMandatoryQueueAnnotation = "nginx.com/health-checks-mandatory-queue"
)

type annotationValidationContext struct {
	annotations map[string]string
	name        string
	value       string
	isPlus      bool
	fieldPath   *field.Path
}

type annotationValidationFunc func(context *annotationValidationContext) field.ErrorList
type validatorFunc func(val string) error

// annotationValidations defines the various validations which will be applied in order to each ingress annotation.
// If any specified validation fails, the remaining validations for that annotation will not be run.
var annotationValidations = map[string][]annotationValidationFunc{
	mergeableIngressTypeAnnotation: {
		validateRequiredAnnotation,
		validateMergeableIngressTypeAnnotation,
	},
	lbMethodAnnotation: {
		validateRequiredAnnotation,
		validateLBMethodAnnotation,
	},
	healthChecksAnnotation: {
		validateRequiredAnnotation,
		validatePlusOnlyAnnotation,
		validateBoolAnnotation,
	},
	healthChecksMandatoryAnnotation: {
		validateRelatedAnnotation(healthChecksAnnotation, validateIsTrue),
		validateRequiredAnnotation,
		validateBoolAnnotation,
	},
	healthChecksMandatoryQueueAnnotation: {
		validateRelatedAnnotation(healthChecksMandatoryAnnotation, validateIsTrue),
		validateRequiredAnnotation,
		validateNonNegativeIntAnnotation,
	},
}
{'fraction_non_alphanumeric': 0.07567718514381458, 'fraction_numerical': 0.003351019268360793, 'mean_word_length': 5.500907441016334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2197368', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1024, 'n_words': 172}