@@ -146,6 +146,30 @@ func (o *DeploymentOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
146
146
147
147
// Run performs the execution of 'create deployment' sub command
148
148
func (o * DeploymentOpts ) Run () error {
149
+ deploy := o .createDeployment ()
150
+
151
+ if o .DryRunStrategy != cmdutil .DryRunClient {
152
+ createOptions := metav1.CreateOptions {}
153
+ if o .FieldManager != "" {
154
+ createOptions .FieldManager = o .FieldManager
155
+ }
156
+ if o .DryRunStrategy == cmdutil .DryRunServer {
157
+ if err := o .DryRunVerifier .HasSupport (deploy .GroupVersionKind ()); err != nil {
158
+ return err
159
+ }
160
+ createOptions .DryRun = []string {metav1 .DryRunAll }
161
+ }
162
+ var err error
163
+ deploy , err = o .Client .Deployments (o .Namespace ).Create (context .TODO (), deploy , createOptions )
164
+ if err != nil {
165
+ return fmt .Errorf ("failed to create deployment: %v" , err )
166
+ }
167
+ }
168
+
169
+ return o .PrintObj (deploy )
170
+ }
171
+
172
+ func (o * DeploymentOpts ) createDeployment () * appsv1.Deployment {
149
173
one := int32 (1 )
150
174
labels := map [string ]string {"app" : o .Name }
151
175
selector := metav1.LabelSelector {MatchLabels : labels }
@@ -154,7 +178,7 @@ func (o *DeploymentOpts) Run() error {
154
178
namespace = o .Namespace
155
179
}
156
180
157
- deploy := & appsv1.Deployment {
181
+ return & appsv1.Deployment {
158
182
TypeMeta : metav1.TypeMeta {APIVersion : appsv1 .SchemeGroupVersion .String (), Kind : "Deployment" },
159
183
ObjectMeta : metav1.ObjectMeta {
160
184
Name : o .Name ,
@@ -172,26 +196,6 @@ func (o *DeploymentOpts) Run() error {
172
196
},
173
197
},
174
198
}
175
-
176
- if o .DryRunStrategy != cmdutil .DryRunClient {
177
- createOptions := metav1.CreateOptions {}
178
- if o .FieldManager != "" {
179
- createOptions .FieldManager = o .FieldManager
180
- }
181
- if o .DryRunStrategy == cmdutil .DryRunServer {
182
- if err := o .DryRunVerifier .HasSupport (deploy .GroupVersionKind ()); err != nil {
183
- return err
184
- }
185
- createOptions .DryRun = []string {metav1 .DryRunAll }
186
- }
187
- var err error
188
- deploy , err = o .Client .Deployments (o .Namespace ).Create (context .TODO (), deploy , createOptions )
189
- if err != nil {
190
- return fmt .Errorf ("failed to create deployment: %v" , err )
191
- }
192
- }
193
-
194
- return o .PrintObj (deploy )
195
199
}
196
200
197
201
// buildPodSpec parses the image strings and assemble them into the Containers
0 commit comments