Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion reposerver/gpgwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 1 addition & 10 deletions reposerver/repository/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 37 additions & 37 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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")})
Expand Down Expand Up @@ -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), "<path to cached source>")
}

Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions reposerver/repository/types.go
Original file line number Diff line number Diff line change
@@ -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"`
}