Skip to content

Commit

Permalink
Merge branch 'main' into vsukhin/fix/init-verbose
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>

# Conflicts:
#	cmd/kubectl-testkube/commands/pro/init.go
  • Loading branch information
vsukhin committed Nov 5, 2024
2 parents 4968f33 + 815175b commit f1d9964
Show file tree
Hide file tree
Showing 38 changed files with 3,772 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: latest
version: 'v2.3.2' # 2.4.4 fails with "no such file or directory"
args: release -f ${{ matrix.path }} --skip=publish
env:
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: latest
version: 'v2.3.2' # 2.4.4 fails with "no such file or directory"
args: release -f .goreleaser-dev.yml
env:
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: latest
version: 'v2.3.2' # 2.4.4 fails with "no such file or directory"
args: release -f ${{ matrix.path }} --skip=publish
env:
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser-pro
version: latest
version: 'v2.3.2' # 2.4.4 fails with "no such file or directory"
args: release -f .goreleaser.yml
env:
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func GetClient(cmd *cobra.Command) (client.Client, string, error) {
token, refreshToken, err = cloudlogin.CheckAndRefreshToken(context.Background(), authURI, cfg.CloudContext.ApiKey, cfg.CloudContext.RefreshToken)
if err != nil {
// Error: failed refreshing, go thru login flow
token, refreshToken, err = LoginUser(authURI)
token, refreshToken, err = LoginUser(authURI, cfg.CloudContext.CustomAuth)
if err != nil {
return nil, "", fmt.Errorf("error logging in: %w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/kubectl-testkube/commands/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ func PopulateMasterFlags(cmd *cobra.Command, opts *HelmOptions, isDockerCmd bool
cmd.Flags().StringVar(&opts.Master.LogsUrlPrefix, "logs-prefix", defaultLogsPrefix, "usually don't need to be changed [required for custom cloud mode]")
cmd.Flags().StringVar(&opts.Master.UiUrlPrefix, "ui-prefix", defaultUiPrefix, "usually don't need to be changed [required for custom cloud mode]")
cmd.Flags().StringVar(&opts.Master.RootDomain, "root-domain", defaultRootDomain, "usually don't need to be changed [required for custom cloud mode]")
cmd.Flags().BoolVar(&opts.Master.CustomAuth, "custom-auth", false, "usually don't need to be changed [required for custom cloud mode]")

// allow to override default values of all URIs
cmd.Flags().String("api-uri-override", "", "api uri override")
cmd.Flags().String("ui-uri-override", "", "ui uri override")
cmd.Flags().String("auth-uri-override", "", "auth uri override")
cmd.Flags().String("agent-uri-override", "", "agent uri override")
cmd.Flags().String("logs-uri-override", "", "logs service uri override")

agentURI := ""
if isDockerCmd {
Expand Down Expand Up @@ -165,6 +173,10 @@ func ProcessMasterFlags(cmd *cobra.Command, opts *HelmOptions, cfg *config.Data)
opts.Master.LogsUrlPrefix = cmd.Flag("logs-prefix").Value.String()
}

if cmd.Flags().Changed("custom-auth") {
opts.Master.CustomAuth = cmd.Flag("custom-auth").Value.String() == "true"
}

uris := NewMasterUris(opts.Master.ApiUrlPrefix,
opts.Master.UiUrlPrefix,
opts.Master.AgentUrlPrefix,
Expand All @@ -191,6 +203,10 @@ func ProcessMasterFlags(cmd *cobra.Command, opts *HelmOptions, cfg *config.Data)
uris.WithUiURI(cmd.Flag("ui-uri-override").Value.String())
}

if cmd.Flag("auth-uri-override") != nil && cmd.Flags().Changed("auth-uri-override") {
uris.WithAuthURI(cmd.Flag("auth-uri-override").Value.String())
}

opts.Master.URIs = uris

}
Expand Down
7 changes: 5 additions & 2 deletions cmd/kubectl-testkube/commands/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,12 @@ func PopulateCloudConfig(cfg config.Data, apiKey string, dockerContainerName *st
return cfg
}

func LoginUser(authUri string) (string, string, error) {
func LoginUser(authUri string, customConnector bool) (string, string, error) {
ui.H1("Login")
connectorID := ui.Select("Choose your login method", []string{github, gitlab})
connectorID := ""
if !customConnector {
connectorID = ui.Select("Choose your login method", []string{github, gitlab})
}

ui.Debug("Logging into cloud with parameters", authUri, connectorID)
authUrl, tokenChan, err := cloudlogin.CloudLogin(context.Background(), authUri, strings.ToLower(connectorID))
Expand Down
4 changes: 0 additions & 4 deletions cmd/kubectl-testkube/commands/context/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ func NewSetContextCmd() *cobra.Command {
cmd.Flags().StringVarP(&apiKey, "api-key", "k", "", "API Key for Testkube Pro")

// allow to override default values of all URIs
cmd.Flags().String("api-uri-override", "", "api uri override")
cmd.Flags().String("ui-uri-override", "", "ui uri override")
cmd.Flags().String("agent-uri-override", "", "agnet uri override")
cmd.Flags().String("logs-uri-override", "", "logs service uri override")
cmd.Flags().StringVar(&dockerContainerName, "docker-container", "testkube-agent", "Docker container name for Testkube Docker Agent")

common.PopulateMasterFlags(cmd, &opts, false)
Expand Down
6 changes: 3 additions & 3 deletions cmd/kubectl-testkube/commands/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func NewDashboardCmd() *cobra.Command {
cfg, err := config.Load()
ui.ExitOnError("loading config file", err)

if namespace == "" {
namespace = cfg.Namespace
if namespace != "" {
cfg.Namespace = namespace
}

if cfg.ContextType != config.ContextTypeCloud {
isDashboardRunning, _ := k8sclient.IsPodOfServiceRunning(context.Background(), cfg.Namespace, config.EnterpriseUiName)
if isDashboardRunning {
openOnPremDashboard(cmd, cfg, verbose, skipBrowser, "")
} else {
ui.Warn("No dashboard found. Is it running in the " + namespace + " namespace?")
ui.Warn("No dashboard found. Is it running in the " + cfg.Namespace + " namespace?")
}
} else {
openCloudDashboard(cfg)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/docker/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewInitCmd() *cobra.Command {
ui.H2("Saving Testkube CLI Pro context")
var token, refreshToken string
if !common.IsUserLoggedIn(cfg, options) {
token, refreshToken, err = common.LoginUser(options.Master.URIs.Auth)
token, refreshToken, err = common.LoginUser(options.Master.URIs.Auth, options.Master.CustomAuth)
sendErrTelemetry(cmd, cfg, "login", err)
ui.ExitOnError("user login", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/pro/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewConnectCmd() *cobra.Command {
)
// if no agent is passed create new environment and get its token
if opts.Master.AgentToken == "" && opts.Master.OrgId == "" && opts.Master.EnvId == "" {
token, refreshToken, err = common.LoginUser(opts.Master.URIs.Auth)
token, refreshToken, err = common.LoginUser(opts.Master.URIs.Auth, opts.Master.CustomAuth)
ui.ExitOnError("login", err)

orgId, orgName, err := common.UiGetOrganizationId(opts.Master.URIs.Api, token)
Expand Down Expand Up @@ -162,7 +162,7 @@ func NewConnectCmd() *cobra.Command {

ui.H2("Saving Testkube CLI Pro context")
if token == "" && !common.IsUserLoggedIn(cfg, opts) {
token, refreshToken, err = common.LoginUser(opts.Master.URIs.Auth)
token, refreshToken, err = common.LoginUser(opts.Master.URIs.Auth, opts.Master.CustomAuth)
ui.ExitOnError("user login", err)
}
err = common.PopulateLoginDataToContext(opts.Master.OrgId, opts.Master.EnvId, token, refreshToken, "", opts, cfg)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/pro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewInitCmd() *cobra.Command {
ui.NL()
ui.H2("Launching web browser...")
ui.NL()
token, refreshToken, err = common.LoginUser(options.Master.URIs.Auth)
token, refreshToken, err = common.LoginUser(options.Master.URIs.Auth, options.Master.CustomAuth)
sendErrTelemetry(cmd, cfg, "login", err)
ui.ExitOnError("user login", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/pro/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewLoginCmd() *cobra.Command {

common.ProcessMasterFlags(cmd, &opts, &cfg)

token, refreshToken, err := common.LoginUser(opts.Master.URIs.Auth)
token, refreshToken, err := common.LoginUser(opts.Master.URIs.Auth, opts.Master.CustomAuth)
ui.ExitOnError("getting token", err)

orgID := opts.Master.OrgId
Expand Down
3 changes: 3 additions & 0 deletions cmd/kubectl-testkube/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/pro"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/cmd/tcl/kubectl-testkube/devbox"
"github.com/kubeshop/testkube/pkg/telemetry"
"github.com/kubeshop/testkube/pkg/ui"
)
Expand Down Expand Up @@ -65,6 +66,8 @@ func init() {
RootCmd.AddCommand(NewDockerCmd())
RootCmd.AddCommand(pro.NewLoginCmd())

RootCmd.AddCommand(devbox.NewDevBoxCommand())

RootCmd.SetHelpCommand(NewHelpCmd())
}

Expand Down
1 change: 1 addition & 0 deletions cmd/kubectl-testkube/config/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type CloudContext struct {
UiUri string `json:"uiUri,omitempty"`
TokenType string `json:"tokenType,omitempty"`
DockerContainerName string `json:"dockerContainerName,omitempty"`
CustomAuth bool `json:"customConnector,omitempty"`
}

type Data struct {
Expand Down
7 changes: 7 additions & 0 deletions cmd/kubectl-testkube/config/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Master struct {
LogsUrlPrefix string `json:"logsUrlPrefix,omitempty"`
ApiUrlPrefix string `json:"apiUrlPrefix,omitempty"`
RootDomain string `json:"rootDomain,omitempty"`
CustomAuth bool `json:"customAuth,omitempty"`
Features featureflags.FeatureFlags `json:"features,omitempty"`

URIs MasterURIs `json:"uris,omitempty"`
Expand Down Expand Up @@ -52,3 +53,9 @@ func (m *MasterURIs) WithUiURI(uri string) *MasterURIs {
m.Ui = uri
return m
}

// WithUi sets whole auth URI
func (m *MasterURIs) WithAuthURI(uri string) *MasterURIs {
m.Auth = uri
return m
}
Loading

0 comments on commit f1d9964

Please sign in to comment.