diff --git a/pkg/extpoints/interfaces.go b/pkg/extpoints/interfaces.go index 3cfa6248..8ba84479 100644 --- a/pkg/extpoints/interfaces.go +++ b/pkg/extpoints/interfaces.go @@ -2,10 +2,11 @@ package extpoints import ( "golang.org/x/net/context" + "google.golang.org/grpc" rls "k8s.io/helm/pkg/proto/hapi/services" ) type Connector interface { UID() string - Connect(context.Context) (rls.ReleaseServiceClient, error) + Connect(context.Context) (*grpc.ClientConn, rls.ReleaseServiceClient, error) } diff --git a/pkg/factory/direct_connector.go b/pkg/factory/direct_connector.go index 08889bf9..f11c2cd6 100644 --- a/pkg/factory/direct_connector.go +++ b/pkg/factory/direct_connector.go @@ -3,6 +3,7 @@ package factory import ( "github.com/appscode/swift/pkg/extpoints" "golang.org/x/net/context" + "google.golang.org/grpc" rls "k8s.io/helm/pkg/proto/hapi/services" ) @@ -20,10 +21,10 @@ func (c *DirectConnector) UID() string { return UIDDirectConnector } -func (c *DirectConnector) Connect(ctx context.Context) (rls.ReleaseServiceClient, error) { +func (c *DirectConnector) Connect(ctx context.Context) (*grpc.ClientConn, rls.ReleaseServiceClient, error) { conn, err := Connect(c.TillerEndpoint) if err != nil { - return nil, err + return nil, nil, err } - return rls.NewReleaseServiceClient(conn), nil + return conn, rls.NewReleaseServiceClient(conn), nil } diff --git a/pkg/factory/incluster_connector.go b/pkg/factory/incluster_connector.go index 51d9474b..636005a2 100644 --- a/pkg/factory/incluster_connector.go +++ b/pkg/factory/incluster_connector.go @@ -7,6 +7,7 @@ import ( "github.com/appscode/swift/pkg/extpoints" "golang.org/x/net/context" + "google.golang.org/grpc" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" apiv1 "k8s.io/client-go/pkg/api/v1" @@ -27,24 +28,24 @@ func (c *InClusterConnector) UID() string { return UIDInClusterConnector } -func (c *InClusterConnector) Connect(ctx context.Context) (rls.ReleaseServiceClient, error) { +func (c *InClusterConnector) Connect(ctx context.Context) (*grpc.ClientConn, rls.ReleaseServiceClient, error) { config, err := restclient.InClusterConfig() if err != nil { - return nil, err + return nil, nil, err } client, err := clientset.NewForConfig(config) if err != nil { - return nil, err + return nil, nil, err } addr, err := c.getTillerAddr(client) if err != nil { - return nil, err + return nil, nil, err } conn, err := Connect(addr) if err != nil { - return nil, err + return nil, nil, err } - return rls.NewReleaseServiceClient(conn), nil + return conn, rls.NewReleaseServiceClient(conn), nil } func (c *InClusterConnector) getTillerAddr(client clientset.Interface) (string, error) { diff --git a/pkg/factory/kubeconfig_connector.go b/pkg/factory/kubeconfig_connector.go index dede1004..86e9361d 100644 --- a/pkg/factory/kubeconfig_connector.go +++ b/pkg/factory/kubeconfig_connector.go @@ -3,6 +3,7 @@ package factory import ( "github.com/appscode/swift/pkg/extpoints" "golang.org/x/net/context" + "google.golang.org/grpc" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -25,24 +26,24 @@ func (c *KubeconfigConnector) UID() string { return UIDKubeconfigConnector } -func (c *KubeconfigConnector) Connect(ctx context.Context) (rls.ReleaseServiceClient, error) { +func (c *KubeconfigConnector) Connect(ctx context.Context) (*grpc.ClientConn, rls.ReleaseServiceClient, error) { config, err := c.getConfig() if err != nil { - return nil, err + return nil, nil, err } client, err := clientset.NewForConfig(config) if err != nil { - return nil, err + return nil, nil, err } addr, err := c.GetTillerAddr(client, config) if err != nil { - return nil, err + return nil, nil, err } conn, err := Connect(addr) if err != nil { - return nil, err + return nil, nil, err } - return rls.NewReleaseServiceClient(conn), nil + return conn, rls.NewReleaseServiceClient(conn), nil } func (c *KubeconfigConnector) getConfig() (*rest.Config, error) { diff --git a/pkg/release/server.go b/pkg/release/server.go index 9155c538..748a67d5 100644 --- a/pkg/release/server.go +++ b/pkg/release/server.go @@ -27,10 +27,11 @@ func newContext() context.Context { } func (s *Server) SummarizeReleases(ctx context.Context, req *proto.SummarizeReleasesRequest) (*proto.SummarizeReleasesResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } + defer conn.Close() listReq := rls.ListReleasesRequest{ Filter: req.Filter, Limit: req.Limit, @@ -89,11 +90,11 @@ func (s *Server) SummarizeReleases(ctx context.Context, req *proto.SummarizeRele // GetReleasesStatus retrieves status information for the specified release. func (s *Server) GetReleaseStatus(ctx context.Context, req *proto.GetReleaseStatusRequest) (*proto.GetReleaseStatusResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() statusReq := rls.GetReleaseStatusRequest{ Name: req.Name, Version: req.Version, @@ -113,11 +114,11 @@ func (s *Server) GetReleaseStatus(ctx context.Context, req *proto.GetReleaseStat // GetReleaseContent retrieves the release content (chart + value) for the specified release. func (s *Server) GetReleaseContent(ctx context.Context, req *proto.GetReleaseContentRequest) (*proto.GetReleaseContentResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() contentReq := rls.GetReleaseContentRequest{ Name: req.Name, Version: req.Version, @@ -146,11 +147,11 @@ func (s *Server) GetReleaseContent(ctx context.Context, req *proto.GetReleaseCon // UpdateRelease updates release content. func (s *Server) UpdateRelease(ctx context.Context, req *proto.UpdateReleaseRequest) (*proto.UpdateReleaseResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() if req.Values == nil { // (req.Values == nil) causes render error req.Values = &chart.Config{} } @@ -188,11 +189,11 @@ func (s *Server) UpdateRelease(ctx context.Context, req *proto.UpdateReleaseRequ // InstallRelease requests installation of a chart as a new release. func (s *Server) InstallRelease(ctx context.Context, req *proto.InstallReleaseRequest) (*proto.InstallReleaseResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() if req.Values == nil { // (req.Values == nil) causes render error req.Values = &chart.Config{} } @@ -228,11 +229,11 @@ func (s *Server) InstallRelease(ctx context.Context, req *proto.InstallReleaseRe // UninstallRelease requests deletion of a named release. func (s *Server) UninstallRelease(ctx context.Context, req *proto.UninstallReleaseRequest) (*proto.UninstallReleaseResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() uninstallReq := rls.UninstallReleaseRequest{ Name: req.Name, Timeout: req.Timeout, @@ -253,11 +254,11 @@ func (s *Server) UninstallRelease(ctx context.Context, req *proto.UninstallRelea // GetVersion returns the current version of the server. func (s *Server) GetVersion(ctx context.Context, req *proto.GetVersionRequest) (*proto.GetVersionResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() versionReq := rls.GetVersionRequest{} versionRes, err := rlc.GetVersion(newContext(), &versionReq) @@ -272,11 +273,11 @@ func (s *Server) GetVersion(ctx context.Context, req *proto.GetVersionRequest) ( // RollbackRelease rolls back a release to a previous version. func (s *Server) RollbackRelease(ctx context.Context, req *proto.RollbackReleaseRequest) (*proto.RollbackReleaseResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() rollbackReq := rls.RollbackReleaseRequest{ Name: req.Name, Timeout: req.Timeout, @@ -300,11 +301,11 @@ func (s *Server) RollbackRelease(ctx context.Context, req *proto.RollbackRelease // ReleaseHistory retrieves a release's history. func (s *Server) GetHistory(ctx context.Context, req *proto.GetHistoryRequest) (*proto.GetHistoryResponse, error) { - rlc, err := s.ClientFactory.Connect(ctx) + conn, rlc, err := s.ClientFactory.Connect(ctx) if err != nil { return nil, err } - + defer conn.Close() historyReq := rls.GetHistoryRequest{ Name: req.Name, Max: req.Max,