Skip to content

Commit

Permalink
CR-16263-check-values (#688)
Browse files Browse the repository at this point in the history
* updated to version `0.1.43`
  • Loading branch information
ATGardner authored Apr 23, 2023
1 parent a983bd4 commit a33091e
Show file tree
Hide file tree
Showing 29 changed files with 2,086 additions and 623 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.1.42
VERSION=v0.1.43

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
6 changes: 3 additions & 3 deletions cmd/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/codefresh-io/cli-v2/pkg/util"
kubeutil "github.com/codefresh-io/cli-v2/pkg/util/kube"
kustutil "github.com/codefresh-io/cli-v2/pkg/util/kust"
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
"github.com/ghodss/yaml"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -185,7 +185,7 @@ func runClusterAdd(ctx context.Context, opts *ClusterAddOptions) error {

csdpToken := cfConfig.GetCurrentContext().Token
addClusterRef := version.String()
if runtime.InstallationType == model.InstallationTypeHelm {
if runtime.InstallationType == platmodel.InstallationTypeHelm {
addClusterRef = "stable"
}

Expand Down Expand Up @@ -288,7 +288,7 @@ func ensureNoClusterNameDuplicates(ctx context.Context, name string, runtimeName
return name, nil
}

func getSuffixToClusterName(clusters []model.Cluster, name string, tempName string, counter int) int {
func getSuffixToClusterName(clusters []platmodel.Cluster, name string, tempName string, counter int) int {
for _, cluster := range clusters {
if cluster.Metadata.Name == tempName {
counter++
Expand Down
99 changes: 31 additions & 68 deletions cmd/commands/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package commands
import (
"testing"

"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
)

func Test_getSuffixToClusterName(t *testing.T) {
Expand All @@ -29,14 +29,14 @@ func Test_getSuffixToClusterName(t *testing.T) {
cluster2.Metadata.Name = "test-cluster-1"
cluster3.Metadata.Name = "test-cluster-2"

clusters := []model.Cluster{
clusters := []platmodel.Cluster{
cluster1,
cluster2,
cluster3,
}

type args struct {
clusters []model.Cluster
clusters []platmodel.Cluster
name string
tempName string
counter int
Expand Down Expand Up @@ -67,43 +67,25 @@ func Test_getSuffixToClusterName(t *testing.T) {
}

func Test_sanitizeClusterName(t *testing.T) {
type args struct {
name string
}
tests := []struct {
tests := map[string]struct {
name string
args args
want string
wantErr bool
}{
{
name: "should return sanitized string",
args: args{
name: "^-.Test!@-:cluster&*`;')test.cluster(-12_3=+::±§.",
},
want: "test----cluster------test-cluster--12-3",
wantErr: false,
},
{
name: "should return sanitized string",
args: args{
name: "^-.123test!@-:cluster&*`;')test.cluster(-12_3=+::±§.",
},
"should return sanitized string": {
name: "^-.123test!@-:cluster&*`;')test.cluster(-12_3=+::±§.",
want: "test----cluster------test-cluster--12-3",
wantErr: false,
},
{
name: "should return error of sanitization failed",
args: args{
name: "12345",
},
"should return error of sanitization failed": {
name: "12345",
want: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := sanitizeClusterName(tt.args.name)
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got, err := sanitizeClusterName(tt.name)

if (err != nil) != tt.wantErr {
t.Errorf("sanitizeClusterName() error = %v, wantErr %v", err, tt.wantErr)
Expand All @@ -116,63 +98,44 @@ func Test_sanitizeClusterName(t *testing.T) {
}

func Test_validateClusterName(t *testing.T) {
type args struct {
name string
}
tests := []struct {
tests := map[string]struct {
name string
args args
wantErr bool
}{
{
name: "name should be valid",
args: args{
name: "test-cluster-123",
},
"name should be valid": {
name: "test-cluster-123",
wantErr: false,
},
{
name: "name should not be valid (contains uppercase)",
args: args{
name: "Test-cluster",
},
"name should not be valid (contains uppercase)": {
name: "Test-cluster",
wantErr: true,
},
{
name: "name should not be valid (contains invalid chars)",
args: args{
name: "test-cluster:test/cluster.123#",
},
"name should not be valid (contains invalid chars)": {
name: "test-cluster:test/cluster.123#",
wantErr: true,
},
{
name: "name should not be valid (begins with numeric char)",
args: args{
name: "2test-cluster",
},
"name should not be valid (begins with numeric char)": {
name: "2test-cluster",
wantErr: true,
},
{
name: "name should not be valid (too long)",
args: args{
name: "this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-123",
},
"name should not be valid (too long)": {
name: "this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-123",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := validateClusterName(tt.args.name); (err != nil) != tt.wantErr {
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if err := validateClusterName(tt.name); (err != nil) != tt.wantErr {
t.Errorf("validateClusterName() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func getEmptyClusterEntity() model.Cluster {
func getEmptyClusterEntity() platmodel.Cluster {
empty := ""
return model.Cluster{
Metadata: &model.ObjectMeta{
return platmodel.Cluster{
Metadata: &platmodel.ObjectMeta{
Group: "",
Version: "",
Kind: "",
Expand All @@ -188,9 +151,9 @@ func getEmptyClusterEntity() model.Cluster {
Created: &empty,
UID: &empty,
},
Errors: []model.Error{},
ReferencedBy: []model.BaseEntity{},
References: []model.BaseEntity{},
Errors: []platmodel.Error{},
ReferencedBy: []platmodel.BaseEntity{},
References: []platmodel.BaseEntity{},
Server: "",
Namespaces: []string{},
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
"github.com/codefresh-io/cli-v2/pkg/store"
"github.com/codefresh-io/cli-v2/pkg/util"
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"
"github.com/codefresh-io/cli-v2/pkg/util/kube"
routingutil "github.com/codefresh-io/cli-v2/pkg/util/routing"

"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
Expand All @@ -57,7 +57,7 @@ var (
//go:embed assets/workflows-route-patch.json
workflowsRoutePatch []byte

cfConfig *config.Config
cfConfig config.Config

GREEN = "\033[32m"
RED = "\033[31m"
Expand Down Expand Up @@ -299,11 +299,13 @@ func ensureGitRuntimeToken(cmd *cobra.Command, gitProvider cfgit.Provider, clone
} else {
err = gitProvider.VerifyRuntimeToken(ctx, cloneOpts.Auth)
}

if err != nil {
// in case when we get invalid value from env variable TOKEN we clean
cloneOpts.Auth.Password = ""
return fmt.Errorf(errMessage, err)
}

if cloneOpts.Auth.Username == "" && gitProvider.Type() == cfgit.BITBUCKET {
return fmt.Errorf("must provide a git user using --git-user for bitbucket cloud")
}
Expand All @@ -318,7 +320,7 @@ func ensureGitRuntimeToken(cmd *cobra.Command, gitProvider cfgit.Provider, clone
func ensureGitUserToken(ctx context.Context, opts *RuntimeInstallOptions) error {
if opts.GitIntegrationRegistrationOpts.Token == "" {
opts.GitIntegrationRegistrationOpts.Token = opts.InsCloneOpts.Auth.Password
currentUser, err := cfConfig.GetCurrentContext().GetUser(ctx)
currentUser, err := cfConfig.GetUser(ctx)
if err != nil {
return fmt.Errorf("failed to get current user from platform: %w", err)
}
Expand Down Expand Up @@ -441,7 +443,7 @@ func ensureAccessMode(ctx context.Context, opts *RuntimeInstallOptions) error {
handleCliStep(reporter.InstallStepPreCheckEnsureIngressClass, "-skipped (ingressless)-", nil, true, false)
handleCliStep(reporter.InstallStepPreCheckEnsureIngressHost, "-skipped (ingressless)-", nil, true, false)
opts.featuresToInstall = append(opts.featuresToInstall, runtime.InstallFeatureIngressless)
accountId, err := cfConfig.GetCurrentContext().GetAccountId(ctx)
accountId, err := cfConfig.GetAccountId(ctx)
if err != nil {
return fmt.Errorf("failed creating ingressHost for tunnel: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/commands/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/codefresh-io/cli-v2/pkg/log"
"github.com/codefresh-io/cli-v2/pkg/util"

"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
"github.com/juju/ansiterm"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -90,7 +90,7 @@ func RunComponentList(ctx context.Context, runtimeName string) error {
return tb.Flush()
}

func printComponents(w io.Writer, components []model.Component) error {
func printComponents(w io.Writer, components []platmodel.Component) error {
_, err := fmt.Fprintln(w, "NAME\tHEALTH STATUS\tSYNC STATUS\tVERSION")
if err != nil {
return err
Expand All @@ -105,7 +105,7 @@ func printComponents(w io.Writer, components []model.Component) error {
return nil
}

func printComponent(w io.Writer, c model.Component) error {
func printComponent(w io.Writer, c platmodel.Component) error {
name := c.Metadata.Name
healthStatus := "N/A"
syncStatus := "N/A"
Expand Down
Loading

0 comments on commit a33091e

Please sign in to comment.