From 6cd8202a681ca61c5150ebef59ea7945088fd6c8 Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Tue, 7 Feb 2023 14:39:31 +0100 Subject: [PATCH 1/7] Add name attribute to ServicePort Signed-off-by: Daniel Del Rio --- experiments/experiment.go | 1 + test/e2e/functional/experiment-with-service.yaml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/experiments/experiment.go b/experiments/experiment.go index 0ab5d3bb8a..2a3b731789 100644 --- a/experiments/experiment.go +++ b/experiments/experiment.go @@ -290,6 +290,7 @@ func (ec *experimentContext) createTemplateService(template *v1alpha1.TemplateSp for _, ctr := range rs.Spec.Template.Spec.Containers { for _, port := range ctr.Ports { servicePort := corev1.ServicePort{ + Name: port.Name, Protocol: port.Protocol, Port: port.ContainerPort, TargetPort: intstr.FromInt(int(port.ContainerPort)), diff --git a/test/e2e/functional/experiment-with-service.yaml b/test/e2e/functional/experiment-with-service.yaml index 76cbddaeed..f0eadaa955 100644 --- a/test/e2e/functional/experiment-with-service.yaml +++ b/test/e2e/functional/experiment-with-service.yaml @@ -26,5 +26,6 @@ spec: memory: 16Mi cpu: 1m ports: - - protocol: TCP + - name: api + protocol: TCP containerPort: 8080 From 9d1b66767c2bf7124dd43758861719436c8c7bab Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Tue, 7 Feb 2023 15:01:24 +0100 Subject: [PATCH 2/7] Format with gofmt Signed-off-by: Daniel Del Rio --- experiments/experiment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/experiment.go b/experiments/experiment.go index 2a3b731789..63d142273d 100644 --- a/experiments/experiment.go +++ b/experiments/experiment.go @@ -290,7 +290,7 @@ func (ec *experimentContext) createTemplateService(template *v1alpha1.TemplateSp for _, ctr := range rs.Spec.Template.Spec.Containers { for _, port := range ctr.Ports { servicePort := corev1.ServicePort{ - Name: port.Name, + Name: port.Name, Protocol: port.Protocol, Port: port.ContainerPort, TargetPort: intstr.FromInt(int(port.ContainerPort)), From ce7d56a053d111f411b467da9a2c0cceb6f05902 Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Tue, 7 Feb 2023 15:41:00 +0100 Subject: [PATCH 3/7] Update experiment test by adding port name Signed-off-by: Daniel Del Rio --- experiments/experiment_test.go | 1 + test/e2e/functional/experiment-with-service.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/experiments/experiment_test.go b/experiments/experiment_test.go index 0860188f65..9cde0b92a8 100644 --- a/experiments/experiment_test.go +++ b/experiments/experiment_test.go @@ -70,6 +70,7 @@ func setExperimentService(template *v1alpha1.TemplateSpec) { template.Service = &v1alpha1.TemplateService{} template.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{ { + Name: "testport", ContainerPort: 80, Protocol: "TCP", }, diff --git a/test/e2e/functional/experiment-with-service.yaml b/test/e2e/functional/experiment-with-service.yaml index f0eadaa955..2f64bb28cb 100644 --- a/test/e2e/functional/experiment-with-service.yaml +++ b/test/e2e/functional/experiment-with-service.yaml @@ -26,6 +26,6 @@ spec: memory: 16Mi cpu: 1m ports: - - name: api + - name: testport protocol: TCP containerPort: 8080 From cd1c970b4669743b8af5594eb8acad23982d7550 Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Wed, 8 Feb 2023 11:12:05 +0100 Subject: [PATCH 4/7] Include port name only when given Signed-off-by: Daniel Del Rio --- experiments/experiment.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/experiments/experiment.go b/experiments/experiment.go index 63d142273d..01d56629f0 100644 --- a/experiments/experiment.go +++ b/experiments/experiment.go @@ -290,11 +290,13 @@ func (ec *experimentContext) createTemplateService(template *v1alpha1.TemplateSp for _, ctr := range rs.Spec.Template.Spec.Containers { for _, port := range ctr.Ports { servicePort := corev1.ServicePort{ - Name: port.Name, Protocol: port.Protocol, Port: port.ContainerPort, TargetPort: intstr.FromInt(int(port.ContainerPort)), } + if port.Name != nil { + servicePort.Name = port.Name + } ports = append(ports, servicePort) } } From 18219889a47a49cd6ea962d36d7d080c427a620c Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Wed, 8 Feb 2023 11:21:54 +0100 Subject: [PATCH 5/7] Implement separate e2e tests for single unnamed port and two named ports Signed-off-by: Daniel Del Rio --- experiments/experiment.go | 2 +- test/e2e/experiment_test.go | 17 +++++++++ .../experiment-with-multiport-service.yaml | 37 +++++++++++++++++++ .../functional/experiment-with-service.yaml | 3 +- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 test/e2e/functional/experiment-with-multiport-service.yaml diff --git a/experiments/experiment.go b/experiments/experiment.go index 01d56629f0..29980309d8 100644 --- a/experiments/experiment.go +++ b/experiments/experiment.go @@ -294,7 +294,7 @@ func (ec *experimentContext) createTemplateService(template *v1alpha1.TemplateSp Port: port.ContainerPort, TargetPort: intstr.FromInt(int(port.ContainerPort)), } - if port.Name != nil { + 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..08a435cab3 100644 --- a/test/e2e/experiment_test.go +++ b/test/e2e/experiment_test.go @@ -99,6 +99,23 @@ 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"). + Sleep(time.Second*5). + Then(). + ExpectExperimentTemplateReplicaSetNumReplicas("experiment-with-multiport-service", "test", 1). + ExpectExperimentServiceCount("experiment-with-multiport-service", 1). + When(). + WaitForExperimentPhase("experiment-with-multiport-service", "Successful"). + Sleep(time.Second*15). + 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 diff --git a/test/e2e/functional/experiment-with-service.yaml b/test/e2e/functional/experiment-with-service.yaml index 2f64bb28cb..76cbddaeed 100644 --- a/test/e2e/functional/experiment-with-service.yaml +++ b/test/e2e/functional/experiment-with-service.yaml @@ -26,6 +26,5 @@ spec: memory: 16Mi cpu: 1m ports: - - name: testport - protocol: TCP + - protocol: TCP containerPort: 8080 From 912ca6cf7449c582c3fb4c2b00a1b4e9411ec648 Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Wed, 8 Feb 2023 14:47:38 +0100 Subject: [PATCH 6/7] Remove port name in experiment_test.go Signed-off-by: Daniel Del Rio --- experiments/experiment_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/experiments/experiment_test.go b/experiments/experiment_test.go index 9cde0b92a8..0860188f65 100644 --- a/experiments/experiment_test.go +++ b/experiments/experiment_test.go @@ -70,7 +70,6 @@ func setExperimentService(template *v1alpha1.TemplateSpec) { template.Service = &v1alpha1.TemplateService{} template.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{ { - Name: "testport", ContainerPort: 80, Protocol: "TCP", }, From 96a9313f3704b6efb1adc93600ce692752e8abd5 Mon Sep 17 00:00:00 2001 From: Daniel Del Rio Date: Thu, 9 Feb 2023 10:33:08 +0100 Subject: [PATCH 7/7] Replace Sleep in new multiport service experiment Signed-off-by: Daniel Del Rio --- test/e2e/experiment_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/e2e/experiment_test.go b/test/e2e/experiment_test.go index 892cfa2348..a1571ae8b0 100644 --- a/test/e2e/experiment_test.go +++ b/test/e2e/experiment_test.go @@ -108,13 +108,17 @@ func (s *ExperimentSuite) TestExperimentWithMultiportServiceAndScaleDownDelay() g.ApplyManifests("@functional/experiment-with-multiport-service.yaml") g.When(). WaitForExperimentPhase("experiment-with-multiport-service", "Running"). - Sleep(time.Second*5). + 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"). - Sleep(time.Second*15). + 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)