Use rollback method on ReleaseModule interface

pull/2079/head
Dmitry Shulyak 8 years ago committed by Maciej Kwiek
parent 59af46502d
commit bd47b8444f

@ -79,7 +79,11 @@ message UpgradeReleaseResponse{
}
message RollbackReleaseRequest{
hapi.release.Release release = 1;
hapi.release.Release current = 1;
hapi.release.Release target = 2;
int64 Timeout = 3;
bool Wait = 4;
bool Recreate = 5;
}
message RollbackReleaseResponse{
hapi.release.Release release = 1;

@ -78,7 +78,10 @@ func (r *ReleaseModuleServiceServer) DeleteRelease(ctx context.Context, in *rele
// RollbackRelease is not implemented
func (r *ReleaseModuleServiceServer) RollbackRelease(ctx context.Context, in *release.RollbackReleaseRequest) (*release.RollbackReleaseResponse, error) {
grpclog.Print("rollback")
return nil, nil
c := bytes.NewBufferString(in.Current.Manifest)
t := bytes.NewBufferString(in.Target.Manifest)
err := kubeClient.Update(in.Target.Namespace, c, t, in.Recreate, in.Timeout, in.Wait)
return &release.RollbackReleaseResponse{}, err
}
// UpgradeRelease upgrades manifests using kubernetes client

@ -209,7 +209,11 @@ func (m *UpgradeReleaseResponse) GetResult() *Result {
}
type RollbackReleaseRequest struct {
Release *Release `protobuf:"bytes,1,opt,name=release" json:"release,omitempty"`
Current *Release `protobuf:"bytes,1,opt,name=current" json:"current,omitempty"`
Target *Release `protobuf:"bytes,2,opt,name=target" json:"target,omitempty"`
Timeout int64 `protobuf:"varint,3,opt,name=Timeout" json:"Timeout,omitempty"`
Wait bool `protobuf:"varint,4,opt,name=Wait" json:"Wait,omitempty"`
Recreate bool `protobuf:"varint,5,opt,name=Recreate" json:"Recreate,omitempty"`
}
func (m *RollbackReleaseRequest) Reset() { *m = RollbackReleaseRequest{} }
@ -217,9 +221,16 @@ func (m *RollbackReleaseRequest) String() string { return proto.Compa
func (*RollbackReleaseRequest) ProtoMessage() {}
func (*RollbackReleaseRequest) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{9} }
func (m *RollbackReleaseRequest) GetRelease() *Release {
func (m *RollbackReleaseRequest) GetCurrent() *Release {
if m != nil {
return m.Release
return m.Current
}
return nil
}
func (m *RollbackReleaseRequest) GetTarget() *Release {
if m != nil {
return m.Target
}
return nil
}
@ -478,38 +489,38 @@ var _ReleaseModuleService_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("hapi/release/modules.proto", fileDescriptor2) }
var fileDescriptor2 = []byte{
// 520 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xbc, 0x55, 0x51, 0x6f, 0xd3, 0x30,
0x10, 0x6e, 0x9a, 0xad, 0x5d, 0xae, 0x0c, 0x22, 0xab, 0xe9, 0xa2, 0x3c, 0x55, 0x1e, 0x48, 0x7d,
0x80, 0x56, 0x2a, 0xaf, 0xbc, 0x40, 0x57, 0xb6, 0x09, 0x91, 0x49, 0x0e, 0xdd, 0xa4, 0x49, 0x48,
0x78, 0xdd, 0x51, 0x22, 0xdc, 0xa4, 0x38, 0x4e, 0xe1, 0xef, 0xf1, 0x77, 0xf8, 0x15, 0x28, 0x69,
0x32, 0x2d, 0x26, 0x6c, 0x9a, 0x26, 0xf5, 0xa9, 0x3e, 0xdf, 0xd7, 0xcf, 0xf7, 0x9d, 0xef, 0x73,
0xc0, 0xfb, 0xc6, 0x57, 0xe1, 0x48, 0xa2, 0x40, 0x9e, 0xe0, 0x68, 0x19, 0x5f, 0xa7, 0x02, 0x93,
0xe1, 0x4a, 0xc6, 0x2a, 0x26, 0x4f, 0xb2, 0xdc, 0xb0, 0xc8, 0x79, 0x55, 0x64, 0xf1, 0xbb, 0x41,
0x52, 0x01, 0x2d, 0x86, 0x49, 0x2a, 0x14, 0x21, 0xb0, 0x13, 0x46, 0x5f, 0x63, 0xd7, 0xe8, 0x1b,
0x03, 0x8b, 0xe5, 0x6b, 0x62, 0x83, 0x29, 0xe2, 0x85, 0xdb, 0xec, 0x9b, 0x03, 0x8b, 0x65, 0x4b,
0xfa, 0x06, 0x5a, 0x81, 0xe2, 0x2a, 0x4d, 0x48, 0x07, 0xda, 0x33, 0xff, 0x83, 0x7f, 0x76, 0xe1,
0xdb, 0x8d, 0x2c, 0x08, 0x66, 0x93, 0xc9, 0x34, 0x08, 0x6c, 0x83, 0xec, 0x83, 0x35, 0xf3, 0x27,
0x27, 0x6f, 0xfd, 0xe3, 0xe9, 0x91, 0xdd, 0x24, 0x16, 0xec, 0x4e, 0x19, 0x3b, 0x63, 0xb6, 0x49,
0x0f, 0xc0, 0x39, 0x47, 0x99, 0x84, 0x71, 0xc4, 0x36, 0x55, 0x30, 0xfc, 0x91, 0x62, 0xa2, 0xe8,
0x7b, 0xe8, 0xe9, 0x89, 0x64, 0x15, 0x47, 0x09, 0x66, 0x65, 0x45, 0x7c, 0x89, 0x65, 0x59, 0xd9,
0x9a, 0xb8, 0xd0, 0x5e, 0x6f, 0xd0, 0x6e, 0x33, 0xdf, 0x2e, 0x43, 0x7a, 0x02, 0xce, 0x69, 0x94,
0x28, 0x2e, 0x44, 0xf5, 0x00, 0x32, 0x82, 0x76, 0x21, 0x3c, 0x67, 0xea, 0x8c, 0x9d, 0xe1, 0xed,
0x1e, 0x0d, 0x4b, 0x78, 0x89, 0xa2, 0x3f, 0xa1, 0xa7, 0x33, 0x15, 0x15, 0x3d, 0x94, 0x8a, 0xbc,
0x84, 0x96, 0xcc, 0x7b, 0x9c, 0x57, 0xdb, 0x19, 0x77, 0x75, 0x7c, 0x96, 0x63, 0x05, 0x86, 0x1e,
0x43, 0xf7, 0x08, 0x05, 0x2a, 0x7c, 0xac, 0x82, 0x35, 0x38, 0x1a, 0xd1, 0x76, 0x04, 0xfc, 0x36,
0xc0, 0x99, 0xad, 0x16, 0x92, 0x5f, 0xd7, 0x48, 0x98, 0xa7, 0x52, 0x62, 0xa4, 0xee, 0x39, 0xb8,
0x40, 0x91, 0x57, 0xd0, 0x52, 0x5c, 0x2e, 0xb0, 0x3c, 0xf8, 0x3f, 0xf8, 0x02, 0x94, 0xcd, 0xc5,
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es of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xd4, 0x55, 0xc1, 0x6e, 0xd3, 0x40,
0x10, 0x8d, 0xe3, 0x36, 0xa9, 0x27, 0x14, 0xac, 0x55, 0x9c, 0x5a, 0x3e, 0x45, 0x5b, 0x90, 0x72,
0x80, 0x44, 0x0a, 0x57, 0x2e, 0x90, 0x86, 0x16, 0x21, 0x5c, 0x69, 0x4d, 0x5a, 0xa9, 0x12, 0x12,
0xdb, 0x74, 0x08, 0x16, 0x1b, 0x3b, 0xac, 0xd7, 0x81, 0xdf, 0x83, 0xcf, 0xe1, 0x2b, 0x90, 0x1d,
0xbb, 0xaa, 0x17, 0xd3, 0x0a, 0x21, 0x45, 0xea, 0x29, 0x33, 0x9e, 0x97, 0xb7, 0x33, 0xcf, 0xb3,
0xcf, 0xe0, 0x7d, 0xe6, 0xab, 0x70, 0x24, 0x51, 0x20, 0x4f, 0x70, 0xb4, 0x8c, 0xaf, 0x52, 0x81,
0xc9, 0x70, 0x25, 0x63, 0x15, 0x93, 0x07, 0x59, 0x6d, 0x58, 0xd4, 0xbc, 0x2a, 0xb2, 0xf8, 0xdd,
0x20, 0xa9, 0x80, 0x16, 0xc3, 0x24, 0x15, 0x8a, 0x10, 0xd8, 0x09, 0xa3, 0x4f, 0xb1, 0x6b, 0xf4,
0x8d, 0x81, 0xc5, 0xf2, 0x98, 0xd8, 0x60, 0x8a, 0x78, 0xe1, 0x36, 0xfb, 0xe6, 0xc0, 0x62, 0x59,
0x48, 0x5f, 0x40, 0x2b, 0x50, 0x5c, 0xa5, 0x09, 0xe9, 0x40, 0x7b, 0xe6, 0xbf, 0xf5, 0x4f, 0xcf,
0x7d, 0xbb, 0x91, 0x25, 0xc1, 0x6c, 0x32, 0x99, 0x06, 0x81, 0x6d, 0x90, 0x7d, 0xb0, 0x66, 0xfe,
0xe4, 0xe4, 0xa5, 0x7f, 0x3c, 0x3d, 0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b9, 0x44,
0xae, 0xd0, 0xdd, 0xcd, 0x9f, 0x5f, 0xe7, 0xd9, 0xdb, 0xd7, 0x47, 0xd8, 0x8e, 0x78, 0x3f, 0x0d,
0xe8, 0xb1, 0x58, 0x88, 0x4b, 0x3e, 0xff, 0x72, 0x6f, 0xd5, 0xfb, 0x0e, 0x07, 0x7f, 0xcc, 0xb0,
0x15, 0xf9, 0xc6, 0xbf, 0x4c, 0xe8, 0x16, 0x14, 0xef, 0x72, 0x47, 0x0c, 0x50, 0xae, 0xc3, 0x39,
0x92, 0x33, 0x68, 0x17, 0x06, 0x43, 0x0e, 0xab, 0x0c, 0xb5, 0x86, 0xe4, 0x3d, 0xbe, 0x1d, 0xb4,
0x99, 0x86, 0x36, 0xc8, 0x07, 0x78, 0x58, 0xb5, 0x09, 0x9d, 0xbe, 0xd6, 0x8e, 0x74, 0xfa, 0x7a,
0xa7, 0xa1, 0x0d, 0x72, 0x01, 0xfb, 0x95, 0x3b, 0x4c, 0x68, 0xf5, 0x8f, 0x75, 0x4e, 0xe1, 0x1d,
0xde, 0x8a, 0xb9, 0xe6, 0xfe, 0x08, 0x8f, 0xb4, 0xb7, 0x44, 0xb4, 0xb6, 0xea, 0x17, 0xd1, 0x7b,
0x72, 0x07, 0xea, 0xa6, 0x38, 0xd5, 0x5b, 0xa4, 0x8b, 0x53, 0x6b, 0x13, 0xba, 0x38, 0xf5, 0x17,
0x91, 0x36, 0x5e, 0x59, 0x17, 0xe5, 0x96, 0x5c, 0xb6, 0xf2, 0xaf, 0xd9, 0xf3, 0xdf, 0x01, 0x00,
0x00, 0xff, 0xff, 0x6c, 0xb6, 0x1e, 0x06, 0x15, 0x07, 0x00, 0x00,
}

@ -17,21 +17,19 @@ limitations under the License.
package rudder // import "k8s.io/helm/pkg/rudder"
import (
"fmt"
"golang.org/x/net/context"
"google.golang.org/grpc"
"k8s.io/helm/pkg/proto/hapi/release"
)
// GrpcAddr is port number for accessing Rudder service
var GrpcAddr = 10001
// GrpcAddr is an address that should be used to access Rudder service
const GrpcAddr = "127.0.0.1:10001"
// InstallRelease calls Rudder InstallRelease method which should create provided release
func InstallRelease(rel *release.InstallReleaseRequest) (*release.InstallReleaseResponse, error) {
//TODO(mkwiek): parametrize this
conn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", GrpcAddr), grpc.WithInsecure())
conn, err := grpc.Dial(GrpcAddr, grpc.WithInsecure())
if err != nil {
return nil, err
}
@ -41,9 +39,9 @@ func InstallRelease(rel *release.InstallReleaseRequest) (*release.InstallRelease
return client.InstallRelease(context.Background(), rel)
}
// UpgradeReleas calls Rudder UpgradeRelease method which should perform update
// UpgradeRelease calls Rudder UpgradeRelease method which should perform update
func UpgradeRelease(req *release.UpgradeReleaseRequest) (*release.UpgradeReleaseResponse, error) {
conn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", GrpcAddr), grpc.WithInsecure())
conn, err := grpc.Dial(GrpcAddr, grpc.WithInsecure())
if err != nil {
return nil, err
}
@ -51,3 +49,14 @@ func UpgradeRelease(req *release.UpgradeReleaseRequest) (*release.UpgradeRelease
client := release.NewReleaseModuleServiceClient(conn)
return client.UpgradeRelease(context.Background(), req)
}
// RollbackRelease calls Rudder RollbackRelease method which should perform update
func RollbackRelease(req *release.RollbackReleaseRequest) (*release.RollbackReleaseResponse, error) {
conn, err := grpc.Dial(GrpcAddr, grpc.WithInsecure())
if err != nil {
return nil, err
}
defer conn.Close()
client := release.NewReleaseModuleServiceClient(conn)
return client.RollbackRelease(context.Background(), req)
}

@ -29,6 +29,7 @@ import (
type ReleaseModule interface {
Create(r *release.Release, req *services.InstallReleaseRequest, env *environment.Environment) error
Update(current, target *release.Release, req *services.UpdateReleaseRequest, env *environment.Environment) error
Rollback(current, target *release.Release, req *services.RollbackReleaseRequest, env *environment.Environment) error
}
// LocalReleaseModule is a local implementation of ReleaseModule
@ -46,6 +47,12 @@ func (m *LocalReleaseModule) Update(current, target *release.Release, req *servi
return env.KubeClient.Update(target.Namespace, c, t, req.Recreate, req.Timeout, req.Wait)
}
func (m *LocalReleaseModule) Rollback(current, target *release.Release, req *services.RollbackReleaseRequest, env *environment.Environment) error {
c := bytes.NewBufferString(current.Manifest)
t := bytes.NewBufferString(target.Manifest)
return env.KubeClient.Update(target.Namespace, c, t, req.Recreate, req.Timeout, req.Wait)
}
// RemoteReleaseModule is a ReleaseModule which calls Rudder service to operate on a release
type RemoteReleaseModule struct{}
@ -58,13 +65,26 @@ func (m *RemoteReleaseModule) Create(r *release.Release, req *services.InstallRe
// Update calls rudder.UpgradeRelease
func (m *RemoteReleaseModule) Update(current, target *release.Release, req *services.UpdateReleaseRequest, env *environment.Environment) error {
req := &release.UpgradeReleaseRequest{
upgrade := &release.UpgradeReleaseRequest{
Current: current,
Target: target,
Recreate: req.Recreate,
Timeout: req.Timeout,
Wait: req.Wait,
}
_, err := rudder.UpgradeRelease(upgrade)
return err
}
// Rollback calls rudder.Rollback
func (m *RemoteReleaseModule) Rollback(current, target *release.Release, req *services.RollbackReleaseRequest, env *environment.Environment) error {
rollback := &release.RollbackReleaseRequest{
Current: current,
Target: target,
Recreate: req.Recreate,
Timeout: req.Timeout,
Wait: req.Wait,
}
_, err := rudder.UpgradeRelease(req)
_, err := rudder.RollbackRelease(rollback)
return err
}

@ -519,7 +519,7 @@ func (s *ReleaseServer) performRollback(currentRelease, targetRelease *release.R
}
}
if err := s.ReleaseModule.Update(currentRelease, targetRelease, req); err != nil {
if err := s.ReleaseModule.Rollback(currentRelease, targetRelease, req, s.env); err != nil {
msg := fmt.Sprintf("Rollback %q failed: %s", targetRelease.Name, err)
log.Printf("warning: %s", msg)
currentRelease.Info.Status.Code = release.Status_SUPERSEDED
@ -893,8 +893,12 @@ func (s *ReleaseServer) performRelease(r *release.Release, req *services.Install
// update new release with next revision number
// so as to append to the old release's history
r.Version = old.Version + 1
if err := s.ReleaseModule.Update(old, r, req, s.env); err != nil {
updateReq := &services.UpdateReleaseRequest{
Wait: req.Wait,
Recreate: false,
Timeout: req.Timeout,
}
if err := s.ReleaseModule.Update(old, r, updateReq, s.env); err != nil {
msg := fmt.Sprintf("Release replace %q failed: %s", r.Name, err)
log.Printf("warning: %s", msg)
old.Info.Status.Code = release.Status_SUPERSEDED

Loading…
Cancel
Save