-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: call CCP to connect project to cluster on new project creation (#…
…4169) Co-authored-by: sunguroku <[email protected]> Co-authored-by: porter-internal[bot] <108749831+porter-internal[bot]@users.noreply.github.com> Co-authored-by: jusrhee <[email protected]> Co-authored-by: d-g-town <[email protected]>
- Loading branch information
1 parent
214dba7
commit b059e3e
Showing
29 changed files
with
1,528 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"on": | ||
push: | ||
branches: | ||
- master | ||
name: Deploy to porter-sandbox | ||
jobs: | ||
build-go: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: build-go | ||
uses: ./.github/actions/build-go | ||
|
||
build-npm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: build-npm | ||
uses: ./.github/actions/build-npm | ||
|
||
porter-deploy: | ||
runs-on: ubuntu-latest | ||
needs: [build-go, build-npm] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Get Go Binaries | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: go-binaries | ||
path: bin/ | ||
- name: Get NPM static files | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: npm-static-files | ||
path: build/ | ||
- name: Set Github tag | ||
id: vars | ||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
- name: Setup porter | ||
uses: porter-dev/[email protected] | ||
- name: Deploy stack | ||
timeout-minutes: 30 | ||
run: exec porter apply -f ./porter.yaml | ||
env: | ||
PORTER_CLUSTER: "11" | ||
PORTER_HOST: https://dashboard.internal-tools.porter.run | ||
PORTER_PR_NUMBER: ${{ github.event.number }} | ||
PORTER_PROJECT: "8" | ||
PORTER_STACK_NAME: porter-sandbox | ||
PORTER_TAG: ${{ steps.vars.outputs.sha_short }} | ||
PORTER_TOKEN: ${{ secrets.PORTER_STACK_8_11 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package project | ||
|
||
import ( | ||
"net/http" | ||
|
||
"connectrpc.com/connect" | ||
porterv1 "github.com/porter-dev/api-contracts/generated/go/porter/v1" | ||
|
||
"github.com/porter-dev/porter/api/server/handlers" | ||
"github.com/porter-dev/porter/api/server/shared" | ||
"github.com/porter-dev/porter/api/server/shared/apierrors" | ||
"github.com/porter-dev/porter/api/server/shared/config" | ||
"github.com/porter-dev/porter/api/types" | ||
"github.com/porter-dev/porter/internal/analytics" | ||
"github.com/porter-dev/porter/internal/models" | ||
"github.com/porter-dev/porter/internal/telemetry" | ||
) | ||
|
||
// ConnectHandler is the handler for the POST /projects/{project_id}/connect endpoint | ||
type ConnectHandler struct { | ||
handlers.PorterHandlerReadWriter | ||
} | ||
|
||
// NewConnectHandler returns a new ConnectHandler | ||
func NewConnectHandler( | ||
config *config.Config, | ||
decoderValidator shared.RequestDecoderValidator, | ||
writer shared.ResultWriter, | ||
) *ConnectHandler { | ||
return &ConnectHandler{ | ||
PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer), | ||
} | ||
} | ||
|
||
// ServeHTTP connects a project to the hosted cluster | ||
func (p *ConnectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
ctx, span := telemetry.NewSpan(r.Context(), "connect-project-to-hosted") | ||
defer span.End() | ||
|
||
user, _ := r.Context().Value(types.UserScope).(*models.User) | ||
proj, _ := r.Context().Value(types.ProjectScope).(*models.Project) | ||
|
||
var err error | ||
resp, err := p.Config().ClusterControlPlaneClient.ConnectHostedProject(ctx, connect.NewRequest(&porterv1.ConnectHostedProjectRequest{ | ||
ProjectId: int64(proj.ID), | ||
})) | ||
if err != nil { | ||
p.HandleAPIError(w, r, apierrors.NewErrInternal(err)) | ||
return | ||
} | ||
|
||
if resp == nil || resp.Msg == nil { | ||
err = telemetry.Error(ctx, span, nil, "connect to hosted response is nil") | ||
p.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError)) | ||
return | ||
} | ||
|
||
p.WriteResult(w, r, resp.Msg.ClusterId) | ||
|
||
_ = p.Config().AnalyticsClient.Track(analytics.ProjectConnectTrack(&analytics.ProjectCreateDeleteTrackOpts{ | ||
ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(user.ID, proj.ID), | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.