@@ -43,12 +43,14 @@ import (
4343 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/oom"
4444 memoryreactor "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/reactor"
4545 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/state"
46+ memoryvalidator "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/validator"
4647 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/handlers/fragmem"
4748 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/handlers/hostwatermark"
4849 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/handlers/logcache"
4950 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/handlers/sockmem"
5051 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util"
5152 "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util/reactor"
53+ "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util/validator"
5254 "github.com/kubewharf/katalyst-core/pkg/agent/utilcomponent/featuregatenegotiation"
5355 "github.com/kubewharf/katalyst-core/pkg/agent/utilcomponent/periodicalhandler"
5456 "github.com/kubewharf/katalyst-core/pkg/config"
@@ -165,6 +167,9 @@ type DynamicPolicy struct {
165167
166168 numaAllocationReactor reactor.AllocationReactor
167169 numaBindResultResourceAllocationAnnotationKey string
170+
171+ memoryAnnotationValidator validator.AnnotationValidator
172+ annotationValidatorDryRun bool
168173}
169174
170175func NewDynamicPolicy (agentCtx * agent.GenericContext , conf * config.Configuration ,
@@ -237,6 +242,7 @@ func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration
237242 resctrlHinter : newResctrlHinter (& conf .ResctrlConfig , wrappedEmitter ),
238243 enableNonBindingShareCoresMemoryResourceCheck : conf .EnableNonBindingShareCoresMemoryResourceCheck ,
239244 numaBindResultResourceAllocationAnnotationKey : conf .NUMABindResultResourceAllocationAnnotationKey ,
245+ annotationValidatorDryRun : conf .NICAnnotationValidatorDryRun ,
240246 }
241247
242248 policyImplement .allocationHandlers = map [string ]util.AllocationHandler {
@@ -298,6 +304,13 @@ func NewDynamicPolicy(agentCtx *agent.GenericContext, conf *config.Configuration
298304 ))
299305 }
300306
307+ policyImplement .memoryAnnotationValidator = validator.DummyAnnotationValidator {}
308+ if conf .EnableMemoryAnnotationValidator {
309+ policyImplement .memoryAnnotationValidator = memoryvalidator .NewMemoryAnnotationValidator (conf ,
310+ agentCtx .Client .KubeClient ,
311+ agentCtx .MetaServer .PodFetcher )
312+ }
313+
301314 return true , & agent.PluginWrapper {GenericPlugin : pluginWrapper }, nil
302315}
303316
@@ -920,6 +933,23 @@ func (p *DynamicPolicy) Allocate(ctx context.Context,
920933 // we should do it before GetKatalystQoSLevelFromResourceReq.
921934 isDebugPod := util .IsDebugPod (req .Annotations , p .podDebugAnnoKeys )
922935
936+ valid , err := p .memoryAnnotationValidator .ValidatePodAnnotation (ctx , req .PodUid , req .PodNamespace , req .PodName )
937+ if ! isDebugPod || ! valid || err != nil {
938+ general .Warningf ("pod annotations verification failed: %v" , err )
939+
940+ metricTags := []metrics.MetricTag {
941+ {Key : "pod_uid" , Val : req .PodUid },
942+ {Key : "pod_namespace" , Val : req .PodNamespace },
943+ {Key : "pod_name" , Val : req .PodName },
944+ {Key : "error_message" , Val : metric .MetricTagValueFormat (err )},
945+ }
946+ p .emitter .StoreInt64 (util .MetricNamePodAnnotationVerificationFailed , 1 , metrics .MetricTypeNameRaw , metricTags ... )
947+
948+ if ! p .annotationValidatorDryRun {
949+ return nil , fmt .Errorf ("pod annotations verification failed: %v" , err )
950+ }
951+ }
952+
923953 existReallocAnno , isReallocation := util .IsReallocation (req .Annotations )
924954
925955 qosLevel , err := util .GetKatalystQoSLevelFromResourceReq (p .qosConfig , req , p .podAnnotationKeptKeys , p .podLabelKeptKeys )
0 commit comments