forked from vmware-tanzu/velero
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OADP-4640: Downstream only to allow override kopia default algorithms #334
Merged
+161
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
OADP-4640: Downstream only to allow override kopia default algorithms
Introduction of downstream only option to override Kopia default: - hashing algorithm - splitting algorithm - encryption algorithm With introduction of 3 environment variables it is possible to override Kopia algorithms used by Velero: KOPIA_HASHING_ALGORITHM KOPIA_SPLITTER_ALGORITHM KOPIA_ENCRYPTION_ALGORITHM If the env algorithms are not set or they are not within Kopia SupportedAlgorithms, the default algorithm will be used. This behavior is consistent with current behavior without this change. Signed-off-by: Michal Pryc <mpryc@redhat.com>
- Loading branch information
commit 2fd82cf4d53f91e45bb047e6681f145dfba1dfb8
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
pkg/repository/udmrepo/kopialib/backend/common_kopia_algorithms_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
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 backend | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/kopia/kopia/repo" | ||
"github.com/kopia/kopia/repo/encryption" | ||
"github.com/kopia/kopia/repo/format" | ||
"github.com/kopia/kopia/repo/hashing" | ||
"github.com/kopia/kopia/repo/splitter" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/vmware-tanzu/velero/pkg/repository/udmrepo" | ||
) | ||
|
||
func TestSetupNewRepoAlgorithms(t *testing.T) { | ||
|
||
testCases := []struct { | ||
name string | ||
envVars map[string]string | ||
flags map[string]string | ||
expected repo.NewRepositoryOptions | ||
}{ | ||
{ | ||
name: "with valid non-default hash algo from env", | ||
envVars: map[string]string{ | ||
"KOPIA_HASHING_ALGORITHM": "HMAC-SHA3-224", | ||
}, | ||
flags: map[string]string{}, | ||
expected: repo.NewRepositoryOptions{ | ||
BlockFormat: format.ContentFormat{ | ||
Hash: "HMAC-SHA3-224", | ||
Encryption: encryption.DefaultAlgorithm, | ||
}, | ||
ObjectFormat: format.ObjectFormat{ | ||
Splitter: splitter.DefaultAlgorithm, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "with valid non-default encryption algo from env", | ||
envVars: map[string]string{ | ||
"KOPIA_HASHING_ALGORITHM": "", | ||
"KOPIA_SPLITTER_ALGORITHM": "", | ||
"KOPIA_ENCRYPTION_ALGORITHM": "CHACHA20-POLY1305-HMAC-SHA256", | ||
}, | ||
flags: map[string]string{}, | ||
expected: repo.NewRepositoryOptions{ | ||
BlockFormat: format.ContentFormat{ | ||
Hash: hashing.DefaultAlgorithm, | ||
Encryption: "CHACHA20-POLY1305-HMAC-SHA256", | ||
}, | ||
ObjectFormat: format.ObjectFormat{ | ||
Splitter: splitter.DefaultAlgorithm, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "with valid non-default splitter algo from env", | ||
envVars: map[string]string{"KOPIA_SPLITTER_ALGORITHM": "FIXED-512K"}, | ||
flags: map[string]string{}, | ||
expected: repo.NewRepositoryOptions{ | ||
BlockFormat: format.ContentFormat{ | ||
Hash: hashing.DefaultAlgorithm, | ||
Encryption: encryption.DefaultAlgorithm, | ||
}, | ||
ObjectFormat: format.ObjectFormat{ | ||
Splitter: "FIXED-512K", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "with valid non-default splitter and hashing algo from env, invalid encryption from env", | ||
envVars: map[string]string{"KOPIA_SPLITTER_ALGORITHM": "FIXED-512K", "KOPIA_HASHING_ALGORITHM": "HMAC-SHA3-224", "KOPIA_ENCRYPTION_ALGORITHM": "NON-EXISTING-SHA256"}, | ||
flags: map[string]string{}, | ||
expected: repo.NewRepositoryOptions{ | ||
BlockFormat: format.ContentFormat{ | ||
Hash: "HMAC-SHA3-224", | ||
Encryption: encryption.DefaultAlgorithm, | ||
}, | ||
ObjectFormat: format.ObjectFormat{ | ||
Splitter: "FIXED-512K", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "with unsupported hash algo in env, fallback to default", | ||
envVars: map[string]string{"KOPIA_HASHING_ALGORITHM": "unsupported-hash"}, | ||
flags: map[string]string{}, | ||
expected: repo.NewRepositoryOptions{ | ||
BlockFormat: format.ContentFormat{ | ||
Hash: hashing.DefaultAlgorithm, | ||
Encryption: encryption.DefaultAlgorithm, | ||
}, | ||
ObjectFormat: format.ObjectFormat{ | ||
Splitter: splitter.DefaultAlgorithm, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "hash in StoreOptionGenHashAlgo and env, env wins", | ||
envVars: map[string]string{"KOPIA_HASHING_ALGORITHM": "HMAC-SHA3-224"}, | ||
flags: map[string]string{ | ||
udmrepo.StoreOptionGenHashAlgo: "HMAC-SHA3-256", | ||
}, | ||
expected: repo.NewRepositoryOptions{ | ||
BlockFormat: format.ContentFormat{ | ||
Hash: "HMAC-SHA3-224", | ||
Encryption: encryption.DefaultAlgorithm, | ||
}, | ||
ObjectFormat: format.ObjectFormat{ | ||
Splitter: splitter.DefaultAlgorithm, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
for key, value := range tc.envVars { | ||
t.Setenv(key, value) | ||
} | ||
ret := SetupNewRepositoryOptions(context.Background(), tc.flags) | ||
assert.Equal(t, tc.expected, ret) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpryc IMO we should add another testcase when
StoreOptionGenHashAlgos
has a valid algo value but the env var has an invalid algo value. Then in such a scenario default would not be used but the one present inStoreOptionGenHashAlgos
would be used, right ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shubham-pampattiwar right. there are 2 levels of fallback here: