Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit aaf21a6

Browse files
authored
revert project validation from client (#1558)
Signed-off-by: Joshua Silverio <joshua@acorn.io>
1 parent 88cf1a8 commit aaf21a6

File tree

6 files changed

+17
-59
lines changed

6 files changed

+17
-59
lines changed

integration/projectconfig/projectconfig_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ func TestCLIConfig(t *testing.T) {
118118
wantRestConfigHost: "https://foo.example.com",
119119
wantNamespace: "bar",
120120
wantToken: "pass",
121-
wantErr: fmt.Errorf("project \"example.com/foo/bar\" does not exist within the current context"),
122-
wantError: true,
123121
},
124122
{
125123
name: "Project arg overrides current project",
@@ -166,8 +164,6 @@ func TestCLIConfig(t *testing.T) {
166164
wantProject: "example.com/foo/bar",
167165
wantNamespace: "bar",
168166
wantToken: "pass",
169-
wantError: true,
170-
wantErr: fmt.Errorf("project \"example.com/foo/bar\" does not exist within the current context"),
171167
},
172168
{
173169
name: "Use alias",

pkg/cli/acorn_test.go

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,6 @@ func TestAcornProject(t *testing.T) {
9393
wantOut string
9494
commandContext CommandContext
9595
}{
96-
{
97-
name: "acorn image -j noproject",
98-
fields: fields{
99-
All: false,
100-
Quiet: false,
101-
Output: "",
102-
},
103-
commandContext: CommandContext{
104-
ClientFactory: &testdata.MockClientFactory{},
105-
StdOut: w,
106-
StdErr: w,
107-
StdIn: strings.NewReader(""),
108-
},
109-
args: args{
110-
args: []string{"image", "-j", "noproject"},
111-
client: &testdata.MockClient{},
112-
},
113-
wantErr: true,
114-
wantOut: "project \"noproject\" does not exist within the current context",
115-
},
11696
{
11797
name: "acorn image -j 12.badname",
11898
fields: fields{
@@ -131,27 +111,7 @@ func TestAcornProject(t *testing.T) {
131111
client: &testdata.MockClient{},
132112
},
133113
wantErr: true,
134-
wantOut: "project \"12.badname\" does not exist within the current context",
135-
},
136-
{
137-
name: "acorn image -j badname/projectname/here",
138-
fields: fields{
139-
All: false,
140-
Quiet: false,
141-
Output: "",
142-
},
143-
commandContext: CommandContext{
144-
ClientFactory: &testdata.MockClientFactory{},
145-
StdOut: w,
146-
StdErr: w,
147-
StdIn: strings.NewReader(""),
148-
},
149-
args: args{
150-
args: []string{"image", "-j", "badname/projectname/here"},
151-
client: &testdata.MockClient{},
152-
},
153-
wantErr: true,
154-
wantOut: "project \"badname/projectname/here\" does not exist within the current context",
114+
wantOut: "invalid project name [12.badname]: can not contain \".\"",
155115
},
156116
}
157117
for _, tt := range tests {

pkg/cli/errors.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"context"
55
"os"
6+
"strings"
67

78
"github.com/pterm/pterm"
89
"github.com/spf13/cobra"
@@ -15,7 +16,13 @@ func RunAndHandleError(ctx context.Context, cmd *cobra.Command) {
1516
cmd.SilenceErrors = true
1617
err := cmd.ExecuteContext(ctx)
1718
if err != nil {
18-
pterm.Error.Println(err)
19+
errString := err.Error()
20+
//If user uses --project/-j flag that does not exist k8s returns namespace error.
21+
//Replace namespace with project in error message to make it more user friendly.
22+
if cmd.Flag("project").Value.String() != "" {
23+
errString = strings.Replace(errString, "namespace", "project", 1)
24+
}
25+
pterm.Error.Println(errString)
1926
os.Exit(1)
2027
}
2128
os.Exit(0)

pkg/project/client.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/acorn-io/acorn/pkg/system"
1414
"github.com/acorn-io/baaah/pkg/restconfig"
1515
"k8s.io/client-go/rest"
16-
"k8s.io/utils/strings/slices"
1716
)
1817

1918
var (
@@ -25,7 +24,6 @@ type Options struct {
2524
Kubeconfig string
2625
ContextEnv string
2726
AllProjects bool
28-
Create bool
2927
CLIConfig *config.CLIConfig
3028
}
3129

@@ -204,11 +202,8 @@ func getClient(ctx context.Context, cfg *config.CLIConfig, opts Options, project
204202
}
205203

206204
func getDesiredProjects(ctx context.Context, cfg *config.CLIConfig, opts Options) (result []string, err error) {
207-
projects, _, err := List(ctx, opts.WithCLIConfig(cfg))
208-
if err != nil {
209-
return nil, err
210-
}
211205
if opts.AllProjects {
206+
projects, _, err := List(ctx, opts.WithCLIConfig(cfg))
212207
return projects, err
213208
}
214209
p := strings.TrimSpace(opts.Project)
@@ -218,9 +213,6 @@ func getDesiredProjects(ctx context.Context, cfg *config.CLIConfig, opts Options
218213
if strings.TrimSpace(p) == "" {
219214
return nil, nil
220215
}
221-
if !opts.Create && len(projects) != 0 && !slices.Contains(projects, p) {
222-
return nil, fmt.Errorf("project \"%s\" does not exist within the current context", p)
223-
}
224216
for _, project := range csvSplit.Split(p, -1) {
225217
if target := cfg.ProjectAliases[project]; target == "" {
226218
result = append(result, project)

pkg/project/operations.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func lastPart(s string) string {
2424

2525
func Create(ctx context.Context, opts Options, name, defaultRegion string, supportedRegions []string) error {
2626
opts.Project = name
27-
opts.Create = true
2827
c, err := Client(ctx, opts)
2928
if err != nil {
3029
return err
@@ -79,7 +78,6 @@ func Exists(ctx context.Context, opts Options, name string) error {
7978

8079
func Update(ctx context.Context, opts Options, project DetailProject, defaultRegion string, supportedRegions []string) error {
8180
opts.Project = project.FullName
82-
opts.Create = false
8381
c, err := Client(ctx, opts)
8482
if err != nil {
8583
return err

pkg/roles/roles.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,15 @@ var (
147147
"clustervolumeclasses",
148148
"projectcomputeclasses",
149149
"clustercomputeclasses",
150-
"imageallowrules",
151150
},
152151
APIGroups: []string{admin_acorn_io.Group},
153152
},
153+
{
154+
Verbs: []string{"*"},
155+
Resources: []string{
156+
"imageallowrules",
157+
},
158+
},
154159
},
155160
}
156161
)
@@ -200,7 +205,7 @@ func ClusterRoles() []rbacv1.ClusterRole {
200205
ObjectMeta: metav1.ObjectMeta{
201206
Name: Admin,
202207
},
203-
Rules: concat(View, ViewLogs, Edit, Build),
208+
Rules: concat(View, ViewLogs, Edit, Build, Admin),
204209
},
205210
{
206211
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)