Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
set default replicas as 1 in DeploymentConfig
Browse files Browse the repository at this point in the history
Setting no value for the "replicas" field in a DeploymentConfig
sets the value as 0, while we should be setting this value as 1.

This commit fixes that.

Fixes #357
  • Loading branch information
concaf committed Oct 13, 2017
1 parent b8538eb commit f8a159a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion docs/examples/deploymentconfig/deploymentconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
controller: deploymentconfig
name: httpd
replicas: 2
containers:
- image: centos/httpd
services:
Expand Down
12 changes: 12 additions & 0 deletions pkg/spec/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,22 @@ func (deploymentConfig *DeploymentConfigSpecMod) Fix() error {
return errors.Wrap(err, "unable to fix secrets")
}

// Fix DeploymentConfig

deploymentConfig.ControllerFields.ObjectMeta.Labels = addKeyValueToMap(appLabelKey,
deploymentConfig.ControllerFields.Name,
deploymentConfig.ControllerFields.ObjectMeta.Labels)

// If the replicas are not specified at all, we need to set the value as 1
if deploymentConfig.Replicas == nil {
deploymentConfig.Replicas = getInt32Addr(1)
}

// Since we have unmarshalled replicas in a custom defined field, we need
// to substitute the unmarshalled (and fixed) value in the internal
// DeploymentConfigSpec struct
deploymentConfig.DeploymentConfigSpec.Replicas = *deploymentConfig.Replicas

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/spec/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,13 @@ type JobSpecMod struct {
type DeploymentConfigSpecMod struct {
ControllerFields `json:",inline"`
os_deploy_v1.DeploymentConfigSpec `json:",inline"`

// Replicas is the number of desired replicas.
// We need to add this field here despite being in v1.DeploymentConfigSpec
// because the one in v1.DeploymentConfigSpec has the type as int32, which
// does not let us check if the set value is 0, is it set by the user or not
// since this field's value with default to 0. We need the default value as
// 1. Hence, we need to check if the user has set it or not.Making the type
// *int32 helps us do it, followed by substitution later on.
Replicas *int32 `json:"replicas,omitempty"`
}

0 comments on commit f8a159a

Please sign in to comment.