1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-07-12 22:21:40 +02:00

Use UUID as podName and cleanup arguments for Kubernetes backend (#3135)

to much args are just horrible to maintain. And we already have it nice
structured stored as step.
This commit is contained in:
6543
2024-01-11 16:32:37 +01:00
committed by GitHub
parent 7756c60a33
commit d1fe86b7be
7 changed files with 201 additions and 108 deletions

View File

@ -26,11 +26,22 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)
func mkService(namespace, name string, ports []uint16, selector map[string]string) *v1.Service {
log.Trace().Str("name", name).Interface("selector", selector).Interface("ports", ports).Msg("Creating service")
const (
ServiceLabel = "service"
)
func mkService(step *types.Step, namespace string) (*v1.Service, error) {
name, err := serviceName(step)
if err != nil {
return nil, err
}
selector := map[string]string{
ServiceLabel: name,
}
var svcPorts []v1.ServicePort
for _, port := range ports {
for _, port := range step.Ports {
svcPorts = append(svcPorts, v1.ServicePort{
Name: fmt.Sprintf("port-%d", port),
Port: int32(port),
@ -48,7 +59,7 @@ func mkService(namespace, name string, ports []uint16, selector map[string]strin
Selector: selector,
Ports: svcPorts,
},
}
}, nil
}
func serviceName(step *types.Step) (string, error) {
@ -56,21 +67,12 @@ func serviceName(step *types.Step) (string, error) {
}
func startService(ctx context.Context, engine *kube, step *types.Step) (*v1.Service, error) {
name, err := serviceName(step)
if err != nil {
return nil, err
}
podName, err := podName(step)
svc, err := mkService(step, engine.config.Namespace)
if err != nil {
return nil, err
}
selector := map[string]string{
StepLabel: podName,
}
svc := mkService(engine.config.Namespace, name, step.Ports, selector)
log.Trace().Str("name", svc.Name).Interface("selector", svc.Spec.Selector).Interface("ports", svc.Spec.Ports).Msg("creating service")
return engine.client.CoreV1().Services(engine.config.Namespace).Create(ctx, svc, metav1.CreateOptions{})
}