Skip to content

Commit 2239fa9

Browse files
committed
Review: factorize some duplicate code
Signed-off-by: Philippe Martin <[email protected]>
1 parent 5985a28 commit 2239fa9

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

pkg/devfile/generator/generators.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ type DeploymentParams struct {
193193
// GetDeployment gets a deployment object
194194
func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams) (*appsv1.Deployment, error) {
195195

196-
var deploySpecParams deploymentSpecParams
196+
deploySpecParams := deploymentSpecParams{
197+
PodSelectorLabels: deployParams.PodSelectorLabels,
198+
Replicas: deployParams.Replicas,
199+
}
197200
if deployParams.PodTemplateSpec == nil {
198201
// Deprecated
199202
podTemplateSpecParams := podTemplateSpecParams{
@@ -206,23 +209,15 @@ func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams)
206209
if err != nil {
207210
return nil, err
208211
}
209-
deploySpecParams = deploymentSpecParams{
210-
PodTemplateSpec: *podTemplateSpec,
211-
PodSelectorLabels: deployParams.PodSelectorLabels,
212-
Replicas: deployParams.Replicas,
213-
}
212+
deploySpecParams.PodTemplateSpec = *podTemplateSpec
214213
} else {
215214
if len(deployParams.InitContainers) > 0 ||
216215
len(deployParams.Containers) > 0 ||
217216
len(deployParams.Volumes) > 0 {
218217
return nil, errors.New("InitContainers, Containers and Volumes cannot be set when PodTemplateSpec is set in parameters")
219218
}
220219

221-
deploySpecParams = deploymentSpecParams{
222-
PodTemplateSpec: *deployParams.PodTemplateSpec,
223-
PodSelectorLabels: deployParams.PodSelectorLabels,
224-
Replicas: deployParams.Replicas,
225-
}
220+
deploySpecParams.PodTemplateSpec = *deployParams.PodTemplateSpec
226221
}
227222

228223
containerAnnotations, err := getContainerAnnotations(devfileObj, common.DevfileOptions{})

0 commit comments

Comments
 (0)