Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Initial work on implementing GitFileGenerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtnpro committed Sep 9, 2020
1 parent 11c59c0 commit 663e525
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ type ClusterGenerator struct {
type GitGenerator struct {
RepoURL string `json:"repoURL"`
Directories []GitDirectoryGeneratorItem `json:"directories,omitempty"`
Files []GitFileGeneratorItem `json:"files,omitempty"`
Revision string `json:"revision"`
}

type GitDirectoryGeneratorItem struct {
Path string `json:"path"`
}

type GitFileGeneratorItem struct {
Path string `json:"path"`
}

// +kubebuilder:object:root=true

// ApplicationSetList contains a list of ApplicationSet
Expand Down
47 changes: 28 additions & 19 deletions pkg/generators/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package generators
import (
"context"
"fmt"
"path"

argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
"github.com/argoproj-labs/applicationset/pkg/services"
"github.com/argoproj-labs/applicationset/pkg/utils"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
log "github.com/sirupsen/logrus"
"path"
)

var _ Generator = (*GitGenerator)(nil)
Expand All @@ -33,22 +34,26 @@ func (g *GitGenerator) GenerateApplications(appSetGenerator *argoprojiov1alpha1.
return nil, fmt.Errorf("git variable empty")
}

allApps, err := g.repos.GetApps(context.TODO(), appSetGenerator.Git.RepoURL, appSetGenerator.Git.Revision)
if err != nil {
return nil, err
var res []argov1alpha1.Application
if appSetGenerator.Git.Directories != nil {
allApps, err := g.repos.GetApps(context.TODO(), appSetGenerator.Git.RepoURL, appSetGenerator.Git.Revision)
if err != nil {
return nil, err
}
log.WithFields(log.Fields{
"allAps": allApps,
"total": len(allApps),
"repoURL": appSetGenerator.Git.RepoURL,
"revision": appSetGenerator.Git.Revision,
}).Info("applications result from the repo service")
requestedApps := g.filter(appSetGenerator.Git.Directories, allApps)
res = g.generateApplicationsFromApps(requestedApps, appSet)
} else if appSetGenerator.Git.Files != nil {
// TODO
// get config list from matching file paths from repo service
// res = g.generateApplicationsFromConfigs(configs, appSet)
}

log.WithFields(log.Fields{
"allAps": allApps,
"total": len(allApps),
"repoURL": appSetGenerator.Git.RepoURL,
"revision": appSetGenerator.Git.Revision,
}).Info("applications result from the repo service")

requestedApps := g.filter(appSetGenerator.Git.Directories, allApps)

res := g.generateApplications(requestedApps, appSet)

return res, nil
}

Expand All @@ -70,11 +75,16 @@ func (g *GitGenerator) filter(Directories []argoprojiov1alpha1.GitDirectoryGener
return res
}

func (g *GitGenerator) generateApplications(requestedApps []string, appSet *argoprojiov1alpha1.ApplicationSet) ([]argov1alpha1.Application) {
func (g *GitGenerator) generateApplicationsFromConfigs(configs []map[string]interface{}, appSet *argoprojiov1alpha1.ApplicationSet) []argov1alpha1.Application {
// TODO
return nil
}

func (g *GitGenerator) generateApplicationsFromApps(requestedApps []string, appSet *argoprojiov1alpha1.ApplicationSet) []argov1alpha1.Application {

res := make([]argov1alpha1.Application, len(requestedApps))
for i, a := range requestedApps {
app, err := g.generateApplication(appSet, a)
app, err := g.generateApplicationFromAppPath(appSet, a)
if err != nil {
log.WithError(err).WithField("app", a).Error("error while generating app")
continue
Expand All @@ -85,8 +95,7 @@ func (g *GitGenerator) generateApplications(requestedApps []string, appSet *argo
return res
}


func (g *GitGenerator) generateApplication(appSet *argoprojiov1alpha1.ApplicationSet, appPath string) (*argov1alpha1.Application, error) {
func (g *GitGenerator) generateApplicationFromAppPath(appSet *argoprojiov1alpha1.ApplicationSet, appPath string) (*argov1alpha1.Application, error) {
var tmplApplication argov1alpha1.Application
tmplApplication.Namespace = appSet.Spec.Template.Namespace
tmplApplication.Name = appSet.Spec.Template.Name
Expand Down

0 comments on commit 663e525

Please sign in to comment.