-
Notifications
You must be signed in to change notification settings - Fork 17
/
persistentworker.go
81 lines (61 loc) · 2.22 KB
/
persistentworker.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package instance
import (
"github.com/cirruslabs/cirrus-ci-agent/api"
"github.com/cirruslabs/cirrus-cli/pkg/parser/instance/isolation"
"github.com/cirruslabs/cirrus-cli/pkg/parser/nameable"
"github.com/cirruslabs/cirrus-cli/pkg/parser/node"
"github.com/cirruslabs/cirrus-cli/pkg/parser/parseable"
"github.com/cirruslabs/cirrus-cli/pkg/parser/parserkit"
"github.com/cirruslabs/cirrus-cli/pkg/parser/schema"
jsschema "github.com/lestrrat-go/jsschema"
)
type PersistentWorker struct {
proto api.PersistentWorkerInstance
parseable.DefaultParser
}
func NewPersistentWorker(mergedEnv map[string]string, parserKit *parserkit.ParserKit) *PersistentWorker {
pworker := &PersistentWorker{}
labelsSchema := schema.String("Labels for selection.")
pworker.OptionalField(nameable.NewSimpleNameable("labels"), labelsSchema, func(node *node.Node) error {
labels, err := node.GetStringMapping()
if err != nil {
return err
}
pworker.proto.Labels = labels
return nil
})
resourcesSchema := schema.String("Resources to acquire on the Persistent Worker.")
pworker.OptionalField(nameable.NewSimpleNameable("resources"), resourcesSchema, func(node *node.Node) error {
resources, err := node.GetFloat64Mapping(mergedEnv)
if err != nil {
return err
}
pworker.proto.ResourcesToAcquire = resources
return nil
})
isolationSchema := isolation.NewIsolation(mergedEnv, parserKit).Schema()
pworker.OptionalField(nameable.NewSimpleNameable("isolation"), isolationSchema, func(node *node.Node) error {
isolation := isolation.NewIsolation(mergedEnv, parserKit)
if err := isolation.Parse(node, parserKit); err != nil {
return err
}
pworker.proto.Isolation = isolation.Proto()
return nil
})
return pworker
}
func (pworker *PersistentWorker) Parse(
node *node.Node,
parserKit *parserkit.ParserKit,
) (*api.PersistentWorkerInstance, error) {
if err := pworker.DefaultParser.Parse(node, parserKit); err != nil {
return nil, err
}
return &pworker.proto, nil
}
func (pworker *PersistentWorker) Schema() *jsschema.Schema {
modifiedSchema := pworker.DefaultParser.Schema()
modifiedSchema.Type = jsschema.PrimitiveTypes{jsschema.ObjectType}
modifiedSchema.Description = "Persistent Worker definition."
return modifiedSchema
}