Skip to content

Commit

Permalink
Merge branch 'main' into vsukhin/feature/run-workflow-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Nov 13, 2024
2 parents 970d017 + 39fbcdc commit 28e5972
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 21 deletions.
5 changes: 4 additions & 1 deletion cmd/kubectl-testkube/commands/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func GetClient(cmd *cobra.Command) (client.Client, string, error) {

if cfg.CloudContext.ApiKey != "" && cfg.CloudContext.RefreshToken != "" {
var refreshToken string
authURI := fmt.Sprintf("%s/idp", cfg.CloudContext.ApiUri)
authURI := cfg.CloudContext.AuthUri
if cfg.CloudContext.AuthUri == "" {
authURI = fmt.Sprintf("%s/idp", cfg.CloudContext.ApiUri)
}
token, refreshToken, err = cloudlogin.CheckAndRefreshToken(context.Background(), authURI, cfg.CloudContext.ApiKey, cfg.CloudContext.RefreshToken)
if err != nil {
// Error: failed refreshing, go thru login flow
Expand Down
14 changes: 12 additions & 2 deletions cmd/kubectl-testkube/commands/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,20 @@ func PopulateLoginDataToContext(orgID, envID, token, refreshToken, dockerContain
if options.Master.AgentToken != "" {
cfg.CloudContext.AgentKey = options.Master.AgentToken
}
if options.Master.URIs.Api != "" {
cfg.CloudContext.AgentUri = options.Master.URIs.Api
if options.Master.URIs.Agent != "" {
cfg.CloudContext.AgentUri = options.Master.URIs.Agent
}
if options.Master.URIs.Ui != "" {
cfg.CloudContext.UiUri = options.Master.URIs.Ui
}
if options.Master.URIs.Api != "" {
cfg.CloudContext.ApiUri = options.Master.URIs.Api
if options.Master.URIs.Agent == "" {
cfg.CloudContext.AgentUri = options.Master.URIs.Api
}
}
if options.Master.URIs.Auth != "" {
cfg.CloudContext.AuthUri = options.Master.URIs.Auth
}
cfg.ContextType = config.ContextTypeCloud
cfg.CloudContext.OrganizationId = orgID
Expand Down Expand Up @@ -349,6 +355,10 @@ func PopulateAgentDataToContext(options HelmOptions, cfg config.Data) error {
cfg.CloudContext.ApiUri = options.Master.URIs.Api
updated = true
}
if options.Master.URIs.Auth != "" {
cfg.CloudContext.AuthUri = options.Master.URIs.Auth
updated = true
}
if options.Master.IdToken != "" {
cfg.CloudContext.ApiKey = options.Master.IdToken
updated = true
Expand Down
20 changes: 12 additions & 8 deletions cmd/kubectl-testkube/commands/docker/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand All @@ -14,18 +15,15 @@ import (
"github.com/kubeshop/testkube/pkg/ui"
)

const (
StableReleasePlaceholder = "<latest-stable-release>"
)

func NewInitCmd() *cobra.Command {
var noLogin bool // ignore ask for login
var dockerContainerName, dockerImage string
var options common.HelmOptions

latestVersion, err := common.GetLatestVersion()
ui.ExitOnError("Gettong latest version", err)

if latestVersion != "" {
latestVersion = ":" + latestVersion
}

cmd := &cobra.Command{
Use: "init",
Short: "Run Testkube Docker Agent and connect to Testkube Pro environment",
Expand All @@ -34,6 +32,12 @@ func NewInitCmd() *cobra.Command {
ui.Info("WELCOME TO")
ui.Logo()

if strings.Contains(dockerImage, StableReleasePlaceholder) {
latestVersion, err := common.GetLatestVersion()
ui.ExitOnError("Getting latest version", err)
dockerImage = strings.ReplaceAll(dockerImage, StableReleasePlaceholder, latestVersion)
}

cfg, err := config.Load()
if err != nil {
cliErr := common.NewCLIError(
Expand Down Expand Up @@ -135,7 +139,7 @@ func NewInitCmd() *cobra.Command {

cmd.Flags().BoolVarP(&noLogin, "no-login", "", false, "Ignore login prompt, set existing token later by `testkube set context`")
cmd.Flags().StringVar(&dockerContainerName, "docker-container", "testkube-agent", "Docker container name for Testkube Docker Agent")
cmd.Flags().StringVar(&dockerImage, "docker-image", "kubeshop/testkube-agent"+latestVersion, "Docker image for Testkube Docker Agent")
cmd.Flags().StringVar(&dockerImage, "docker-image", "kubeshop/testkube-agent:"+StableReleasePlaceholder, "Docker image for Testkube Docker Agent")

return cmd
}
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 @@ -22,6 +22,7 @@ type CloudContext struct {
AgentUri string `json:"agentUri,omitempty"`
RootDomain string `json:"rootDomain,omitempty"`
UiUri string `json:"uiUri,omitempty"`
AuthUri string `json:"authUri,omitempty"`
TokenType string `json:"tokenType,omitempty"`
DockerContainerName string `json:"dockerContainerName,omitempty"`
CustomAuth bool `json:"customConnector,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion cmd/tcl/kubectl-testkube/devbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This utility is used to help with development of the Agent features (like Test W
## Usage

* Login to Testkube CLI, like `testkube login`
* For local development Testkube Enterprise (Skaffold), consider `testkube login --api-uri-override=http://localhost:8099 --agent-uri-override=http://testkube-enterprise-api.tk-dev.svc.local:8089 --auth-uri-override=http://localhost:5556 --custom-auth`
* For local development Testkube Enterprise (Skaffold), consider `testkube login --api-uri-override=http://localhost:8099 --agent-uri-override=http://testkube-enterprise-api.tk-dev.svc.cluster.local:8089 --auth-uri-override=http://localhost:5556 --custom-auth`
* It's worth to create alias for that in own `.bashrc` or `.bash_profile`
* It's worth to pass a devbox name, like `-n dawid`, so it's not using random name
* For OSS version - run with `--oss` parameter
Expand Down
2 changes: 1 addition & 1 deletion cmd/tcl/kubectl-testkube/devbox/devutils/crdsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ func (c *CRDSync) processTemplate(sourcePath string, template testworkflowsv1.Te
if !bytes.Equal(v1, v2) {
c.templates[i].Template = template
c.updates = append(c.updates, CRDSyncUpdate{Template: &template, Op: CRDSyncUpdateOpUpdate})
return nil
}
return nil
}
}
c.templates = append(c.templates, CRDSyncTemplate{SourcePath: sourcePath, Template: template})
Expand Down
20 changes: 16 additions & 4 deletions cmd/tcl/kubectl-testkube/devbox/devutils/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ func (r *ossResourcesClient) CreateTestWorkflow(workflow testkube.TestWorkflow)
}

func (r *ossResourcesClient) UpdateTestWorkflow(workflow testkube.TestWorkflow) (result testkube.TestWorkflow, err error) {
workflow.Namespace = r.namespace
v, err := r.testWorkflows.Update(testworkflows.MapAPIToKube(&workflow))
prev, err := r.testWorkflows.Get(workflow.Name)
if err != nil {
return r.CreateTestWorkflow(workflow)
}
cr := testworkflows.MapAPIToKube(&workflow)
cr.Namespace = r.namespace
cr.ResourceVersion = prev.ResourceVersion
v, err := r.testWorkflows.Update(cr)
if err != nil {
return
}
Expand All @@ -72,8 +78,14 @@ func (r *ossResourcesClient) CreateTestWorkflowTemplate(template testkube.TestWo
}

func (r *ossResourcesClient) UpdateTestWorkflowTemplate(template testkube.TestWorkflowTemplate) (result testkube.TestWorkflowTemplate, err error) {
template.Namespace = r.namespace
v, err := r.testWorkflowTemplates.Update(testworkflows.MapTemplateAPIToKube(&template))
prev, err := r.testWorkflowTemplates.Get(template.Name)
if err != nil {
return r.CreateTestWorkflowTemplate(template)
}
cr := testworkflows.MapTemplateAPIToKube(&template)
cr.Namespace = r.namespace
cr.ResourceVersion = prev.ResourceVersion
v, err := r.testWorkflowTemplates.Update(cr)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/app/api/deprecatedv1/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ func (s *DeprecatedTestkubeAPI) ListTestSuiteExecutionsHandler() fiber.Handler {
}
l.Debugw("got executions totals", "totals", executionsTotals, "time", time.Since(now))
filterAllTotals := *filter.(*testresult.FilterImpl)
filterAllTotals.WithPage(0).WithPageSize(math.MaxInt64)
allExecutionsTotals, err := s.DeprecatedRepositories.TestSuiteResults().GetExecutionsTotals(ctx, filterAllTotals)
filterAllTotals.WithPage(0).WithPageSize(math.MaxInt32)
allExecutionsTotals, err := s.DeprecatedRepositories.TestSuiteResults().GetExecutionsTotals(ctx, &filterAllTotals)
if err != nil {
return s.Error(c, http.StatusInternalServerError, fmt.Errorf("%s: client could not get all executions totals: %w", errPrefix, err))
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/imageinspector/cranefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"encoding/json"
"fmt"
"regexp"
"runtime"
"strconv"
"strings"
"time"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
v1 "github.com/google/go-containerregistry/pkg/v1"
corev1 "k8s.io/api/core/v1"

"github.com/kubeshop/testkube/pkg/utils"
Expand Down Expand Up @@ -42,14 +44,21 @@ func (c *craneFetcher) Fetch(ctx context.Context, registry, image string, pullSe
}

// Select the auth
cranePlatformOption := crane.WithPlatform(&v1.Platform{OS: runtime.GOOS, Architecture: runtime.GOARCH})
craneOptions := []crane.Option{crane.WithContext(ctx)}
if len(authConfigs) > 0 {
craneOptions = append(craneOptions, crane.WithAuth(authn.FromConfig(authConfigs[0])))
}

// Fetch the image configuration
fetchedAt := time.Now()
serializedImageConfig, err := crane.Config(image, craneOptions...)
serializedImageConfig, err := crane.Config(image, append(craneOptions, cranePlatformOption)...)

// Retry again without specifying platform
if err != nil && (strings.Contains(err.Error(), "no child") || strings.Contains(err.Error(), "not known")) {
serializedImageConfig, err = crane.Config(image, craneOptions...)
}

if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo

// Load the image details when necessary
hasPodSecurityContextGroup := podConfig.SecurityContext != nil && podConfig.SecurityContext.RunAsGroup != nil
imageNames := root.GetImages(hasPodSecurityContextGroup)
imageNames := root.GetImages(!hasPodSecurityContextGroup)
images := make(map[string]*imageinspector.Info)
imageNameResolutions := map[string]string{}
for image, needsMetadata := range imageNames {
Expand Down

0 comments on commit 28e5972

Please sign in to comment.