Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c50a9962
Commit
c50a9962
authored
Nov 12, 2024
by
Brad Davidson
Committed by
Brad Davidson
Nov 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of wrapped subcommands when run with a path
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
dd5aea38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
defaultparser.go
pkg/configfilearg/defaultparser.go
+3
-2
defaultparser_test.go
pkg/configfilearg/defaultparser_test.go
+21
-1
No files found.
pkg/configfilearg/defaultparser.go
View file @
c50a9962
package
configfilearg
package
configfilearg
import
(
import
(
"path/filepath"
"slices"
"slices"
"github.com/k3s-io/k3s/pkg/cli/cmds"
"github.com/k3s-io/k3s/pkg/cli/cmds"
...
@@ -31,10 +32,10 @@ func MustFindString(args []string, target string, commandsWithoutOverride ...str
...
@@ -31,10 +32,10 @@ func MustFindString(args []string, target string, commandsWithoutOverride ...str
// Some subcommands such as `k3s ctr` or just `ctr` need to be extracted out even to
// Some subcommands such as `k3s ctr` or just `ctr` need to be extracted out even to
// provide version or help text, and we cannot short-circuit loading the config file. For
// provide version or help text, and we cannot short-circuit loading the config file. For
// these commands, treat failure to load the config file as a warning instead of a fatal.
// these commands, treat failure to load the config file as a warning instead of a fatal.
if
len
(
args
)
>
0
&&
args
[
0
]
==
version
.
Program
{
if
len
(
args
)
>
0
&&
filepath
.
Base
(
args
[
0
])
==
version
.
Program
{
args
=
args
[
1
:
]
args
=
args
[
1
:
]
}
}
if
len
(
args
)
>
0
&&
slices
.
Contains
(
commandsWithoutOverride
,
args
[
0
]
)
{
if
len
(
args
)
>
0
&&
slices
.
Contains
(
commandsWithoutOverride
,
filepath
.
Base
(
args
[
0
])
)
{
overrideFlags
=
nil
overrideFlags
=
nil
}
}
...
...
pkg/configfilearg/defaultparser_test.go
View file @
c50a9962
...
@@ -124,7 +124,17 @@ func Test_UnitMustFindString(t *testing.T) {
...
@@ -124,7 +124,17 @@ func Test_UnitMustFindString(t *testing.T) {
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
},
{
{
name
:
"Override flag is not returned for specific subcommands"
,
name
:
"Override flag is not returned for specific subcommands with full path"
,
args
:
[]
string
{
"/usr/local/bin/k3s"
,
"ctr"
,
"--foo"
,
"bar"
,
"--version"
},
target
:
"token"
,
want
:
"12345"
,
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/defaultdata.yaml"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
{
name
:
"Override flag is not returned for wrapped commands"
,
args
:
[]
string
{
"kubectl"
,
"--foo"
,
"bar"
,
"--help"
},
args
:
[]
string
{
"kubectl"
,
"--foo"
,
"bar"
,
"--help"
},
target
:
"token"
,
target
:
"token"
,
...
@@ -133,6 +143,16 @@ func Test_UnitMustFindString(t *testing.T) {
...
@@ -133,6 +143,16 @@ func Test_UnitMustFindString(t *testing.T) {
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/defaultdata.yaml"
)
},
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/defaultdata.yaml"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
},
{
name
:
"Override flag is not returned for wrapped commands with full path"
,
args
:
[]
string
{
"/usr/local/bin/kubectl"
,
"--foo"
,
"bar"
,
"--help"
},
target
:
"token"
,
want
:
"12345"
,
setup
:
func
()
error
{
return
os
.
Setenv
(
"K3S_CONFIG_FILE"
,
"./testdata/defaultdata.yaml"
)
},
teardown
:
func
()
error
{
return
os
.
Unsetenv
(
"K3S_CONFIG_FILE"
)
},
},
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment