@@ -12,6 +12,7 @@ import (
12
12
"k8s.io/kubernetes/pkg/runtime"
13
13
"k8s.io/kubernetes/pkg/util/flowcontrol"
14
14
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
15
+ "k8s.io/kubernetes/pkg/util/sets"
15
16
"k8s.io/kubernetes/pkg/watch"
16
17
17
18
controller "github.com/openshift/origin/pkg/controller"
@@ -128,36 +129,50 @@ func (factory *DeploymentControllerFactory) Create() controller.RunnableControll
128
129
// 1. For the Recreate and Rolling strategies, strategy, use the factory's
129
130
// DeployerImage as the container image, and the factory's Environment
130
131
// as the container environment.
131
- // 2. For all Custom strategy, use the strategy's image for the container
132
- // image, and use the combination of the factory's Environment and the
133
- // strategy's environment as the container environment.
132
+ // 2. For all Custom strategies, or if the CustomParams field is set, use
133
+ // the strategy's image for the container image, and use the combination
134
+ // of the factory's Environment and the strategy's environment as the
135
+ // container environment.
134
136
//
135
137
// An error is returned if the deployment strategy type is not supported.
136
138
func (factory * DeploymentControllerFactory ) makeContainer (strategy * deployapi.DeploymentStrategy ) (* kapi.Container , error ) {
139
+ image := factory .DeployerImage
140
+ var environment []kapi.EnvVar
141
+ var command []string
142
+
143
+ set := sets .NewString ()
144
+ // Use user-defined values from the strategy input.
145
+ if p := strategy .CustomParams ; p != nil {
146
+ if len (p .Image ) > 0 {
147
+ image = p .Image
148
+ }
149
+ if len (p .Command ) > 0 {
150
+ command = p .Command
151
+ }
152
+ for _ , env := range strategy .CustomParams .Environment {
153
+ set .Insert (env .Name )
154
+ environment = append (environment , env )
155
+ }
156
+ }
157
+
137
158
// Set default environment values
138
- environment := []kapi.EnvVar {}
139
159
for _ , env := range factory .Environment {
160
+ if set .Has (env .Name ) {
161
+ continue
162
+ }
140
163
environment = append (environment , env )
141
164
}
142
165
143
166
// Every strategy type should be handled here.
144
167
switch strategy .Type {
145
- case deployapi .DeploymentStrategyTypeRecreate , deployapi .DeploymentStrategyTypeRolling :
146
- // Use the factory-configured image.
147
- return & kapi.Container {
148
- Image : factory .DeployerImage ,
149
- Env : environment ,
150
- }, nil
151
- case deployapi .DeploymentStrategyTypeCustom :
152
- // Use user-defined values from the strategy input.
153
- for _ , env := range strategy .CustomParams .Environment {
154
- environment = append (environment , env )
155
- }
156
- return & kapi.Container {
157
- Image : strategy .CustomParams .Image ,
158
- Env : environment ,
159
- }, nil
168
+ case deployapi .DeploymentStrategyTypeRecreate , deployapi .DeploymentStrategyTypeRolling , deployapi .DeploymentStrategyTypeCustom :
160
169
default :
161
170
return nil , fmt .Errorf ("unsupported deployment strategy type: %s" , strategy .Type )
162
171
}
172
+
173
+ return & kapi.Container {
174
+ Image : image ,
175
+ Command : command ,
176
+ Env : environment ,
177
+ }, nil
163
178
}
0 commit comments