forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ok.go
167 lines (153 loc) · 4.25 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
package test
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
)
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"),
},
},
}
}
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 OkRollingStrategy() deployapi.DeploymentStrategy {
mkintp := func(i int) *int64 {
v := int64(i)
return &v
}
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 OkControllerTemplate() kapi.ReplicationControllerSpec {
return kapi.ReplicationControllerSpec{
Replicas: 1,
Selector: OkSelector(),
Template: OkPodTemplate(),
}
}
func OkDeploymentTemplate() deployapi.DeploymentTemplate {
return deployapi.DeploymentTemplate{
Strategy: OkStrategy(),
ControllerTemplate: OkControllerTemplate(),
}
}
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: "ImageStream",
Name: "test-image-stream",
},
Tag: imageapi.DefaultImageTag,
},
}
}
func OkImageChangeTriggerDeprecated() deployapi.DeploymentTriggerPolicy {
return deployapi.DeploymentTriggerPolicy{
Type: deployapi.DeploymentTriggerOnImageChange,
ImageChangeParams: &deployapi.DeploymentTriggerImageChangeParams{
Automatic: true,
ContainerNames: []string{
"container1",
},
RepositoryName: "registry:8080/repo1:ref1",
Tag: imageapi.DefaultImageTag,
},
}
}
func OkDeploymentConfig(version int) *deployapi.DeploymentConfig {
return &deployapi.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{
Name: "config",
},
LatestVersion: version,
Triggers: []deployapi.DeploymentTriggerPolicy{
OkImageChangeTrigger(),
},
Template: OkDeploymentTemplate(),
}
}