Skip to content
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

fix: overrides should not appear in the manifest cache key #9601

Merged
merged 4 commits into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions reposerver/repository/repository.go
Expand Up @@ -873,7 +873,11 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
var dest *v1alpha1.ApplicationDestination

resourceTracking := argo.NewResourceTracking()
appSourceType, err := GetAppSourceType(ctx, q.ApplicationSource, appPath, q.AppName, q.EnabledSourceTypes)

// Apply overrides, but don't mutate the given source. The un-overridden source should be used to generate the
// manifest cache key.
overriddenApplicationSource := q.ApplicationSource.DeepCopy()
appSourceType, err := GetAppSourceType(ctx, overriddenApplicationSource, appPath, q.AppName, q.EnabledSourceTypes)
if err != nil {
return nil, err
}
Expand All @@ -892,9 +896,9 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
kustomizeBinary = q.KustomizeOptions.BinaryPath
}
k := kustomize.NewKustomizeApp(appPath, q.Repo.GetGitCreds(gitCredsStore), repoURL, kustomizeBinary)
targetObjs, _, err = k.Build(q.ApplicationSource.Kustomize, q.KustomizeOptions, env)
targetObjs, _, err = k.Build(overriddenApplicationSource.Kustomize, q.KustomizeOptions, env)
case v1alpha1.ApplicationSourceTypePlugin:
if q.ApplicationSource.Plugin != nil && q.ApplicationSource.Plugin.Name != "" {
if overriddenApplicationSource.Plugin != nil && overriddenApplicationSource.Plugin.Name != "" {
targetObjs, err = runConfigManagementPlugin(appPath, repoRoot, env, q, q.Repo.GetGitCreds(gitCredsStore))
} else {
targetObjs, err = runConfigManagementPluginSidecars(ctx, appPath, repoRoot, env, q, q.Repo.GetGitCreds(gitCredsStore), opt.cmpTarDoneCh)
Expand All @@ -904,7 +908,7 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
}
case v1alpha1.ApplicationSourceTypeDirectory:
var directory *v1alpha1.ApplicationSourceDirectory
if directory = q.ApplicationSource.Directory; directory == nil {
if directory = overriddenApplicationSource.Directory; directory == nil {
directory = &v1alpha1.ApplicationSourceDirectory{}
}
logCtx := log.WithField("application", q.AppName)
Expand Down Expand Up @@ -985,7 +989,7 @@ func mergeSourceParameters(source *v1alpha1.ApplicationSource, path, appName str
overrides = append(overrides, filepath.Join(path, fmt.Sprintf(appSourceFile, appName)))
}

var merged v1alpha1.ApplicationSource = *source.DeepCopy()
var merged = *source.DeepCopy()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit type was redundant.


for _, filename := range overrides {
info, err := os.Stat(filename)
Expand Down
22 changes: 22 additions & 0 deletions reposerver/repository/repository_test.go
Expand Up @@ -1541,6 +1541,28 @@ func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
assert.Equal(t, "gcr.io/heptio-images/ks-guestbook-demo:0.1", image)
})
})

t.Run("Override info does not appear in cache key", func(t *testing.T) {
service := newService(".")
runWithTempTestdata(t, "single-global", func(t *testing.T, path string) {
source := &argoappv1.ApplicationSource{
Path: path,
}
sourceCopy := source.DeepCopy() // make a copy in case GenerateManifest mutates it.
_, err := service.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
Repo: &argoappv1.Repository{},
ApplicationSource: sourceCopy,
AppName: "test",
})
assert.NoError(t, err)
res := &cache.CachedManifestResponse{}
// Try to pull from the cache with a `source` that does not include any overrides. Overrides should not be
// part of the cache key, because you can't get the overrides without a repo operation. And avoiding repo
// operations is the point of the cache.
err = service.cache.GetManifests(mock.Anything, source, &argoappv1.ClusterInfo{}, "", "", "", "test", res)
assert.NoError(t, err)
})
})
}

func TestGenerateManifestWithAnnotatedAndRegularGitTagHashes(t *testing.T) {
Expand Down