forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollback.go
64 lines (52 loc) · 1.85 KB
/
rollback.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
57
58
59
60
61
62
63
64
package cmd
import (
"bytes"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/kubectl"
kinternalprinters "k8s.io/kubernetes/pkg/printers/internalversion"
"github.com/openshift/origin/pkg/client"
deployapi "github.com/openshift/origin/pkg/deploy/api"
)
func NewDeploymentConfigRollbacker(oc client.Interface) kubectl.Rollbacker {
return &DeploymentConfigRollbacker{dn: oc}
}
// DeploymentConfigRollbacker is an implementation of the kubectl Rollbacker interface
// for deployment configs.
type DeploymentConfigRollbacker struct {
dn client.DeploymentConfigsNamespacer
}
var _ kubectl.Rollbacker = &DeploymentConfigRollbacker{}
// Rollback the provided deployment config to a specific revision. If revision is zero, we will
// rollback to the previous deployment.
func (r *DeploymentConfigRollbacker) Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRun bool) (string, error) {
config, ok := obj.(*deployapi.DeploymentConfig)
if !ok {
return "", fmt.Errorf("passed object is not a deployment config: %#v", obj)
}
if config.Spec.Paused {
return "", fmt.Errorf("cannot rollback a paused config; resume it first with 'rollout resume dc/%s' and try again", config.Name)
}
rollback := &deployapi.DeploymentConfigRollback{
Name: config.Name,
UpdatedAnnotations: updatedAnnotations,
Spec: deployapi.DeploymentConfigRollbackSpec{
Revision: toRevision,
IncludeTemplate: true,
},
}
rolledback, err := r.dn.DeploymentConfigs(config.Namespace).Rollback(rollback)
if err != nil {
return "", err
}
if dryRun {
out := bytes.NewBuffer([]byte("\n"))
kinternalprinters.DescribePodTemplate(rolledback.Spec.Template, out)
return out.String(), nil
}
_, err = r.dn.DeploymentConfigs(config.Namespace).Update(rolledback)
if err != nil {
return "", err
}
return "rolled back", nil
}