diff --git a/pkg/grpc/installation/installation.go b/pkg/grpc/installation/installation.go index 4980fbbc7..ed09941d9 100644 --- a/pkg/grpc/installation/installation.go +++ b/pkg/grpc/installation/installation.go @@ -2,31 +2,56 @@ package installation import ( "context" - "log" iGRPC "get.porter.sh/porter/gen/proto/go/porterapis/installation/v1alpha1" pGRPC "get.porter.sh/porter/gen/proto/go/porterapis/porter/v1alpha1" + "get.porter.sh/porter/pkg/porter" + "get.porter.sh/porter/pkg/tracing" ) // server is used to implement helloworld.GreeterServer. type PorterServer struct { + porter *porter.Porter pGRPC.UnimplementedPorterBundleServer } -// SayHello implements helloworld.GreeterServer +func NewPorterService() (*PorterServer, error) { + p := porter.New() + return &PorterServer{porter: p}, nil +} + func (s *PorterServer) ListInstallations(ctx context.Context, in *iGRPC.ListInstallationsRequest) (*iGRPC.ListInstallationsResponse, error) { - log.Printf("IN LIST INSTALLATIONS") - inst := iGRPC.Installation{ - Name: "test installation", - Namespace: "foo", - Bundle: &iGRPC.Bundle{ - Repository: "test.repo", - Version: "v1.0.0", - }, - State: iGRPC.InstallationState_INSTALLED, - Status: iGRPC.InstallationStatus_SUCCEEDED, + ctx, log := tracing.StartSpan(ctx) + defer log.EndSpan() + + err := s.porter.Connect(ctx) + if err != nil { + return nil, err + } + defer s.porter.Close() + opts := porter.ListOptions{} + + installations, err := s.porter.ListInstallations(ctx, opts) + if err != nil { + return nil, err + } + + insts := []*iGRPC.Installation{} + for _, pInst := range installations { + inst := iGRPC.Installation{ + Name: pInst.Name, + Namespace: pInst.Namespace, + Bundle: &iGRPC.Bundle{ + Repository: pInst.Bundle.Repository, + Version: pInst.Bundle.Version, + }, + //TODO: figure this out + State: iGRPC.InstallationState_INSTALLED, + Status: iGRPC.InstallationStatus_SUCCEEDED, + } + insts = append(insts, &inst) + } - insts := []*iGRPC.Installation{&inst} res := iGRPC.ListInstallationsResponse{ Installation: insts, } diff --git a/pkg/grpc/server.go b/pkg/grpc/server.go index 0db3bfd82..c7b1dd53e 100644 --- a/pkg/grpc/server.go +++ b/pkg/grpc/server.go @@ -8,7 +8,8 @@ import ( "go.uber.org/zap" //"go.uber.org/zap/zapcore" - igrpc "get.porter.sh/porter/gen/proto/go/porterapis/installation/v1alpha1" + //igrpc "get.porter.sh/porter/gen/proto/go/porterapis/installation/v1alpha1" + pGRPC "get.porter.sh/porter/gen/proto/go/porterapis/porter/v1alpha1" "get.porter.sh/porter/pkg/grpc/installation" "get.porter.sh/porter/pkg/porter" @@ -49,8 +50,12 @@ func (s *PorterGRPCService) ListenAndServe() *grpc.Server { healthServer := health.NewServer() reflection.Register(srv) grpc_health_v1.RegisterHealthServer(srv, healthServer) - isrv := &installation.PorterServer{} - igrpc.RegisterInstallationsServer(srv, isrv) + isrv, err := installation.NewPorterService() + if err != nil { + panic(err) + } + + pGRPC.RegisterPorterBundleServer(srv, isrv) healthServer.SetServingStatus(s.config.ServiceName, grpc_health_v1.HealthCheckResponse_SERVING) go func() { diff --git a/proto/porterapis/installation/v1alpha1/installation.proto b/proto/porterapis/installation/v1alpha1/installation.proto index db0d5c75b..6d546718b 100644 --- a/proto/porterapis/installation/v1alpha1/installation.proto +++ b/proto/porterapis/installation/v1alpha1/installation.proto @@ -29,6 +29,7 @@ message Installation { InstallationStatus status = 5; } +//Installations message ListInstallationsRequest { string name = 1; string namespace = 2; @@ -44,6 +45,9 @@ message ListInstallationsResponse { message InstallationRequest { Installation installation = 1; } + + +//InstallationRuns message InstallationRun { int64 id = 1; Installation installation = 2; @@ -56,5 +60,5 @@ message ListInstallationRunsResponse { message InstallationRunRequest { InstallationRun run = 1; } - +//InstallationRunOutputs message ListInstallationRunOutputsResponse {} \ No newline at end of file diff --git a/proto/porterapis/porter/v1alpha1/porter.proto b/proto/porterapis/porter/v1alpha1/porter.proto index 8b955f904..e3cda3558 100644 --- a/proto/porterapis/porter/v1alpha1/porter.proto +++ b/proto/porterapis/porter/v1alpha1/porter.proto @@ -12,6 +12,6 @@ service PorterBundle { rpc ListInstallationRuns(installation.v1alpha1.Installation) returns(installation.v1alpha1.ListInstallationRunsResponse) {} //Returns a list of all outputs for a single installation run - //Must support a "latest" run id + //Must support a "latest" if no run id specified rpc ListInstallationRunOutputs(installation.v1alpha1.InstallationRunRequest) returns(installation.v1alpha1.ListInstallationRunOutputsResponse) {} } \ No newline at end of file diff --git a/tests/grpc/install_test.go b/tests/grpc/install_test.go index 7cc384af7..133bd22f0 100644 --- a/tests/grpc/install_test.go +++ b/tests/grpc/install_test.go @@ -7,6 +7,7 @@ import ( iGRPC "get.porter.sh/porter/gen/proto/go/porterapis/installation/v1alpha1" pGRPC "get.porter.sh/porter/gen/proto/go/porterapis/porter/v1alpha1" + "get.porter.sh/porter/pkg/portercontext" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -14,7 +15,9 @@ import ( func TestInstall_installationMessage(t *testing.T) { t.Parallel() + ctx := context.Background() + //ctx := portercontext.New() conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure()) if err != nil { t.Fatalf("failed to dial bufnet: %v", err) diff --git a/tests/grpc/test_utils.go b/tests/grpc/test_utils.go index 5d38eacf5..68a11aee6 100644 --- a/tests/grpc/test_utils.go +++ b/tests/grpc/test_utils.go @@ -45,8 +45,11 @@ func (s *TestPorterGRPCService) ListenAndServe() *grpc.Server { healthServer := health.NewServer() reflection.Register(srv) grpc_health_v1.RegisterHealthServer(srv, healthServer) - isrv := &installation.PorterServer{} - pGRPC.RegisterPorterBundleServer(srv, isrv) + pSvc, err := installation.NewPorterService() + if err != nil { + panic(err) + } + pGRPC.RegisterPorterBundleServer(srv, pSvc) healthServer.SetServingStatus("test-health", grpc_health_v1.HealthCheckResponse_SERVING) go func() {