diff --git a/experiments/experiment.go b/experiments/experiment.go index 0ab5d3bb8a..29980309d8 100644 --- a/experiments/experiment.go +++ b/experiments/experiment.go @@ -294,6 +294,9 @@ func (ec *experimentContext) createTemplateService(template *v1alpha1.TemplateSp Port: port.ContainerPort, TargetPort: intstr.FromInt(int(port.ContainerPort)), } + if port.Name != "" { + servicePort.Name = port.Name + } ports = append(ports, servicePort) } } diff --git a/test/e2e/experiment_test.go b/test/e2e/experiment_test.go index 4ff844cb50..1d7262b099 100644 --- a/test/e2e/experiment_test.go +++ b/test/e2e/experiment_test.go @@ -99,6 +99,27 @@ func (s *ExperimentSuite) TestExperimentWithServiceAndScaleDownDelay() { ExpectExperimentServiceCount("experiment-with-service", 0) } +func (s *ExperimentSuite) TestExperimentWithMultiportServiceAndScaleDownDelay() { + g := s.Given() + g.ApplyManifests("@functional/experiment-with-multiport-service.yaml") + g.When(). + WaitForExperimentPhase("experiment-with-multiport-service", "Running"). + WaitForExperimentCondition("experiment-with-multiport-service", func(ex *rov1.Experiment) bool { + return s.GetReplicaSetFromExperiment(ex, "test").Status.Replicas == 1 + }, "number-of-rs-pods-meet", fixtures.E2EWaitTimeout). + Then(). + ExpectExperimentTemplateReplicaSetNumReplicas("experiment-with-multiport-service", "test", 1). + ExpectExperimentServiceCount("experiment-with-multiport-service", 1). + When(). + WaitForExperimentPhase("experiment-with-multiport-service", "Successful"). + WaitForExperimentCondition("experiment-with-multiport-service", func(ex *rov1.Experiment) bool { + return s.GetReplicaSetFromExperiment(ex, "test").Status.Replicas == 0 + }, "number-of-rs-pods-meet", fixtures.E2EWaitTimeout). + Then(). + ExpectExperimentTemplateReplicaSetNumReplicas("experiment-with-multiport-service", "test", 0). + ExpectExperimentServiceCount("experiment-with-multiport-service", 0) +} + func (s *ExperimentSuite) TestExperimentWithDryRunMetrics() { g := s.Given() g.ApplyManifests("@functional/experiment-dry-run-analysis.yaml") diff --git a/test/e2e/functional/experiment-with-multiport-service.yaml b/test/e2e/functional/experiment-with-multiport-service.yaml new file mode 100644 index 0000000000..a9cb44da60 --- /dev/null +++ b/test/e2e/functional/experiment-with-multiport-service.yaml @@ -0,0 +1,37 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Experiment +metadata: + name: experiment-with-multiport-service +spec: + duration: 10s + scaleDownDelaySeconds: 5 + # List of pod template specs to run in the experiment as ReplicaSets + templates: + - name: test + replicas: 1 + service: {} + selector: + matchLabels: + app: experiment-with-multiport-service + template: + metadata: + labels: + app: experiment-with-multiport-service + spec: + containers: + - name: experiment-with-multiport-service + image: nginx:1.19-alpine + resources: + requests: + memory: 16Mi + cpu: 1m + ports: + - name: testport1 + protocol: TCP + containerPort: 8080 + - name: testport2 + protocol: TCP + containerPort: 8081 + - name: testport3 + protocol: TCP + containerPort: 8082