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

Commit

Permalink
Sketch out an interface for generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoodwin committed Jun 15, 2020
1 parent 80f5081 commit 75f58c7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dylib
bin
vendor
dist

# Test binary, build with `go test -c`
*.test
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
6 changes: 3 additions & 3 deletions pkg/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// ApplicationSetReconciler reconciles a ApplicationSet object
type ApplicationSetReconciler struct {
client.Client
Scheme *runtime.Scheme
Scheme *runtime.Scheme
Recorder record.EventRecorder
}

Expand All @@ -42,8 +42,8 @@ func (r *ApplicationSetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
ctx := context.Background()
_ = log.WithField("applicationset", req.NamespacedName)

var applicationSetInfo argoprojiov1alpha1.ApplicationSet
if err := r.Get(ctx, req.NamespacedName, &applicationSetInfo); err != nil {
var appSet argoprojiov1alpha1.ApplicationSet
if err := r.Get(ctx, req.NamespacedName, &appSet); err != nil {
log.Info("Unable to fetch applicationSetInfo %v", err)

return ctrl.Result{}, client.IgnoreNotFound(err)
Expand Down
30 changes: 30 additions & 0 deletions pkg/generators/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package generators

import (
"fmt"
argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ Generator = (*ClusterGenerator)(nil)

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

func NewClusterGenerator(client client.Client) Generator {
g := &ClusterGenerator{
commonClient: client,
}
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)
}
29 changes: 29 additions & 0 deletions pkg/generators/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package generators

import (
"fmt"
argoprojiov1alpha1 "github.com/argoproj-labs/applicationset/api/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ Generator = (*ListGenerator)(nil)

type ListGenerator struct {
commonClient client.Client
}

func NewListGenerator(client client.Client) Generator {
g := &ListGenerator{
commonClient: client,
}
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 75f58c7

Please sign in to comment.