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: repo-server should allow not to skip hidden directories #17957

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions cmd/argocd-repo-server/commands/argocd_repo_server.go
Expand Up @@ -70,6 +70,7 @@ func NewCommand() *cobra.Command {
helmManifestMaxExtractedSize string
helmRegistryMaxIndexSize string
disableManifestMaxExtractedSize bool
includeHiddenDirectories bool
)
var command = cobra.Command{
Use: cliName,
Expand Down Expand Up @@ -130,6 +131,7 @@ func NewCommand() *cobra.Command {
StreamedManifestMaxTarSize: streamedManifestMaxTarSizeQuantity.ToDec().Value(),
HelmManifestMaxExtractedSize: helmManifestMaxExtractedSizeQuantity.ToDec().Value(),
HelmRegistryMaxIndexSize: helmRegistryMaxIndexSizeQuantity.ToDec().Value(),
IncludeHiddenDirectories: includeHiddenDirectories,
}, askPassServer)
errors.CheckError(err)

Expand Down Expand Up @@ -215,6 +217,7 @@ func NewCommand() *cobra.Command {
command.Flags().StringVar(&helmManifestMaxExtractedSize, "helm-manifest-max-extracted-size", env.StringFromEnv("ARGOCD_REPO_SERVER_HELM_MANIFEST_MAX_EXTRACTED_SIZE", "1G"), "Maximum size of helm manifest archives when extracted")
command.Flags().StringVar(&helmRegistryMaxIndexSize, "helm-registry-max-index-size", env.StringFromEnv("ARGOCD_REPO_SERVER_HELM_MANIFEST_MAX_INDEX_SIZE", "1G"), "Maximum size of registry index file")
command.Flags().BoolVar(&disableManifestMaxExtractedSize, "disable-helm-manifest-max-extracted-size", env.ParseBoolFromEnv("ARGOCD_REPO_SERVER_DISABLE_HELM_MANIFEST_MAX_EXTRACTED_SIZE", false), "Disable maximum size of helm manifest archives when extracted")
command.Flags().BoolVar(&includeHiddenDirectories, "include-hidden-directories", env.ParseBoolFromEnv("ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES", false), "Include hidden directories from Git")
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command)
cacheSrc = reposervercache.AddCacheFlagsToCmd(&command, cacheutil.Options{
OnClientCreated: func(client *redis.Client) {
Expand Down
2 changes: 2 additions & 0 deletions docs/operator-manual/argocd-cmd-params-cm.yaml
Expand Up @@ -179,6 +179,8 @@ data:
reposerver.git.lsremote.parallelism.limit: "0"
# Git requests timeout.
reposerver.git.request.timeout: "15s"
# Include hidden directories from Git
reposerver.include.hidden.directories: "false"

# Disable TLS on the HTTP endpoint
dexserver.disable.tls: "false"
Expand Down
Expand Up @@ -23,6 +23,7 @@ argocd-repo-server [flags]
--helm-manifest-max-extracted-size string Maximum size of helm manifest archives when extracted (default "1G")
--helm-registry-max-index-size string Maximum size of registry index file (default "1G")
-h, --help help for argocd-repo-server
--include-hidden-directories Include hidden directories from Git
--logformat string Set the logging format. One of: text|json (default "text")
--loglevel string Set the logging level. One of: debug|info|warn|error (default "info")
--max-combined-directory-manifests-size string Max combined size of manifest files in a directory-type Application (default "10M")
Expand Down
Expand Up @@ -209,6 +209,12 @@ spec:
key: reposerver.grpc.max.size
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES
valueFrom:
configMapKeyRef:
key: reposerver.include.hidden.directories
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 6 additions & 0 deletions manifests/core-install.yaml
Expand Up @@ -21622,6 +21622,12 @@ spec:
key: reposerver.grpc.max.size
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES
valueFrom:
configMapKeyRef:
key: reposerver.include.hidden.directories
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 6 additions & 0 deletions manifests/ha/install.yaml
Expand Up @@ -23197,6 +23197,12 @@ spec:
key: reposerver.grpc.max.size
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES
valueFrom:
configMapKeyRef:
key: reposerver.include.hidden.directories
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 6 additions & 0 deletions manifests/ha/namespace-install.yaml
Expand Up @@ -2279,6 +2279,12 @@ spec:
key: reposerver.grpc.max.size
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES
valueFrom:
configMapKeyRef:
key: reposerver.include.hidden.directories
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 6 additions & 0 deletions manifests/install.yaml
Expand Up @@ -22267,6 +22267,12 @@ spec:
key: reposerver.grpc.max.size
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES
valueFrom:
configMapKeyRef:
key: reposerver.include.hidden.directories
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 6 additions & 0 deletions manifests/namespace-install.yaml
Expand Up @@ -1349,6 +1349,12 @@ spec:
key: reposerver.grpc.max.size
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_INCLUDE_HIDDEN_DIRECTORIES
valueFrom:
configMapKeyRef:
key: reposerver.include.hidden.directories
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 3 additions & 3 deletions reposerver/repository/repository.go
Expand Up @@ -112,6 +112,7 @@ type RepoServerInitConstants struct {
HelmManifestMaxExtractedSize int64
HelmRegistryMaxIndexSize int64
DisableHelmManifestMaxExtractedSize bool
IncludeHiddenDirectories bool
}

// NewService returns a new instance of the Manifest service
Expand Down Expand Up @@ -2650,9 +2651,8 @@ func (s *Service) GetGitDirectories(_ context.Context, request *apiclient.GitDir
return nil
}

fname := entry.Name()
if strings.HasPrefix(fname, ".") { // Skip all folders starts with "."
return filepath.SkipDir
if !s.initConstants.IncludeHiddenDirectories && strings.HasPrefix(entry.Name(), ".") {
return filepath.SkipDir // Skip hidden directory
}

relativePath, err := filepath.Rel(repoRoot, path)
Expand Down
33 changes: 33 additions & 0 deletions reposerver/repository/repository_test.go
Expand Up @@ -3339,6 +3339,39 @@ func TestGetGitDirectories(t *testing.T) {
})
}

func TestGetGitDirectoriesWithHiddenDirSupported(t *testing.T) {
// test not using the cache
root := "./testdata/git-files-dirs"
s, _, cacheMocks := newServiceWithOpt(t, func(gitClient *gitmocks.Client, helmClient *helmmocks.Client, paths *iomocks.TempPaths) {
gitClient.On("Init").Return(nil)
gitClient.On("Fetch", mock.Anything).Return(nil)
gitClient.On("Checkout", mock.Anything, mock.Anything).Once().Return(nil)
gitClient.On("LsRemote", "HEAD").Return("632039659e542ed7de0c170a4fcc1c571b288fc0", nil)
gitClient.On("Root").Return(root)
paths.On("GetPath", mock.Anything).Return(root, nil)
paths.On("GetPathIfExists", mock.Anything).Return(root, nil)
}, root)
s.initConstants.IncludeHiddenDirectories = true
dirRequest := &apiclient.GitDirectoriesRequest{
Repo: &argoappv1.Repository{Repo: "a-url.com"},
SubmoduleEnabled: false,
Revision: "HEAD",
}
directories, err := s.GetGitDirectories(context.TODO(), dirRequest)
assert.Nil(t, err)
assert.ElementsMatch(t, directories.GetPaths(), []string{"app", "app/bar", "app/foo/bar", "somedir", "app/foo", "app/bar/.hidden"})

// do the same request again to use the cache
// we only allow CheckOut to be called once in the mock
directories, err = s.GetGitDirectories(context.TODO(), dirRequest)
assert.Nil(t, err)
assert.ElementsMatch(t, []string{"app", "app/bar", "app/foo/bar", "somedir", "app/foo", "app/bar/.hidden"}, directories.GetPaths())
cacheMocks.mockCache.AssertCacheCalledTimes(t, &repositorymocks.CacheCallCounts{
ExternalSets: 1,
ExternalGets: 2,
})
}

func TestErrorGetGitFiles(t *testing.T) {
// test not using the cache
root := ""
Expand Down