From 32f9b058373defeee8c804cc7eba7c37823a5e1f Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Fri, 10 Jan 2025 12:53:06 +0100 Subject: [PATCH 1/4] Kubernetes provider: include v1alpha+ label when searching for jobs --- internal/kubernetes/kubernetes.go | 53 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/internal/kubernetes/kubernetes.go b/internal/kubernetes/kubernetes.go index cb8bee7..8f8a546 100644 --- a/internal/kubernetes/kubernetes.go +++ b/internal/kubernetes/kubernetes.go @@ -21,6 +21,7 @@ import ( config "github.com/eiffel-community/etos-api/internal/configs/base" "github.com/sirupsen/logrus" + v1 "k8s.io/api/batch/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -73,15 +74,24 @@ func (k *Kubernetes) IsFinished(ctx context.Context, identifier string) bool { k.logger.Error(err) return false } - jobs, err := client.BatchV1().Jobs(k.namespace).List( - ctx, - metav1.ListOptions{ - LabelSelector: fmt.Sprintf("id=%s", identifier), - }, - ) - if err != nil { - k.logger.Error(err) - return false + + var jobs v1.JobList + // Try different labels for backward compatibility: + // label id is v0 legacy, while etos.eiffel-community.github.io/id is v1alpha+ + for _, label := range []string{"id", "etos.eiffel-community.github.io/id"} { + jobs, err := client.BatchV1().Jobs(k.namespace).List( + ctx, + metav1.ListOptions{ + LabelSelector: fmt.Sprintf("%s=%s", label, identifier), + }, + ) + if err != nil { + k.logger.Error(err) + return false + } + if len(jobs.Items) > 0 { + break + } } if len(jobs.Items) == 0 { // Assume that a job is finished if it does not exist. @@ -101,14 +111,23 @@ func (k *Kubernetes) LogListenerIP(ctx context.Context, identifier string) (stri if err != nil { return "", err } - jobs, err := client.BatchV1().Jobs(k.namespace).List( - ctx, - metav1.ListOptions{ - LabelSelector: fmt.Sprintf("id=%s", identifier), - }, - ) - if err != nil { - return "", err + var jobs v1.JobList + // Try different labels for backward compatibility: + // label id is v0 legacy, while etos.eiffel-community.github.io/id is v1alpha+ + for _, label := range []string{"id", "etos.eiffel-community.github.io/id"} { + jobs, err := client.BatchV1().Jobs(k.namespace).List( + ctx, + metav1.ListOptions{ + LabelSelector: fmt.Sprintf("%s=%s", label, identifier), + }, + ) + if err != nil { + k.logger.Error(err) + return "", err + } + if len(jobs.Items) > 0 { + break + } } if len(jobs.Items) == 0 { return "", fmt.Errorf("could not find esr job with id %s", identifier) From 5c45e4ca787c0d309e33483bf1afc42ec8a8a636 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Wed, 15 Jan 2025 10:32:21 +0100 Subject: [PATCH 2/4] job label iteration moved to getJobsByIdentifier() --- internal/kubernetes/kubernetes.go | 57 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/internal/kubernetes/kubernetes.go b/internal/kubernetes/kubernetes.go index 8f8a546..1c08636 100644 --- a/internal/kubernetes/kubernetes.go +++ b/internal/kubernetes/kubernetes.go @@ -67,18 +67,13 @@ func (k *Kubernetes) clientset() (*kubernetes.Clientset, error) { return k.client, nil } -// IsFinished checks if an ESR job is finished. -func (k *Kubernetes) IsFinished(ctx context.Context, identifier string) bool { - client, err := k.clientset() - if err != nil { - k.logger.Error(err) - return false - } - - var jobs v1.JobList +// getJobsByIdentifier returns a list of jobs bound to the given testrun identifier. +func (k *Kubernetes) getJobsByIdentifier(ctx context.Context, client *kubernetes.Clientset, identifier string) (*v1.JobList, error) { // Try different labels for backward compatibility: - // label id is v0 legacy, while etos.eiffel-community.github.io/id is v1alpha+ - for _, label := range []string{"id", "etos.eiffel-community.github.io/id"} { + // - etos.eiffel-community.github.io/id is v1alpha+ + // - id is v0 legacy + var jobs *v1.JobList + for _, label := range []string{"etos.eiffel-community.github.io/id", "id"} { jobs, err := client.BatchV1().Jobs(k.namespace).List( ctx, metav1.ListOptions{ @@ -87,12 +82,27 @@ func (k *Kubernetes) IsFinished(ctx context.Context, identifier string) bool { ) if err != nil { k.logger.Error(err) - return false + return nil, err } if len(jobs.Items) > 0 { - break + return jobs, nil } } + return jobs, nil +} + +// IsFinished checks if an ESR job is finished. +func (k *Kubernetes) IsFinished(ctx context.Context, identifier string) bool { + client, err := k.clientset() + if err != nil { + k.logger.Error(err) + return false + } + jobs, err := k.getJobsByIdentifier(ctx, client, identifier) + if err != nil { + k.logger.Error(err) + return false + } if len(jobs.Items) == 0 { // Assume that a job is finished if it does not exist. k.logger.Warningf("job with id %s does not exist, assuming finished", identifier) @@ -111,23 +121,10 @@ func (k *Kubernetes) LogListenerIP(ctx context.Context, identifier string) (stri if err != nil { return "", err } - var jobs v1.JobList - // Try different labels for backward compatibility: - // label id is v0 legacy, while etos.eiffel-community.github.io/id is v1alpha+ - for _, label := range []string{"id", "etos.eiffel-community.github.io/id"} { - jobs, err := client.BatchV1().Jobs(k.namespace).List( - ctx, - metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", label, identifier), - }, - ) - if err != nil { - k.logger.Error(err) - return "", err - } - if len(jobs.Items) > 0 { - break - } + jobs, err := k.getJobsByIdentifier(ctx, client, identifier) + if err != nil { + k.logger.Error(err) + return "", err } if len(jobs.Items) == 0 { return "", fmt.Errorf("could not find esr job with id %s", identifier) From 8781930f73dc338e4a761e08653bbe70ab9daccb Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Wed, 15 Jan 2025 10:37:55 +0100 Subject: [PATCH 3/4] git version update in deploy/*/Dockerfile --- deploy/etos-executionspace/Dockerfile | 2 +- deploy/etos-iut/Dockerfile | 2 +- deploy/etos-logarea/Dockerfile | 2 +- deploy/etos-sse/Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/etos-executionspace/Dockerfile b/deploy/etos-executionspace/Dockerfile index 87b479a..4fd047e 100644 --- a/deploy/etos-executionspace/Dockerfile +++ b/deploy/etos-executionspace/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.22-alpine AS build WORKDIR /tmp/executionspace COPY . . -RUN apk add --no-cache make=4.4.1-r2 git=2.47.1-r0 && make executionspace +RUN apk add --no-cache make=4.4.1-r2 git=2.47.2-r0 && make executionspace FROM alpine:3.17.3 ARG TZ diff --git a/deploy/etos-iut/Dockerfile b/deploy/etos-iut/Dockerfile index 7502f6d..4c171f4 100644 --- a/deploy/etos-iut/Dockerfile +++ b/deploy/etos-iut/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.22-alpine AS build WORKDIR /tmp/iut COPY . . -RUN apk add --no-cache make=4.4.1-r2 git=2.47.1-r0 && make iut +RUN apk add --no-cache make=4.4.1-r2 git=2.47.2-r0 && make iut FROM alpine:3.17.3 ARG TZ diff --git a/deploy/etos-logarea/Dockerfile b/deploy/etos-logarea/Dockerfile index cca07ea..ecc28b6 100644 --- a/deploy/etos-logarea/Dockerfile +++ b/deploy/etos-logarea/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.22-alpine AS build WORKDIR /tmp/logarea COPY . . -RUN apk add --no-cache make=4.4.1-r2 git=2.47.1-r0 && make logarea +RUN apk add --no-cache make=4.4.1-r2 git=2.47.2-r0 && make logarea FROM alpine:3.17.3 ARG TZ diff --git a/deploy/etos-sse/Dockerfile b/deploy/etos-sse/Dockerfile index be6873b..68bf232 100644 --- a/deploy/etos-sse/Dockerfile +++ b/deploy/etos-sse/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.22-alpine AS build WORKDIR /tmp/sse COPY . . -RUN apk add --no-cache make=4.4.1-r2 git=2.47.1-r0 && make sse +RUN apk add --no-cache make=4.4.1-r2 git=2.47.2-r0 && make sse FROM alpine:3.17.3 ARG TZ From e268c592b2e910b4846b2eb8d4dbecfce8f7b217 Mon Sep 17 00:00:00 2001 From: Andrei Matveyeu Date: Wed, 15 Jan 2025 12:13:11 +0100 Subject: [PATCH 4/4] url update in Kubernetes.New() --- internal/executionspace/provider/kubernetes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/executionspace/provider/kubernetes.go b/internal/executionspace/provider/kubernetes.go index 97c5b71..1f7e247 100644 --- a/internal/executionspace/provider/kubernetes.go +++ b/internal/executionspace/provider/kubernetes.go @@ -34,7 +34,7 @@ func (k Kubernetes) New(db database.Opener, cfg config.Config) Provider { providerCore{ db: db, cfg: cfg, - url: fmt.Sprintf("%s/v1alpha/executor/kubernetes", cfg.Hostname()), + url: fmt.Sprintf("%s/executionspace/v1alpha/executor/kubernetes", cfg.Hostname()), executor: executor.Kubernetes( cfg.ETOSNamespace(), ),