github.com/darkowlzz/helm@v2.5.1-0.20171213183701-6707fe0468d4+incompatible/pkg/rudder/client.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package rudder // import "k8s.io/helm/pkg/rudder" 18 19 import ( 20 "fmt" 21 22 "golang.org/x/net/context" 23 "google.golang.org/grpc" 24 25 rudderAPI "k8s.io/helm/pkg/proto/hapi/rudder" 26 ) 27 28 // GrpcPort specifies port on which rudder will spawn a server 29 const ( 30 GrpcPort = 10001 31 ) 32 33 var grpcAddr = fmt.Sprintf("127.0.0.1:%d", GrpcPort) 34 35 // InstallRelease calls Rudder InstallRelease method which should create provided release 36 func InstallRelease(rel *rudderAPI.InstallReleaseRequest) (*rudderAPI.InstallReleaseResponse, error) { 37 //TODO(mkwiek): parametrize this 38 conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure()) 39 if err != nil { 40 return nil, err 41 } 42 43 defer conn.Close() 44 client := rudderAPI.NewReleaseModuleServiceClient(conn) 45 return client.InstallRelease(context.Background(), rel) 46 } 47 48 // UpgradeRelease calls Rudder UpgradeRelease method which should perform update 49 func UpgradeRelease(req *rudderAPI.UpgradeReleaseRequest) (*rudderAPI.UpgradeReleaseResponse, error) { 50 conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure()) 51 if err != nil { 52 return nil, err 53 } 54 defer conn.Close() 55 client := rudderAPI.NewReleaseModuleServiceClient(conn) 56 return client.UpgradeRelease(context.Background(), req) 57 } 58 59 // RollbackRelease calls Rudder RollbackRelease method which should perform update 60 func RollbackRelease(req *rudderAPI.RollbackReleaseRequest) (*rudderAPI.RollbackReleaseResponse, error) { 61 conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure()) 62 if err != nil { 63 return nil, err 64 } 65 defer conn.Close() 66 client := rudderAPI.NewReleaseModuleServiceClient(conn) 67 return client.RollbackRelease(context.Background(), req) 68 } 69 70 // ReleaseStatus calls Rudder ReleaseStatus method which should perform update 71 func ReleaseStatus(req *rudderAPI.ReleaseStatusRequest) (*rudderAPI.ReleaseStatusResponse, error) { 72 conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure()) 73 if err != nil { 74 return nil, err 75 } 76 defer conn.Close() 77 client := rudderAPI.NewReleaseModuleServiceClient(conn) 78 return client.ReleaseStatus(context.Background(), req) 79 } 80 81 // DeleteRelease calls Rudder DeleteRelease method which should uninstall provided release 82 func DeleteRelease(rel *rudderAPI.DeleteReleaseRequest) (*rudderAPI.DeleteReleaseResponse, error) { 83 conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure()) 84 if err != nil { 85 return nil, err 86 } 87 88 defer conn.Close() 89 client := rudderAPI.NewReleaseModuleServiceClient(conn) 90 return client.DeleteRelease(context.Background(), rel) 91 }