-
Notifications
You must be signed in to change notification settings - Fork 52
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
Added lazy sync functionality #279
Merged
joaopapereira
merged 10 commits into
carvel-dev:develop
from
fritzduchardt:added_lazy_syncing
Oct 26, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5d8f4d2
feat: added lazy sync functionality to only do a sync, if the config …
fritzduchardt dca8107
feat: reimplementation of lazy sync functionality
6fa6535
feat: first working draft
77b9440
Remove hash container
a1beab7
Revamp of entire lazy sync logic
fritzduchardt e0a6b99
Tweaked handling of lock file
fritzduchardt c004cac
Change naming
fritzduchardt 622b00c
Added e2e test, removed unit test, improved help message.
fritzduchardt e9af3ba
Some more comments
fritzduchardt 82c3c9f
Introduced require test function in e2e test
fritzduchardt 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
There are no files selected for viewing
Empty file.
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,9 @@ | ||
apiVersion: vendir.k14s.io/v1alpha1 | ||
kind: Config | ||
directories: | ||
- path: vendor | ||
contents: | ||
- path: dir | ||
lazy: true | ||
directory: | ||
path: ./some-content |
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,8 @@ | ||
apiVersion: vendir.k14s.io/v1alpha1 | ||
kind: Config | ||
directories: | ||
- path: vendor | ||
contents: | ||
- path: dir | ||
directory: | ||
path: ./some-content |
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,7 @@ | ||
apiVersion: vendir.k14s.io/v1alpha1 | ||
directories: | ||
- contents: | ||
- directory: {} | ||
path: dir | ||
path: vendor | ||
kind: LockConfig |
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
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
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
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
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
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
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,56 @@ | ||
// Copyright 2020 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
ctlconf "github.com/vmware-tanzu/carvel-vendir/pkg/vendir/config" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestExampleLazy(t *testing.T) { | ||
env := BuildEnv(t) | ||
vendir := Vendir{t, env.BinaryPath, Logger{}} | ||
|
||
osEnv := []string{"VENDIR_HELM_BINARY=" + env.Helm2Binary} | ||
|
||
dir := "examples/lazy" | ||
path := "../../" + dir | ||
|
||
// run lazy sync | ||
_, err := vendir.RunWithOpts([]string{"sync", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv}) | ||
require.NoError(t, err) | ||
|
||
// check that the lock file has config digest | ||
lockConf, err := ctlconf.NewLockConfigFromFile(path + "/vendir.lock.yml") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, lockConf.Directories[0].Contents[0].ConfigDigest, "Expected Config Digest in Lock File") | ||
|
||
// remove some directory | ||
err = os.RemoveAll(path + "/vendor/dir") | ||
require.NoError(t, err) | ||
|
||
// resync lazily, should not sync. Removed dir has not been reinstated | ||
_, err = vendir.RunWithOpts([]string{"sync", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv}) | ||
require.NoError(t, err) | ||
require.NoDirExists(t, path+"/vendor/dir") | ||
|
||
// resync with lazy override, should not affect config digest | ||
_, err = vendir.RunWithOpts([]string{"sync", "--lazy=false", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv}) | ||
require.NoError(t, err) | ||
require.DirExists(t, path+"/vendor/dir") | ||
|
||
// content digest is kept during lazy sync override | ||
lockConf, err = ctlconf.NewLockConfigFromFile(path + "/vendir.lock.yml") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, lockConf.Directories[0].Contents[0].ConfigDigest, "Expected Config Digest in Lock File") | ||
|
||
// if synced without lazy flag in vendir.yml, no config digest should be kept in lock file | ||
_, err = vendir.RunWithOpts([]string{"sync", "-f=vendir-nonlazy.yml"}, RunOpts{Dir: path, Env: osEnv}) | ||
require.NoError(t, err) | ||
lockConf, err = ctlconf.NewLockConfigFromFile(path + "/vendir.lock.yml") | ||
require.NoError(t, err) | ||
require.Empty(t, lockConf.Directories[0].Contents[0].ConfigDigest, "Expected No Config Digest in Lock File") | ||
} |
Oops, something went wrong.
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.
We do have
require
package as a dependency, and we are using it to do all the assertions in the other tests, you can see an example here.Do you mind refactoring this test to make it similar to the other tests?
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.
Not at all - look much more concise now