/
ok.go
179 lines (162 loc) · 4.65 KB
/
ok.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package test
import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
)
func OkDeploymentConfigSpec() deployapi.DeploymentConfigSpec {
return deployapi.DeploymentConfigSpec{
Replicas: 1,
Selector: OkSelector(),
Strategy: OkStrategy(),
Template: OkPodTemplate(),
Triggers: []deployapi.DeploymentTriggerPolicy{
OkImageChangeTrigger(),
},
}
}
func OkDeploymentConfigStatus(version int) deployapi.DeploymentConfigStatus {
return deployapi.DeploymentConfigStatus{
LatestVersion: version,
}
}
func OkImageChangeDetails() *deployapi.DeploymentDetails {
return &deployapi.DeploymentDetails{
Causes: []*deployapi.DeploymentCause{{
Type: deployapi.DeploymentTriggerOnImageChange,
ImageTrigger: &deployapi.DeploymentCauseImageTrigger{
From: kapi.ObjectReference{
Name: imageapi.JoinImageStreamTag("test-image-stream", imageapi.DefaultImageTag),
Kind: "ImageStreamTag",
}}}}}
}
func OkConfigChangeDetails() *deployapi.DeploymentDetails {
return &deployapi.DeploymentDetails{
Causes: []*deployapi.DeploymentCause{{
Type: deployapi.DeploymentTriggerOnConfigChange,
}}}
}
func OkStrategy() deployapi.DeploymentStrategy {
return deployapi.DeploymentStrategy{
Type: deployapi.DeploymentStrategyTypeRecreate,
Resources: kapi.ResourceRequirements{
Limits: kapi.ResourceList{
kapi.ResourceName(kapi.ResourceCPU): resource.MustParse("10"),
kapi.ResourceName(kapi.ResourceMemory): resource.MustParse("10G"),
},
},
RecreateParams: &deployapi.RecreateDeploymentStrategyParams{
TimeoutSeconds: mkintp(20),
},
}
}
func OkCustomStrategy() deployapi.DeploymentStrategy {
return deployapi.DeploymentStrategy{
Type: deployapi.DeploymentStrategyTypeCustom,
CustomParams: OkCustomParams(),
Resources: kapi.ResourceRequirements{
Limits: kapi.ResourceList{
kapi.ResourceName(kapi.ResourceCPU): resource.MustParse("10"),
kapi.ResourceName(kapi.ResourceMemory): resource.MustParse("10G"),
},
},
}
}
func OkCustomParams() *deployapi.CustomDeploymentStrategyParams {
return &deployapi.CustomDeploymentStrategyParams{
Image: "openshift/origin-deployer",
Environment: []kapi.EnvVar{
{
Name: "ENV1",
Value: "VAL1",
},
},
Command: []string{"/bin/echo", "hello", "world"},
}
}
func mkintp(i int) *int64 {
v := int64(i)
return &v
}
func OkRollingStrategy() deployapi.DeploymentStrategy {
return deployapi.DeploymentStrategy{
Type: deployapi.DeploymentStrategyTypeRolling,
RollingParams: &deployapi.RollingDeploymentStrategyParams{
UpdatePeriodSeconds: mkintp(1),
IntervalSeconds: mkintp(1),
TimeoutSeconds: mkintp(20),
},
Resources: kapi.ResourceRequirements{
Limits: kapi.ResourceList{
kapi.ResourceName(kapi.ResourceCPU): resource.MustParse("10"),
kapi.ResourceName(kapi.ResourceMemory): resource.MustParse("10G"),
},
},
}
}
func OkSelector() map[string]string {
return map[string]string{"a": "b"}
}
func OkPodTemplate() *kapi.PodTemplateSpec {
return &kapi.PodTemplateSpec{
Spec: kapi.PodSpec{
Containers: []kapi.Container{
{
Name: "container1",
Image: "registry:8080/repo1:ref1",
Env: []kapi.EnvVar{
{
Name: "ENV1",
Value: "VAL1",
},
},
ImagePullPolicy: kapi.PullIfNotPresent,
},
{
Name: "container2",
Image: "registry:8080/repo1:ref2",
ImagePullPolicy: kapi.PullIfNotPresent,
},
},
RestartPolicy: kapi.RestartPolicyAlways,
DNSPolicy: kapi.DNSClusterFirst,
},
ObjectMeta: kapi.ObjectMeta{
Labels: OkSelector(),
},
}
}
func OkConfigChangeTrigger() deployapi.DeploymentTriggerPolicy {
return deployapi.DeploymentTriggerPolicy{
Type: deployapi.DeploymentTriggerOnConfigChange,
}
}
func OkImageChangeTrigger() deployapi.DeploymentTriggerPolicy {
return deployapi.DeploymentTriggerPolicy{
Type: deployapi.DeploymentTriggerOnImageChange,
ImageChangeParams: &deployapi.DeploymentTriggerImageChangeParams{
Automatic: true,
ContainerNames: []string{
"container1",
},
From: kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: imageapi.JoinImageStreamTag("test-image-stream", imageapi.DefaultImageTag),
},
},
}
}
func OkDeploymentConfig(version int) *deployapi.DeploymentConfig {
return &deployapi.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{
Name: "config",
},
Spec: OkDeploymentConfigSpec(),
Status: OkDeploymentConfigStatus(version),
}
}
func TestDeploymentConfig(config *deployapi.DeploymentConfig) *deployapi.DeploymentConfig {
config.Spec.Test = true
return config
}