Skip to content

Commit

Permalink
chore: collab on failing porter integration
Browse files Browse the repository at this point in the history
Signed-off-by: Brian DeGeeter <[email protected]>
  • Loading branch information
Brian DeGeeter committed Jan 13, 2023
1 parent cb40dc8 commit 1f00986
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 20 deletions.
51 changes: 38 additions & 13 deletions pkg/grpc/installation/installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion proto/porterapis/installation/v1alpha1/installation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message Installation {
InstallationStatus status = 5;
}

//Installations
message ListInstallationsRequest {
string name = 1;
string namespace = 2;
Expand All @@ -44,6 +45,9 @@ message ListInstallationsResponse {
message InstallationRequest {
Installation installation = 1;
}


//InstallationRuns
message InstallationRun {
int64 id = 1;
Installation installation = 2;
Expand All @@ -56,5 +60,5 @@ message ListInstallationRunsResponse {
message InstallationRunRequest {
InstallationRun run = 1;
}

//InstallationRunOutputs
message ListInstallationRunOutputsResponse {}
2 changes: 1 addition & 1 deletion proto/porterapis/porter/v1alpha1/porter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
3 changes: 3 additions & 0 deletions tests/grpc/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ 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"
)

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)
Expand Down
7 changes: 5 additions & 2 deletions tests/grpc/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1f00986

Please sign in to comment.