Explorar o código

Merge pull request #1056 from porter-dev/0.8.0-pod-events-managment

0.8.0 pod events managment -> dev
Nicolas Frati %!s(int64=4) %!d(string=hai) anos
pai
achega
d26c4d63cb

+ 9 - 0
cli/cmd/create.go

@@ -74,6 +74,7 @@ var name string
 var values string
 var values string
 var source string
 var source string
 var image string
 var image string
+var registryURL string
 
 
 func init() {
 func init() {
 	rootCmd.AddCommand(createCmd)
 	rootCmd.AddCommand(createCmd)
@@ -137,6 +138,13 @@ func init() {
 		"",
 		"",
 		"if the source is \"registry\", the image to use, in repository:tag format",
 		"if the source is \"registry\", the image to use, in repository:tag format",
 	)
 	)
+
+	createCmd.PersistentFlags().StringVar(
+		&registryURL,
+		"registry-url",
+		"",
+		"the registry URL to use (must exist in \"porter registries list\")",
+	)
 }
 }
 
 
 var supportedKinds = map[string]string{"web": "", "job": "", "worker": ""}
 var supportedKinds = map[string]string{"web": "", "job": "", "worker": ""}
@@ -183,6 +191,7 @@ func createFull(resp *api.AuthCheckResponse, client *api.Client, args []string)
 			},
 			},
 			Kind:        args[0],
 			Kind:        args[0],
 			ReleaseName: name,
 			ReleaseName: name,
+			RegistryURL: registryURL,
 		},
 		},
 	}
 	}
 
 

+ 8 - 1
cli/cmd/deploy/create.go

@@ -25,6 +25,7 @@ type CreateOpts struct {
 
 
 	Kind        string
 	Kind        string
 	ReleaseName string
 	ReleaseName string
+	RegistryURL string
 }
 }
 
 
 // GithubOpts are the options for linking a Github source to the app
 // GithubOpts are the options for linking a Github source to the app
@@ -367,7 +368,13 @@ func (c *CreateAgent) GetImageRepoURL(name, namespace string) (uint, string, err
 	var regID uint
 	var regID uint
 
 
 	for _, reg := range registries {
 	for _, reg := range registries {
-		if reg.URL != "" {
+		if c.CreateOpts.RegistryURL != "" {
+			if c.CreateOpts.RegistryURL == reg.URL {
+				regID = reg.ID
+				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+				break
+			}
+		} else if reg.URL != "" {
 			regID = reg.ID
 			regID = reg.ID
 			imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
 			imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
 			break
 			break

+ 1 - 1
cli/cmd/version.go

@@ -7,7 +7,7 @@ import (
 )
 )
 
 
 // Version will be linked by an ldflag during build
 // Version will be linked by an ldflag during build
-var Version string = "v0.5.0"
+var Version string = "v0.8.0"
 
 
 var versionCmd = &cobra.Command{
 var versionCmd = &cobra.Command{
 	Use:     "version",
 	Use:     "version",

+ 3 - 3
dashboard/src/shared/api.tsx

@@ -1010,7 +1010,7 @@ const getPorterAgentIsInstalled = baseApi<
   },
   },
   { project_id: number }
   { project_id: number }
 >("GET", (pathParams) => {
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.project_id}/k8s/agent/detect`;
+  return `/api/projects/${pathParams.project_id}/agent/detect`;
 });
 });
 
 
 const installPorterAgent = baseApi<
 const installPorterAgent = baseApi<
@@ -1018,8 +1018,8 @@ const installPorterAgent = baseApi<
     cluster_id: number;
     cluster_id: number;
   },
   },
   { project_id: number }
   { project_id: number }
->("GET", (pathParams) => {
-  return `/api/projects/${pathParams.project_id}/k8s/agent/deploy`;
+>("POST", (pathParams) => {
+  return `/api/projects/${pathParams.project_id}/agent/deploy`;
 });
 });
 
 
 const getEvents = baseApi<
 const getEvents = baseApi<

+ 5 - 1
server/api/api.go

@@ -316,7 +316,11 @@ func (app *App) getTokenFromRequest(r *http.Request) *token.Token {
 
 
 	reqToken = strings.TrimSpace(splitToken[1])
 	reqToken = strings.TrimSpace(splitToken[1])
 
 
-	tok, _ := token.GetTokenFromEncoded(reqToken, app.tokenConf)
+	tok, err := token.GetTokenFromEncoded(reqToken, app.tokenConf)
+
+	if err != nil {
+		return nil
+	}
 
 
 	return tok
 	return tok
 }
 }

+ 8 - 3
server/api/git_repo_handler.go

@@ -4,8 +4,6 @@ import (
 	"context"
 	"context"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
-	"github.com/porter-dev/porter/internal/models"
-	"golang.org/x/oauth2"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
 	"regexp"
 	"regexp"
@@ -13,6 +11,9 @@ import (
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 
 
+	"github.com/porter-dev/porter/internal/models"
+	"golang.org/x/oauth2"
+
 	"github.com/bradleyfalzon/ghinstallation"
 	"github.com/bradleyfalzon/ghinstallation"
 	"github.com/go-chi/chi"
 	"github.com/go-chi/chi"
 	"github.com/google/go-github/github"
 	"github.com/google/go-github/github"
@@ -20,10 +21,13 @@ import (
 
 
 // HandleListProjectGitRepos returns a list of git repos for a project
 // HandleListProjectGitRepos returns a list of git repos for a project
 func (app *App) HandleListProjectGitRepos(w http.ResponseWriter, r *http.Request) {
 func (app *App) HandleListProjectGitRepos(w http.ResponseWriter, r *http.Request) {
-
 	tok, err := app.getGithubAppOauthTokenFromRequest(r)
 	tok, err := app.getGithubAppOauthTokenFromRequest(r)
 
 
 	if err != nil {
 	if err != nil {
+		app.Logger.Warn().Err(err).
+			Str("info", "github app oauth token error").
+			Msg("")
+
 		json.NewEncoder(w).Encode(make([]*models.GitRepoExternal, 0))
 		json.NewEncoder(w).Encode(make([]*models.GitRepoExternal, 0))
 		return
 		return
 	}
 	}
@@ -35,6 +39,7 @@ func (app *App) HandleListProjectGitRepos(w http.ResponseWriter, r *http.Request
 	AuthUser, _, err := client.Users.Get(context.Background(), "")
 	AuthUser, _, err := client.Users.Get(context.Background(), "")
 
 
 	if err != nil {
 	if err != nil {
+
 		app.handleErrorInternal(err, w)
 		app.handleErrorInternal(err, w)
 		return
 		return
 	}
 	}

+ 8 - 7
server/api/integration_handler.go

@@ -7,12 +7,6 @@ import (
 	"encoding/hex"
 	"encoding/hex"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
-	"github.com/go-chi/chi"
-	"github.com/google/go-github/github"
-	"github.com/porter-dev/porter/internal/forms"
-	"github.com/porter-dev/porter/internal/oauth"
-	"golang.org/x/oauth2"
-	"gorm.io/gorm"
 	"io/ioutil"
 	"io/ioutil"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
@@ -20,6 +14,13 @@ import (
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
+	"github.com/go-chi/chi"
+	"github.com/google/go-github/github"
+	"github.com/porter-dev/porter/internal/forms"
+	"github.com/porter-dev/porter/internal/oauth"
+	"golang.org/x/oauth2"
+	"gorm.io/gorm"
+
 	"github.com/porter-dev/porter/internal/models/integrations"
 	"github.com/porter-dev/porter/internal/models/integrations"
 	ints "github.com/porter-dev/porter/internal/models/integrations"
 	ints "github.com/porter-dev/porter/internal/models/integrations"
 )
 )
@@ -583,7 +584,7 @@ func (app *App) getGithubAppOauthTokenFromRequest(r *http.Request) (*oauth2.Toke
 	oauthInt, err := app.Repo.GithubAppOAuthIntegration.ReadGithubAppOauthIntegration(user.GithubAppIntegrationID)
 	oauthInt, err := app.Repo.GithubAppOAuthIntegration.ReadGithubAppOauthIntegration(user.GithubAppIntegrationID)
 
 
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Could not get GH app integration for user %d: %s", user.ID, err.Error())
 	}
 	}
 
 
 	_, _, err = oauth.GetAccessToken(oauthInt.SharedOAuthModel,
 	_, _, err = oauth.GetAccessToken(oauthInt.SharedOAuthModel,

+ 1 - 1
server/api/user_handler.go

@@ -848,7 +848,7 @@ func (app *App) getUserIDFromRequest(r *http.Request) (uint, error) {
 	session, err := app.Store.Get(r, app.ServerConf.CookieName)
 	session, err := app.Store.Get(r, app.ServerConf.CookieName)
 
 
 	if err != nil {
 	if err != nil {
-		return 0, err
+		return 0, fmt.Errorf("could not get session: %s", err.Error())
 	}
 	}
 
 
 	sessID, ok := session.Values["user_id"]
 	sessID, ok := session.Values["user_id"]