Allow using a local Docker image, e.g., for tests

This commit is contained in:
Sebastian Serth
2022-09-18 01:49:25 +02:00
committed by Sebastian Serth
parent 15b9117382
commit 7454e577e4
5 changed files with 40 additions and 8 deletions

View File

@ -42,7 +42,8 @@ var (
CertFile: "",
KeyFile: "",
},
Namespace: "default",
Namespace: "default",
DisableForcePull: false,
},
AWS: AWS{
Enabled: false,
@ -88,12 +89,13 @@ func (s *server) URL() *url.URL {
// Nomad configures the used Nomad cluster.
type Nomad struct {
Enabled bool
Address string
Port int
Token string
TLS TLS
Namespace string
Enabled bool
Address string
Port int
Token string
TLS TLS
Namespace string
DisableForcePull bool
}
// URL returns the URL for the configured Nomad cluster.

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
nomadApi "github.com/hashicorp/nomad/api"
"github.com/openHPI/poseidon/internal/config"
"github.com/openHPI/poseidon/pkg/dto"
"strconv"
"strings"
@ -146,7 +147,11 @@ func FindAndValidateDefaultTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task {
func SetForcePullFlag(job *nomadApi.Job, value bool) {
taskGroup := FindAndValidateDefaultTaskGroup(job)
task := FindAndValidateDefaultTask(taskGroup)
task.Config["force_pull"] = value
if config.Config.Nomad.DisableForcePull {
task.Config["force_pull"] = false
} else {
task.Config["force_pull"] = value
}
}
// IsEnvironmentTemplateID checks if the passed job id belongs to a template job.

View File

@ -2,6 +2,7 @@ package nomad
import (
nomadApi "github.com/hashicorp/nomad/api"
"github.com/openHPI/poseidon/internal/config"
"github.com/openHPI/poseidon/pkg/dto"
"github.com/openHPI/poseidon/tests/helpers"
"github.com/stretchr/testify/assert"
@ -96,6 +97,27 @@ func TestFindOrCreateTask(t *testing.T) {
})
}
func TestSetForcePullFlag(t *testing.T) {
_, job := helpers.CreateTemplateJob()
taskGroup := FindAndValidateDefaultTaskGroup(job)
task := FindAndValidateDefaultTask(taskGroup)
t.Run("Ignoring passed value if DisableForcePull", func(t *testing.T) {
config.Config.Nomad.DisableForcePull = true
SetForcePullFlag(job, true)
assert.Equal(t, false, task.Config["force_pull"])
})
t.Run("Using passed value if not DisableForcePull", func(t *testing.T) {
config.Config.Nomad.DisableForcePull = false
SetForcePullFlag(job, true)
assert.Equal(t, true, task.Config["force_pull"])
SetForcePullFlag(job, false)
assert.Equal(t, false, task.Config["force_pull"])
})
}
func TestIsEnvironmentTemplateID(t *testing.T) {
assert.True(t, IsEnvironmentTemplateID("template-42"))
assert.False(t, IsEnvironmentTemplateID("template-42-100"))