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

Commit

Permalink
Sketch out generator interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoodwin committed Jun 16, 2020
1 parent b7d7bde commit 391e4de
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 28 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ApplicationSetTemplate struct {

// ApplicationSetGenerator include list item info
type ApplicationSetGenerator struct {
List *ListGenerator `json:"list, omitempty"`
List *ListGenerator `json:"list,omitempty"`
Clusters *ClusterGenerator `json:"clusters,omitempty"`
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/yudai/gojsondiff v1.0.1-0.20180504020246-0525c875b75c // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
Expand Down
27 changes: 27 additions & 0 deletions pkg/generators/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package generators

import (
"fmt"
argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
)

var _ Generator = (*ClusterGenerator)(nil)

// ClusterGenerator generates Applications for some or all clusters registered with ArgoCD.
type ClusterGenerator struct {
}

func NewClusterGenerator() Generator {
// TODO: pass client or informer for access to cluster secrets
g := &ClusterGenerator{}
return g
}

func (g *ClusterGenerator) GenerateApplications(appSet *argoprojiov1alpha1.ApplicationSet) ([]argov1alpha1.Application, error) {
if appSet == nil {
return nil, fmt.Errorf("ApplicationSet is empty")
}

return nil, nil
}
27 changes: 0 additions & 27 deletions pkg/generators/generator.go

This file was deleted.

14 changes: 14 additions & 0 deletions pkg/generators/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package generators

import (
argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
)

// Generator defines the interface implemented by all ApplicationSet generators.
type Generator interface {
// GenerateApplications interprets the ApplicationSet and generates all relevant Applications.
// The expected / desired list of Applications is returned, it then needs to be reconciled
// against the current state of the Applications in the cluster.
GenerateApplications(appSet *argoprojiov1alpha1.ApplicationSet) ([]argov1alpha1.Application, error)
}
25 changes: 25 additions & 0 deletions pkg/generators/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package generators

import (
"fmt"
argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
)

var _ Generator = (*ListGenerator)(nil)

type ListGenerator struct {
}

func NewListGenerator() Generator {
g := &ListGenerator{}
return g
}

func (g *ListGenerator) GenerateApplications(appSet *argoprojiov1alpha1.ApplicationSet) ([]argov1alpha1.Application, error) {
if appSet == nil {
return nil, fmt.Errorf("ApplicationSet is empty")
}

return nil, nil
}

0 comments on commit 391e4de

Please sign in to comment.