-
Notifications
You must be signed in to change notification settings - Fork 113
/
worker.go
79 lines (67 loc) · 2.13 KB
/
worker.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
package testkit
import (
"fmt"
"github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/kyma-project/control-plane/components/provisioner/internal/util"
"k8s.io/apimachinery/pkg/util/intstr"
)
// TestWorker allows construction of Gardener workers
type TestWorker struct {
worker v1beta1.Worker
}
// NewTestWorker creates TestWorker and returns pointer to it, allowing to pipe the constraints
func NewTestWorker(name string) *TestWorker {
return &TestWorker{worker: v1beta1.Worker{
Name: name,
Machine: v1beta1.Machine{
Image: &v1beta1.ShootMachineImage{},
},
Volume: &v1beta1.Volume{
Type: util.PtrTo(""),
},
MaxSurge: util.PtrTo(intstr.FromInt(0)),
MaxUnavailable: util.PtrTo(intstr.FromInt(0)),
Zones: nil,
}}
}
// ToWorker returns TestWorker as *v1beta1.Worker
func (tw *TestWorker) ToWorker() v1beta1.Worker {
return tw.worker
}
// WithMachineType sets value of worker.Machine.Type
func (tw *TestWorker) WithMachineType(t string) *TestWorker {
tw.worker.Machine.Type = t
return tw
}
func (tw *TestWorker) WithMachineImageAndVersion(name string, version string) *TestWorker {
tw.worker.Machine.Image.Name = name
tw.worker.Machine.Image.Version = util.PtrTo(version)
return tw
}
// WithVolume sets value of worker.Volume Type and Size
func (tw *TestWorker) WithVolume(vType string, size int) *TestWorker {
tw.worker.Volume.Type = util.PtrTo(vType)
tw.worker.Volume.VolumeSize = fmt.Sprintf("%dGi", size)
return tw
}
// WithMinMax sets values of Minimum and Maximum
func (tw *TestWorker) WithMinMax(min, max int32) *TestWorker {
tw.worker.Minimum = min
tw.worker.Maximum = max
return tw
}
// WithMaxSurge sets value of MaxSurge
func (tw *TestWorker) WithMaxSurge(max int) *TestWorker {
tw.worker.MaxSurge = util.PtrTo(intstr.FromInt(max))
return tw
}
// WithMaxUnavailable sets value of MaxUnavailable
func (tw *TestWorker) WithMaxUnavailable(max int) *TestWorker {
tw.worker.MaxUnavailable = util.PtrTo(intstr.FromInt(max))
return tw
}
// WithZones adds zones to Zones
func (tw *TestWorker) WithZones(zones ...string) *TestWorker {
tw.worker.Zones = append(tw.worker.Zones, zones...)
return tw
}