diff --git a/reposerver/gpgwatcher.go b/reposerver/gpgwatcher.go index bf2387a7e38b2..9c2c9be790813 100644 --- a/reposerver/gpgwatcher.go +++ b/reposerver/gpgwatcher.go @@ -21,7 +21,11 @@ func StartGPGWatcher(sourcePath string) error { if err != nil { return err } - defer watcher.Close() + defer func(watcher *fsnotify.Watcher) { + if err = watcher.Close(); err != nil { + log.Errorf("Error closing watcher: %v", err) + } + }(watcher) done := make(chan bool) go func() { diff --git a/reposerver/repository/chart.go b/reposerver/repository/chart.go index 819cc498c2255..f4bcf48fba569 100644 --- a/reposerver/repository/chart.go +++ b/reposerver/repository/chart.go @@ -9,16 +9,7 @@ import ( ) func getChartDetails(chartYAML string) (*v1alpha1.ChartDetails, error) { - // see: https://helm.sh/docs/topics/charts/ for more details - var chart struct { - Description string `yaml:"description,omitempty"` - Home string `yaml:"home,omitempty"` - Maintainers []struct { - Name string `yaml:"name,omitempty"` - Email string `yaml:"email,omitempty"` - Url string `yaml:"url,omitempty"` - } `yaml:"maintainers,omitempty"` - } + var chart Chart err := yaml.Unmarshal([]byte(chartYAML), &chart) if err != nil { return nil, fmt.Errorf("failed to unmarshal chart: %w", err) diff --git a/reposerver/repository/repository.go b/reposerver/repository/repository.go index 0937ff10d3667..260850888e50c 100644 --- a/reposerver/repository/repository.go +++ b/reposerver/repository/repository.go @@ -149,16 +149,16 @@ func (s *Service) Init() error { // give itself read permissions to list previously written directories err = os.Chmod(s.rootDir, 0700) } - var files []fs.DirEntry + var dirEntries []fs.DirEntry if err == nil { - files, err = os.ReadDir(s.rootDir) + dirEntries, err = os.ReadDir(s.rootDir) } if err != nil { log.Warnf("Failed to restore cloned repositories paths: %v", err) return nil } - for _, file := range files { + for _, file := range dirEntries { if !file.IsDir() { continue } @@ -175,7 +175,7 @@ func (s *Service) Init() error { return os.Chmod(s.rootDir, 0300) } -// List a subset of the refs (currently, branches and tags) of a git repo +// ListRefs List a subset of the refs (currently, branches and tags) of a git repo func (s *Service) ListRefs(ctx context.Context, q *apiclient.ListRefsRequest) (*apiclient.Refs, error) { gitClient, err := s.newClient(q.Repo) if err != nil { @@ -242,7 +242,7 @@ func (s *Service) ListPlugins(ctx context.Context, _ *empty.Empty) (*apiclient.P return nil, fmt.Errorf("failed to get plugins from dir %v, error=%w", pluginSockFilePath, err) } - plugins := []*apiclient.PluginInfo{} + var plugins []*apiclient.PluginInfo for _, file := range sockFiles { if file.Type() == os.ModeSocket { plugins = append(plugins, &apiclient.PluginInfo{Name: strings.TrimSuffix(file.Name(), ".sock")}) @@ -294,7 +294,7 @@ func (s *Service) runRepoOperation( refSources map[string]*v1alpha1.RefTarget) error { if sanitizer, ok := grpc.SanitizerFromContext(ctx); ok { - // make sure randomized path replaced with '.' in the error message + // make sure a randomized path replaced with '.' in the error message sanitizer.AddRegexReplacement(getRepoSanitizerRegex(s.rootDir), "") } @@ -459,38 +459,38 @@ type gitClientGetter func(repo *v1alpha1.Repository, revision string, opts ...gi // should be updated. func resolveReferencedSources(hasMultipleSources bool, source *v1alpha1.ApplicationSourceHelm, refSources map[string]*v1alpha1.RefTarget, newClientResolveRevision gitClientGetter) (map[string]string, error) { repoRefs := make(map[string]string) - if hasMultipleSources { - if source != nil { - for _, valueFile := range source.ValueFiles { - if strings.HasPrefix(valueFile, "$") { - refVar := strings.Split(valueFile, "/")[0] - - refSourceMapping, ok := refSources[refVar] - if !ok { - if len(refSources) == 0 { - return nil, fmt.Errorf("source referenced %q, but no source has a 'ref' field defined", refVar) - } - refKeys := make([]string, 0) - for refKey := range refSources { - refKeys = append(refKeys, refKey) - } - return nil, fmt.Errorf("source referenced %q, which is not one of the available sources (%s)", refVar, strings.Join(refKeys, ", ")) - } - if refSourceMapping.Chart != "" { - return nil, fmt.Errorf("source has a 'chart' field defined, but Helm charts are not yet not supported for 'ref' sources") - } - normalizedRepoURL := git.NormalizeGitURL(refSourceMapping.Repo.Repo) - _, ok = repoRefs[normalizedRepoURL] - if !ok { - _, referencedCommitSHA, err := newClientResolveRevision(&refSourceMapping.Repo, refSourceMapping.TargetRevision) - if err != nil { - log.Errorf("Failed to get git client for repo %s: %v", refSourceMapping.Repo.Repo, err) - return nil, fmt.Errorf("failed to get git client for repo %s", refSourceMapping.Repo.Repo) - } + if !hasMultipleSources || source == nil { + return repoRefs, nil + } - repoRefs[normalizedRepoURL] = referencedCommitSHA - } + for _, valueFile := range source.ValueFiles { + if strings.HasPrefix(valueFile, "$") { + refVar := strings.Split(valueFile, "/")[0] + + refSourceMapping, ok := refSources[refVar] + if !ok { + if len(refSources) == 0 { + return nil, fmt.Errorf("source referenced %q, but no source has a 'ref' field defined", refVar) + } + refKeys := make([]string, 0) + for refKey := range refSources { + refKeys = append(refKeys, refKey) } + return nil, fmt.Errorf("source referenced %q, which is not one of the available sources (%s)", refVar, strings.Join(refKeys, ", ")) + } + if refSourceMapping.Chart != "" { + return nil, fmt.Errorf("source has a 'chart' field defined, but Helm charts are not yet not supported for 'ref' sources") + } + normalizedRepoURL := git.NormalizeGitURL(refSourceMapping.Repo.Repo) + _, ok = repoRefs[normalizedRepoURL] + if !ok { + _, referencedCommitSHA, err := newClientResolveRevision(&refSourceMapping.Repo, refSourceMapping.TargetRevision) + if err != nil { + log.Errorf("Failed to get git client for repo %s: %v", refSourceMapping.Repo.Repo, err) + return nil, fmt.Errorf("failed to get git client for repo %s", refSourceMapping.Repo.Repo) + } + + repoRefs[normalizedRepoURL] = referencedCommitSHA } } } @@ -2097,7 +2097,7 @@ func populateHelmAppDetails(res *apiclient.RepoAppDetailsResponse, appPath strin for _, v := range fileParameters(q) { res.Helm.FileParameters = append(res.Helm.FileParameters, &v1alpha1.HelmFileParameter{ Name: v.Name, - Path: v.Path, //filepath.Join(appPath, v.Path), + Path: v.Path, // filepath.Join(appPath, v.Path), }) } return nil diff --git a/reposerver/repository/types.go b/reposerver/repository/types.go new file mode 100644 index 0000000000000..3e45a5bf3a1cf --- /dev/null +++ b/reposerver/repository/types.go @@ -0,0 +1,14 @@ +package repository + +// Chart see: https://helm.sh/docs/topics/charts/ for more details +type Chart struct { + Description string `yaml:"description,omitempty"` + Home string `yaml:"home,omitempty"` + Maintainers []Maintainer `yaml:"maintainers,omitempty"` +} + +type Maintainer struct { + Name string `yaml:"name,omitempty"` + Email string `yaml:"email,omitempty"` + Url string `yaml:"url,omitempty"` +}