This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollback_generator.go
56 lines (44 loc) · 2.02 KB
/
rollback_generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package rollback
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
)
// RollbackGenerator generates a new DeploymentConfig by merging a pair of DeploymentConfigs
// in a configurable way.
type RollbackGenerator struct{}
// Generate creates a new DeploymentConfig by merging to onto from based on the options provided
// by spec. The LatestVersion of the result is unconditionally incremented, as rollback candidates are
// should be possible to be deployed manually regardless of other system behavior such as triggering.
func (g *RollbackGenerator) GenerateRollback(from, to *deployapi.DeploymentConfig, spec *deployapi.DeploymentConfigRollbackSpec) (*deployapi.DeploymentConfig, error) {
rollback := &deployapi.DeploymentConfig{}
if err := kapi.Scheme.Convert(&from, &rollback); err != nil {
return nil, fmt.Errorf("Couldn't clone 'from' deploymentConfig: %v", err)
}
// construct the candidate deploymentConfig based on the rollback spec
if spec.IncludeTemplate {
if err := kapi.Scheme.Convert(&to.Template.ControllerTemplate.Template, &rollback.Template.ControllerTemplate.Template); err != nil {
return nil, fmt.Errorf("Couldn't copy template to rollback:: %v", err)
}
}
if spec.IncludeReplicationMeta {
rollback.Template.ControllerTemplate.Replicas = to.Template.ControllerTemplate.Replicas
rollback.Template.ControllerTemplate.Selector = map[string]string{}
for k, v := range to.Template.ControllerTemplate.Selector {
rollback.Template.ControllerTemplate.Selector[k] = v
}
}
if spec.IncludeTriggers {
if err := kapi.Scheme.Convert(&to.Triggers, &rollback.Triggers); err != nil {
return nil, fmt.Errorf("Couldn't copy triggers to rollback:: %v", err)
}
}
if spec.IncludeStrategy {
if err := kapi.Scheme.Convert(&to.Template.Strategy, &rollback.Template.Strategy); err != nil {
return nil, fmt.Errorf("Couldn't copy strategy to rollback:: %v", err)
}
}
// TODO: add a new cause?
rollback.LatestVersion++
return rollback, nil
}