Use unique label selector for pod label for kubernetes services (#2723)

Co-authored-by: Julian Haseleu <julian.haseleu@dreamit.de>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
J-Ha 2023-11-04 10:35:37 +01:00 committed by GitHub
parent fc8a001b2b
commit 9af71dcc98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View file

@ -164,7 +164,7 @@ func (e *kube) SetupWorkflow(ctx context.Context, conf *types.Config, taskUUID s
return err
}
log.Trace().Str("pod-name", stepName).Msgf("Creating service: %s", step.Name)
svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
svc, err := Service(e.config.Namespace, step.Name, step.Ports)
if err != nil {
return err
}
@ -391,7 +391,7 @@ func (e *kube) DestroyWorkflow(_ context.Context, conf *types.Config, taskUUID s
if stage.Alias == "services" {
for _, step := range stage.Steps {
log.Trace().Msgf("Deleting service: %s", step.Name)
svc, err := Service(e.config.Namespace, step.Name, step.Alias, step.Ports)
svc, err := Service(e.config.Namespace, step.Name, step.Ports)
if err != nil {
return err
}

View file

@ -20,7 +20,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)
func Service(namespace, name, podName string, ports []uint16) (*v1.Service, error) {
func Service(namespace, name string, ports []uint16) (*v1.Service, error) {
var svcPorts []v1.ServicePort
for _, port := range ports {
svcPorts = append(svcPorts, v1.ServicePort{
@ -42,7 +42,7 @@ func Service(namespace, name, podName string, ports []uint16) (*v1.Service, erro
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeClusterIP,
Selector: map[string]string{
"step": podName,
"step": dnsName,
},
Ports: svcPorts,
},

View file

@ -45,7 +45,7 @@ func TestService(t *testing.T) {
}
],
"selector": {
"step": "baz"
"step": "bar"
},
"type": "ClusterIP"
},
@ -54,7 +54,7 @@ func TestService(t *testing.T) {
}
}`
s, _ := Service("foo", "bar", "baz", []uint16{1, 2, 3})
s, _ := Service("foo", "bar", []uint16{1, 2, 3})
j, err := json.Marshal(s)
assert.NoError(t, err)
assert.JSONEq(t, expected, string(j))