e2e: jobs3 hcl vars differently (#23363)

and include jobspec and vars in registrations
(so they show up in the UI under job Definition)
This commit is contained in:
Daniel Bennett
2024-06-17 13:20:51 -05:00
committed by GitHub
parent 5a6e3d5ef0
commit 2da38ba9c4

View File

@@ -44,7 +44,7 @@ type Submission struct {
// preCleanup funcs to run before deregistering the job
preCleanup []func(*Submission)
vars *set.Set[string] // key=value
vars Vars
waitComplete *set.Set[string] // groups to wait until complete
inNamespace string
authToken string
@@ -306,6 +306,12 @@ func (sub *Submission) run() {
job.ConsulToken = pointer.Of(sub.legacyConsulToken)
}
registerOpts := &nomadapi.RegisterOptions{
Submission: &nomadapi.JobSubmission{
Source: sub.jobSpec,
Variables: sub.vars.String(),
},
}
writeOpts := &nomadapi.WriteOptions{
Namespace: sub.inNamespace,
AuthToken: sub.authToken,
@@ -313,7 +319,7 @@ func (sub *Submission) run() {
jobsAPI := sub.nomadClient.Jobs()
sub.logf("register (%s) job: %q", *job.Type, sub.jobID)
regResp, _, err := jobsAPI.Register(job, writeOpts)
regResp, _, err := jobsAPI.RegisterOpts(job, registerOpts, writeOpts)
must.NoError(sub.t, err)
if !sub.noCleanup {
@@ -527,7 +533,7 @@ func initialize(t *testing.T, filename string) *Submission {
jobID: jobID,
origJobID: jobID,
timeout: 20 * time.Second,
vars: set.New[string](0),
vars: Vars{},
waitComplete: set.New[string](0),
preCleanup: []func(*Submission){defaultPreCleanup},
}
@@ -579,10 +585,28 @@ func Verbose(on bool) Option {
// Set an HCL variable.
func Var(key, value string) Option {
return func(sub *Submission) {
sub.vars.Insert(fmt.Sprintf("%s=%s", key, value))
sub.vars[key] = value
}
}
type Vars map[string]string
func (v Vars) Slice() []string {
s := make([]string, 0, len(v))
for k, v := range v {
s = append(s, fmt.Sprintf("%s=%s", k, v))
}
return s
}
func (v Vars) String() string {
s := ""
for k, v := range v {
s = s + fmt.Sprintf("%s=%q\n", k, v)
}
return s
}
// WaitComplete will wait until all allocations of the given group are
// in the "complete" state (or timeout, or terminal with another status).
func WaitComplete(group string) Option {