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

Commit

Permalink
fixup naming nits, use consistent handling of GitTrack mode and Clust…
Browse files Browse the repository at this point in the history
…erGitTrack mode
  • Loading branch information
Daniel Morsing committed Sep 11, 2019
1 parent b74ce9c commit a7e92c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
8 changes: 4 additions & 4 deletions pkg/controller/gittrack/gittrack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func newReconciler(mgr manager.Manager) (reconcile.Reconciler, *reconcileGitTrac
mutex: &sync.RWMutex{},
applier: applier,
log: rlogr.Log.WithName("gittrack-controller"),
handleGitTracks: farosflags.HandleGitTracks,
gitTrackMode: farosflags.GitTrack,
namespace: farosflags.Namespace,
clusterGitTrackMode: farosflags.ClusterGitTrack,
}
Expand All @@ -98,7 +98,7 @@ func newReconciler(mgr manager.Manager) (reconcile.Reconciler, *reconcileGitTrac

type reconcileGitTrackOpts struct {
clusterGitTrackMode farosflags.ClusterGitTrackMode
handleGitTracks bool
gitTrackMode farosflags.GitTrackMode
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
Expand All @@ -109,7 +109,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, opts *reconcileGitTrackOpt
return err
}

if opts.handleGitTracks {
if opts.gitTrackMode == farosflags.GTMEnabled {
// Watch for changes to GitTrack
err = c.Watch(&source.Kind{Type: &farosv1alpha1.GitTrack{}}, &handler.EnqueueRequestForObject{})
if err != nil {
Expand Down Expand Up @@ -164,7 +164,7 @@ type ReconcileGitTrack struct {
applier farosclient.Client
log logr.Logger

handleGitTracks bool
gitTrackMode farosflags.GitTrackMode
namespace string
clusterGitTrackMode farosflags.ClusterGitTrackMode
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/gittrack/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

farosv1alpha1 "github.com/pusher/faros/pkg/apis/faros/v1alpha1"
gittrackutils "github.com/pusher/faros/pkg/controller/gittrack/utils"
farosflags "github.com/pusher/faros/pkg/flags"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
Expand Down Expand Up @@ -81,7 +82,7 @@ func (r *ReconcileGitTrack) handleGitTrack(gt farosv1alpha1.GitTrackInterface) h
// don't reconcile if it's a gittrack and they're disabled
// we shouldn't ever get here because reconcile should be turned off at the controller level,
// but for testing and safeguarding, check anyway
if _, ok := gt.(*farosv1alpha1.ClusterGitTrack); ok && !r.handleGitTracks {
if _, ok := gt.(*farosv1alpha1.ClusterGitTrack); ok && r.gitTrackMode == farosflags.GTMDisabled {
return result
}

Expand Down
30 changes: 18 additions & 12 deletions pkg/flags/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var (
// FetchTimeout in seconds for fetching changes from repositories
FetchTimeout time.Duration

// HandleGitTracks specifies if we're handling GitTracks
HandleGitTracks HandleGitTrackMode
// GitTrack specifies if we're handling GitTracks
GitTrack GitTrackMode

// ClusterGitTrack specifies which mode we're handling ClusterGitTracks in
ClusterGitTrack ClusterGitTrackMode
Expand All @@ -60,7 +60,7 @@ func init() {
FlagSet.BoolVar(&ServerDryRun, "server-dry-run", true, "Enable/Disable server side dry run before updating resources")
FlagSet.DurationVar(&FetchTimeout, "fetch-timeout", 30*time.Second, "Timeout in seconds for fetching changes from repositories")
FlagSet.StringVar(&RepositoryDir, "repository-dir", "", "Directory in which to clone repositories. Defaults to cloning in memory if unset.")
FlagSet.Var(&HandleGitTracks, "gittrack-mode", "Whether to manage GitTracks. Valid values are Disabled and Enabled")
FlagSet.Var(&GitTrack, "gittrack-mode", "Whether to manage GitTracks. Valid values are Disabled and Enabled")
FlagSet.Var(&ClusterGitTrack, "clustergittrack-mode", "How to manage ClusterGitTracks. Valid values are Disabled, IncludeNamespaced and ExcludeNamespaced")
}

Expand Down Expand Up @@ -133,33 +133,39 @@ func (cgtm ClusterGitTrackMode) Type() string {
return "ClusterGitTrackMode"
}

// HandleGitTrackMode specifies which mode we're running GitTracks in
type HandleGitTrackMode bool
// GitTrackMode specifies which mode we're running GitTracks in
type GitTrackMode bool

// Enums for GitTrackMode
const (
GTMDisabled GitTrackMode = false
GTMEnabled GitTrackMode = true
)

// String implements the flag.Value interface
func (hgtm HandleGitTrackMode) String() string {
if hgtm {
func (gtm GitTrackMode) String() string {
if gtm {
return "Enabled"
}
return "Disabled"
}

// Set implements the flag.Value interface
func (hgtm *HandleGitTrackMode) Set(s string) error {
func (gtm *GitTrackMode) Set(s string) error {
lowered := strings.ToLower(s)
switch lowered {
case "disabled":
*hgtm = false
*gtm = false
return nil
case "enabled":
*hgtm = true
*gtm = true
return nil
default:
return fmt.Errorf("invalid value %q for gittrack-mode; valid values are Disabled and Enabled", s)
}
}

// Type implements the flag.Value interface
func (hgtm *HandleGitTrackMode) Type() string {
return "HandleGitTrackMode"
func (hgtm *GitTrackMode) Type() string {
return "GitTrackMode"
}

0 comments on commit a7e92c8

Please sign in to comment.