Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes provider: include v1alpha+ label when searching for jobs #97

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/etos-executionspace/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion deploy/etos-iut/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion deploy/etos-logarea/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion deploy/etos-sse/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/executionspace/provider/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
Expand Down
40 changes: 28 additions & 12 deletions internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -66,19 +67,38 @@ func (k *Kubernetes) clientset() (*kubernetes.Clientset, error) {
return k.client, nil
}

// 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:
// - 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{
LabelSelector: fmt.Sprintf("%s=%s", label, identifier),
},
)
if err != nil {
k.logger.Error(err)
return nil, err
}
if len(jobs.Items) > 0 {
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 := client.BatchV1().Jobs(k.namespace).List(
ctx,
metav1.ListOptions{
LabelSelector: fmt.Sprintf("id=%s", identifier),
},
)
jobs, err := k.getJobsByIdentifier(ctx, client, identifier)
if err != nil {
k.logger.Error(err)
return false
Expand All @@ -101,13 +121,9 @@ 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),
},
)
jobs, err := k.getJobsByIdentifier(ctx, client, identifier)
if err != nil {
k.logger.Error(err)
return "", err
}
if len(jobs.Items) == 0 {
Expand Down
Loading