This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollback.go
65 lines (53 loc) · 2.06 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
65
package cmd
import (
"bytes"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/kubectl"
kinternalprinters "k8s.io/kubernetes/pkg/printers/internalversion"
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
appsclient "github.com/openshift/origin/pkg/apps/generated/internalclientset"
appsinternal "github.com/openshift/origin/pkg/apps/generated/internalclientset/typed/apps/internalversion"
)
func NewDeploymentConfigRollbacker(appsClient appsclient.Interface) kubectl.Rollbacker {
return &DeploymentConfigRollbacker{dn: appsClient.Apps()}
}
// DeploymentConfigRollbacker is an implementation of the kubectl Rollbacker interface
// for deployment configs.
type DeploymentConfigRollbacker struct {
dn appsinternal.DeploymentConfigsGetter
}
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.(*appsapi.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 := &appsapi.DeploymentConfigRollback{
Name: config.Name,
UpdatedAnnotations: updatedAnnotations,
Spec: appsapi.DeploymentConfigRollbackSpec{
Revision: toRevision,
IncludeTemplate: true,
},
}
rolledback, err := r.dn.DeploymentConfigs(config.Namespace).Rollback(config.Name, rollback)
if err != nil {
return "", err
}
if dryRun {
out := bytes.NewBuffer([]byte("\n"))
kinternalprinters.DescribePodTemplate(rolledback.Spec.Template, kinternalprinters.NewPrefixWriter(out))
return out.String(), nil
}
_, err = r.dn.DeploymentConfigs(config.Namespace).Update(rolledback)
if err != nil {
return "", err
}
return "rolled back", nil
}