1
0
mirror of https://github.com/rancher/types.git synced 2025-06-28 06:26:49 +00:00
types/mapper/deployment_strategy.go

48 lines
1.6 KiB
Go
Raw Normal View History

2017-11-15 23:59:47 +00:00
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
2017-11-29 21:38:39 +00:00
"github.com/rancher/norman/types/values"
2017-11-15 23:59:47 +00:00
)
type DeploymentStrategyMapper struct {
}
func (d DeploymentStrategyMapper) FromInternal(data map[string]interface{}) {
2017-11-29 21:38:39 +00:00
if values.GetValueN(data, "strategy", "type") != "Recreate" {
values.PutValue(data, "Parallel", "deploymentStrategy", "kind")
maxUnavailable := values.GetValueN(data, "strategy", "rollingUpdate", "maxUnavailable")
maxSurge := values.GetValueN(data, "strategy", "rollingUpdate", "maxSurge")
2017-11-15 23:59:47 +00:00
if !convert.IsEmpty(maxSurge) {
2017-11-29 21:38:39 +00:00
values.PutValue(data, true, "deploymentStrategy", "parallelConfig", "startFirst")
values.PutValue(data, convert.ToString(maxSurge), "batchSize")
2017-11-15 23:59:47 +00:00
} else if !convert.IsEmpty(maxUnavailable) {
2017-11-29 21:38:39 +00:00
values.PutValue(data, convert.ToString(maxUnavailable), "batchSize")
2017-11-15 23:59:47 +00:00
}
}
}
func (d DeploymentStrategyMapper) ToInternal(data map[string]interface{}) {
2017-11-29 21:38:39 +00:00
batchSize := values.GetValueN(data, "batchSize")
2017-11-15 23:59:47 +00:00
if convert.IsEmpty(batchSize) {
batchSize = 1
}
batchSize, _ = convert.ToNumber(batchSize)
2017-11-29 21:38:39 +00:00
kind, _ := values.GetValueN(data, "deploymentStrategy", "kind").(string)
2017-11-15 23:59:47 +00:00
if kind == "" || kind == "Parallel" {
2017-11-29 21:38:39 +00:00
startFirst, _ := values.GetValueN(data, "deploymentStrategy", "startFirst").(bool)
2017-11-15 23:59:47 +00:00
if startFirst {
2017-11-29 21:38:39 +00:00
values.PutValue(data, batchSize, "strategy", "rollingUpdate", "maxSurge")
2017-11-15 23:59:47 +00:00
} else {
2017-11-29 21:38:39 +00:00
values.PutValue(data, batchSize, "strategy", "rollingUpdate", "maxUnavailable")
2017-11-15 23:59:47 +00:00
}
}
}
func (d DeploymentStrategyMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
return nil
}