-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathresource_job.go
50 lines (39 loc) · 1.4 KB
/
resource_job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package nomad
import (
"github.com/jumppad-labs/hclconfig/types"
"github.com/jumppad-labs/jumppad/pkg/config"
"github.com/jumppad-labs/jumppad/pkg/config/resources/healthcheck"
"github.com/jumppad-labs/jumppad/pkg/utils"
)
// TypeNomadJob defines the string type for the Kubernetes config resource
const TypeNomadJob string = "nomad_job"
// NomadJob applies and deletes and deletes Nomad cluster jobs
type NomadJob struct {
// embedded type holding name, etc
types.ResourceMetadata `hcl:",remain"`
// Cluster is the name of the cluster to apply configuration to
Cluster NomadCluster `hcl:"cluster" json:"cluster"`
// Path of a file or directory of Job files to apply
Paths []string `hcl:"paths" validator:"filepath" json:"paths"`
// HealthCheck defines a health check for the resource
HealthCheck *healthcheck.HealthCheckNomad `hcl:"health_check,block" json:"health_check,omitempty"`
// output
// JobChecksums stores a checksum of the files or paths
JobChecksums []string `hcl:"job_checksums,optional" json:"job_checksums,omitempty"`
}
func (n *NomadJob) Process() error {
// make all the paths absolute
for i, p := range n.Paths {
n.Paths[i] = utils.EnsureAbsolute(p, n.File)
}
cfg, err := config.LoadState()
if err == nil {
// try and find the resource in the state
r, _ := cfg.FindResource(n.ID)
if r != nil {
state := r.(*NomadJob)
n.JobChecksums = state.JobChecksums
}
}
return nil
}