Skip to content

Commit 70123cc

Browse files
committed
lint the cli code
Signed-off-by: Karol Szwaj <[email protected]> On-behalf-of: @SAP [email protected]
1 parent 8532a35 commit 70123cc

File tree

6 files changed

+15
-41
lines changed

6 files changed

+15
-41
lines changed

cli/cmd/kubectl-create-workspace/cmd/kubectlCreateWorkspace.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ func KubectlCreateWorkspaceCommand() *cobra.Command {
4141
klog.InitFlags(fs)
4242
createWorkspaceCommand.PersistentFlags().AddGoFlagSet(fs)
4343
return createWorkspaceCommand
44-
4544
}

cli/cmd/kubectl-ws/cmd/kubectlWs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ func KubectlWsCommand() *cobra.Command {
4141
klog.InitFlags(fs)
4242
wsCommand.PersistentFlags().AddGoFlagSet(fs)
4343
return wsCommand
44-
4544
}

cli/pkg/workspace/plugin/context_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ func TestCreateContext(t *testing.T) {
196196
},
197197
}
198198
for _, tt := range tests {
199-
tt := tt
200-
201199
t.Run(tt.name, func(t *testing.T) {
202200
var got *clientcmdapi.Config
203201

cli/pkg/workspace/plugin/create_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ func TestCreate(t *testing.T) {
184184

185185
var got *clientcmdapi.Config
186186

187-
cluster := tt.config.Clusters[tt.config.Contexts[tt.config.CurrentContext].Cluster] //nolint:govet // TODO(sttts): fixing this above breaks the test
187+
cluster := tt.config.Clusters[tt.config.Contexts[tt.config.CurrentContext].Cluster]
188188
u := parseURLOrDie(cluster.Server)
189189
currentClusterName := logicalcluster.NewPath(strings.TrimPrefix(u.Path, "/clusters/"))
190190
u.Path = ""
191191

192192
objects := []runtime.Object{}
193-
for _, name := range tt.existingWorkspaces { //nolint:govet // TODO(sttts): fixing this above breaks the test
193+
for _, name := range tt.existingWorkspaces {
194194
objects = append(objects, &tenancyv1alpha1.Workspace{
195195
ObjectMeta: metav1.ObjectMeta{
196196
Name: name,
@@ -217,7 +217,7 @@ func TestCreate(t *testing.T) {
217217
}
218218
}
219219

220-
if tt.markReady { //nolint:govet // TODO(sttts): fixing this above breaks the test
220+
if tt.markReady {
221221
client.PrependReactor("create", "workspaces", func(action kcptesting.Action) (handled bool, ret runtime.Object, err error) {
222222
obj := action.(kcptesting.CreateAction).GetObject().(*tenancyv1alpha1.Workspace)
223223
obj.Status.Phase = corev1alpha1.LogicalClusterPhaseReady
@@ -233,30 +233,30 @@ func TestCreate(t *testing.T) {
233233
}
234234

235235
opts := NewCreateWorkspaceOptions(genericclioptions.NewTestIOStreamsDiscard())
236-
opts.Name = tt.newWorkspaceName //nolint:govet // TODO(sttts): fixing this above breaks the test
236+
opts.Name = tt.newWorkspaceName
237237
opts.Type = workspaceType.Path + ":" + string(workspaceType.Name)
238-
opts.IgnoreExisting = tt.ignoreExisting //nolint:govet // TODO(sttts): fixing this above breaks the test
239-
opts.EnterAfterCreate = tt.useAfterCreation //nolint:govet // TODO(sttts): fixing this above breaks the test
238+
opts.IgnoreExisting = tt.ignoreExisting
239+
opts.EnterAfterCreate = tt.useAfterCreation
240240
opts.ReadyWaitTimeout = time.Second
241241
opts.modifyConfig = func(configAccess clientcmd.ConfigAccess, config *clientcmdapi.Config) error {
242242
got = config
243243
return nil
244244
}
245245
opts.kcpClusterClient = client
246-
opts.ClientConfig = clientcmd.NewDefaultClientConfig(*tt.config.DeepCopy(), nil) //nolint:govet // TODO(sttts): fixing this above breaks the test
246+
opts.ClientConfig = clientcmd.NewDefaultClientConfig(*tt.config.DeepCopy(), nil)
247247
err := opts.Run(context.Background())
248-
if tt.wantErr { //nolint:govet // TODO(sttts): fixing this above breaks the test
248+
if tt.wantErr {
249249
require.Error(t, err)
250250
} else {
251251
require.NoError(t, err)
252252
}
253253

254-
if got != nil && tt.expected == nil { //nolint:govet // TODO(sttts): fixing this above breaks the test
254+
if got != nil && tt.expected == nil {
255255
t.Errorf("unexpected kubeconfig write")
256-
} else if got == nil && tt.expected != nil { //nolint:govet // TODO(sttts): fixing this above breaks the test
256+
} else if got == nil && tt.expected != nil {
257257
t.Errorf("expected a kubeconfig write, but didn't see one")
258-
} else if got != nil && !reflect.DeepEqual(got, tt.expected) { //nolint:govet // TODO(sttts): fixing this above breaks the test
259-
t.Errorf("unexpected config, diff (expected, got): %s", cmp.Diff(tt.expected, got)) //nolint:govet // TODO(sttts): fixing this above breaks the test
258+
} else if got != nil && !reflect.DeepEqual(got, tt.expected) {
259+
t.Errorf("unexpected config, diff (expected, got): %s", cmp.Diff(tt.expected, got))
260260
}
261261
})
262262
}

cli/pkg/workspace/plugin/use.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ func (o *UseWorkspaceOptions) Run(ctx context.Context) (err error) {
206206
if err != nil && !apierrors.IsForbidden(err) {
207207
return err
208208
}
209-
denied := false
210-
if apierrors.IsForbidden(err) || len(groups.Groups) == 0 {
211-
denied = true
212-
}
209+
denied := apierrors.IsForbidden(err) || len(groups.Groups) == 0
213210

214211
// first try to get Workspace from parent to potentially get a 404. A 403 in the parent though is
215212
// not a blocker to enter the workspace. We do discovery as a final check.
@@ -260,9 +257,7 @@ func resolveDots(pth string) (logicalcluster.Path, error) {
260257
return ret, nil
261258
}
262259

263-
// swapContexts moves to previous context from the config.
264-
// It will update existing configuration by swapping current & previous configurations.
265-
// This method already commits. Do not use with commitConfig
260+
// This method already commits. Do not use with commitConfig.
266261
func (o *UseWorkspaceOptions) swapContexts(ctx context.Context, currentContext *clientcmdapi.Context) (string, error) {
267262
currentContext = currentContext.DeepCopy()
268263

@@ -370,21 +365,6 @@ func (o *UseWorkspaceOptions) homePath(ctx context.Context) (logicalcluster.Path
370365
return logicalcluster.NewPath(strings.TrimPrefix(uh.Path, "/clusters/")), nil
371366
}
372367

373-
func (o *UseWorkspaceOptions) legacyRootURL() (*url.URL, error) {
374-
cluster := logicalcluster.NewPath(o.Name)
375-
if !cluster.IsValid() {
376-
return nil, fmt.Errorf("invalid workspace name format: %s", o.Name)
377-
}
378-
379-
u, _, err := o.parseCurrentLogicalCluster()
380-
if err != nil {
381-
return nil, err
382-
}
383-
// root workspace
384-
u.Path = path.Join(u.Path, cluster.RequestPath())
385-
return u, nil
386-
}
387-
388368
func (o *UseWorkspaceOptions) currentRootURL() (*url.URL, error) {
389369
u, currentClusterName, err := o.parseCurrentLogicalCluster()
390370
if err != nil {

cli/pkg/workspace/plugin/use_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func TestUse(t *testing.T) {
429429
param: "~/..",
430430
expected: NewKubeconfig().WithKcpCurrent("root:users:ab:cd").WithKcpPrevious("root:foo").Build(),
431431
destination: homeWorkspace.String(),
432-
wantStdout: []string{fmt.Sprintf("Current workspace is 'root:users:ab:cd'")},
432+
wantStdout: []string{"Current workspace is 'root:users:ab:cd'"},
433433
},
434434
{
435435
name: "~ unfolded",
@@ -736,8 +736,6 @@ func TestUse(t *testing.T) {
736736
},
737737
}
738738
for _, tt := range tests {
739-
tt := tt
740-
741739
t.Run(tt.name, func(t *testing.T) {
742740
var got *clientcmdapi.Config
743741

0 commit comments

Comments
 (0)