forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_pod_lifecycle.go
66 lines (54 loc) · 2.22 KB
/
config_pod_lifecycle.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
package evergreen
import (
"github.com/mongodb/anser/bsonutil"
"github.com/mongodb/grip"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var podLifecycleConfigKey = bsonutil.MustHaveTag(Settings{}, "PodLifecycle") //nolint:unused
// PodLifecycleConfig holds logging settings for the pod init process.
type PodLifecycleConfig struct {
S3BaseURL string `bson:"s3_base_url" json:"s3_base_url" yaml:"s3_base_url"`
MaxParallelPodRequests int `bson:"max_parallel_pod_requests" json:"max_parallel_pod_requests" yaml:"max_parallel_pod_requests"`
MaxPodDefinitionCleanupRate int `bson:"max_pod_definition_cleanup_rate" json:"max_pod_definition_cleanup_rate" yam:"max_pod_definition_cleanup_rate"`
MaxSecretCleanupRate int `bson:"max_secret_cleanup_rate" json:"max_secret_cleanup_rate" yaml:"max_secret_cleanup_rate"`
}
func (c *PodLifecycleConfig) SectionId() string { return "pod_lifecycle" }
func (c *PodLifecycleConfig) Get(env Environment) error {
ctx, cancel := env.Context()
defer cancel()
coll := env.DB().Collection(ConfigCollection)
res := coll.FindOne(ctx, byId(c.SectionId()))
if err := res.Err(); err != nil {
if err == mongo.ErrNoDocuments {
*c = PodLifecycleConfig{}
return nil
}
return errors.Wrapf(err, "getting config section '%s'", c.SectionId())
}
if err := res.Decode(c); err != nil {
return errors.Wrapf(err, "decoding config section '%s'", c.SectionId())
}
return nil
}
func (c *PodLifecycleConfig) Set() error {
env := GetEnvironment()
ctx, cancel := env.Context()
defer cancel()
coll := env.DB().Collection(ConfigCollection)
_, err := coll.UpdateOne(ctx, byId(c.SectionId()), bson.M{
"$set": c,
}, options.Update().SetUpsert(true))
return errors.Wrapf(err, "updating config section '%s'", c.SectionId())
}
func (c *PodLifecycleConfig) ValidateAndDefault() error {
catcher := grip.NewSimpleCatcher()
if c.MaxParallelPodRequests == 0 {
// TODO: (EVG-16217) Determine empirically if this is indeed reasonable
c.MaxParallelPodRequests = 2000
}
catcher.NewWhen(c.MaxParallelPodRequests < 0, "max parallel pod requests cannot be negative")
return catcher.Resolve()
}