mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
Merge pull request #46760 from xilabao/fix-parse-pairs
Automatic merge from submit-queue (batch tested with PRs 49524, 46760, 50206, 50166, 49603) fix parse pairs **What this PR does / why we need it**: add check to `-` ``` # kubectl label pod foo - error: at least one label update is required See 'kubectl label -h' for help and examples. ``` **Which issue this PR fixes**: **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -606,7 +606,7 @@ func AddInclude3rdPartyVarFlags(cmd *cobra.Command, include3rdParty *bool) {
|
||||
func GetResourcesAndPairs(args []string, pairType string) (resources []string, pairArgs []string, err error) {
|
||||
foundPair := false
|
||||
for _, s := range args {
|
||||
nonResource := strings.Contains(s, "=") || strings.HasSuffix(s, "-")
|
||||
nonResource := (strings.Contains(s, "=") && s[0] != '=') || (strings.HasSuffix(s, "-") && s != "-")
|
||||
switch {
|
||||
case !foundPair && nonResource:
|
||||
foundPair = true
|
||||
@@ -632,7 +632,7 @@ func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPair
|
||||
var invalidBuf bytes.Buffer
|
||||
var invalidBufNonEmpty bool
|
||||
for _, pairArg := range pairArgs {
|
||||
if strings.Contains(pairArg, "=") {
|
||||
if strings.Contains(pairArg, "=") && pairArg[0] != '=' {
|
||||
parts := strings.SplitN(pairArg, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
if invalidBufNonEmpty {
|
||||
@@ -643,7 +643,7 @@ func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPair
|
||||
} else {
|
||||
newPairs[parts[0]] = parts[1]
|
||||
}
|
||||
} else if supportRemove && strings.HasSuffix(pairArg, "-") {
|
||||
} else if supportRemove && strings.HasSuffix(pairArg, "-") && pairArg != "-" {
|
||||
removePairs = append(removePairs, pairArg[:len(pairArg)-1])
|
||||
} else {
|
||||
if invalidBufNonEmpty {
|
||||
|
||||
Reference in New Issue
Block a user