From 4009824712dc3e7154b38e5439854cecfe7d0281 Mon Sep 17 00:00:00 2001 From: jeongwook-park Date: Wed, 25 May 2022 14:51:31 +0900 Subject: [PATCH] additional metric names should not include objective metric name --- pkg/webhook/v1beta1/experiment/validator/validator.go | 3 +++ .../v1beta1/experiment/validator/validator_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/webhook/v1beta1/experiment/validator/validator.go b/pkg/webhook/v1beta1/experiment/validator/validator.go index fe6680e13d1..47a766a3260 100644 --- a/pkg/webhook/v1beta1/experiment/validator/validator.go +++ b/pkg/webhook/v1beta1/experiment/validator/validator.go @@ -157,6 +157,9 @@ func (g *DefaultValidator) validateObjective(obj *commonapiv1beta1.ObjectiveSpec if obj.ObjectiveMetricName == "" { return fmt.Errorf("no spec.objective.objectiveMetricName specified") } + if contains(obj.AdditionalMetricNames, obj.ObjectiveMetricName) { + return fmt.Errorf("spec.objective.additionalMetricNames should not contain spec.objective.objectiveMetricName") + } return nil } diff --git a/pkg/webhook/v1beta1/experiment/validator/validator_test.go b/pkg/webhook/v1beta1/experiment/validator/validator_test.go index b9b3049a6de..b2b3f786ddd 100644 --- a/pkg/webhook/v1beta1/experiment/validator/validator_test.go +++ b/pkg/webhook/v1beta1/experiment/validator/validator_test.go @@ -108,6 +108,16 @@ func TestValidateExperiment(t *testing.T) { Err: true, testDescription: "Objective metric name is empty", }, + { + Instance: func() *experimentsv1beta1.Experiment { + i := newFakeInstance() + i.Spec.Objective.ObjectiveMetricName = "objective" + i.Spec.Objective.AdditionalMetricNames = []string{"objective", "objective-1"} + return i + }(), + Err: true, + testDescription: "additionalMetricNames should not contain objective metric name", + }, // Algorithm { Instance: func() *experimentsv1beta1.Experiment {