mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-13 11:34:54 +00:00
Fix user version priorities parsing to handle CRLF line endings (#10496)
Run the E2E test on kind / setup-test-matrix (push) Failing after 3s
e2e-test-kind.yaml / extract (push) Failing after 6s
Run the E2E test on kind / get-go-version (push) Failing after 8s
Run the E2E test on kind / build (push) Skipped
Run the E2E test on kind / run-e2e-test (push) Skipped
push.yml / extract (push) Failing after 5s
Main CI / get-go-version (push) Failing after 6s
Main CI / Build (push) Skipped
Run the E2E test on kind / setup-test-matrix (push) Failing after 3s
e2e-test-kind.yaml / extract (push) Failing after 6s
Run the E2E test on kind / get-go-version (push) Failing after 8s
Run the E2E test on kind / build (push) Skipped
Run the E2E test on kind / run-e2e-test (push) Skipped
push.yml / extract (push) Failing after 5s
Main CI / get-go-version (push) Failing after 6s
Main CI / Build (push) Skipped
formatUserPriorities stripped only spaces, so an enableapigroupversions ConfigMap written with CRLF line endings (common for files edited on Windows) kept a trailing carriage return in each version string, e.g. "v2beta1\r". versionsContain compares versions with equality, so the user priority never matched and was silently ignored. Trim the trailing carriage return so stored versions match again. Signed-off-by: HeonJe LEE <lhjnano@gmail.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Fix user version priorities parsing to handle CRLF line endings
|
||||
@@ -245,7 +245,11 @@ func parseUserPriorities(ctx *restoreContext, prioritiesData string) map[string]
|
||||
// orchestras.music.example.io=v2,v3alpha1\n
|
||||
// subscriptions.operators.coreos.com=v2,v1
|
||||
|
||||
lines := strings.Split(prioritiesData, "\n")
|
||||
// Normalize Windows (CRLF) and legacy Mac (CR) line endings before splitting.
|
||||
normalized := strings.ReplaceAll(prioritiesData, "\r\n", "\n")
|
||||
normalized = strings.ReplaceAll(normalized, "\r", "\n")
|
||||
|
||||
lines := strings.Split(normalized, "\n")
|
||||
lines = formatUserPriorities(lines)
|
||||
|
||||
for _, line := range lines {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright the Velero contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package restore
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/test"
|
||||
)
|
||||
|
||||
// TestParseUserPrioritiesCRLF verifies that user version priorities parsed
|
||||
// from an enableapigroupversions ConfigMap written with CRLF line endings
|
||||
// (common for files edited on Windows) do not retain the trailing "\r".
|
||||
// A retained "\r" makes versionsContain never match the version, silently
|
||||
// disabling the user priority (Priority 0 becomes a no-op).
|
||||
func TestParseUserPrioritiesCRLF(t *testing.T) {
|
||||
fakeCtx := &restoreContext{
|
||||
log: test.NewLogger(),
|
||||
}
|
||||
|
||||
priorities := parseUserPriorities(fakeCtx, "rockbands.music.example.io=v2beta1\r\nother.example.io=v2\r\n")
|
||||
|
||||
assert.Len(t, priorities, 2)
|
||||
|
||||
rb, ok := priorities["rockbands.music.example.io"]
|
||||
assert.True(t, ok, "expected key rockbands.music.example.io to exist")
|
||||
assert.Len(t, rb.Versions, 1)
|
||||
assert.Equal(t, "v2beta1", rb.Versions[0].Version, "trailing \\r must not be retained in the stored version")
|
||||
|
||||
other, ok := priorities["other.example.io"]
|
||||
assert.True(t, ok, "expected key other.example.io to exist")
|
||||
assert.Len(t, other.Versions, 1)
|
||||
assert.Equal(t, "v2", other.Versions[0].Version, "trailing \\r must not be retained in the stored version")
|
||||
|
||||
// A line made only of a carriage return is dropped like blank lines.
|
||||
empty := parseUserPriorities(fakeCtx, "\r")
|
||||
assert.Empty(t, empty)
|
||||
}
|
||||
Reference in New Issue
Block a user