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

Commit

Permalink
error out if invalid flag combination has been set
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Morsing committed Sep 24, 2019
1 parent 1ff8d03 commit c8edd7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/manager/main.go
Expand Up @@ -62,6 +62,12 @@ func main() {
flag.CommandLine.AddGoFlagSet(logFlags)
flag.Parse()

err = farosflags.ValidateSettings()
if err != nil {
log.Error(err, "Invalid flags set")
return
}

// Handle version flag
if *showVersion {
fmt.Printf("faros-gittrack-controller %s (built with %s)\n", VERSION, runtime.Version())
Expand Down
13 changes: 13 additions & 0 deletions pkg/flags/flagset.go
Expand Up @@ -87,6 +87,19 @@ func ParseIgnoredResources() (map[schema.GroupVersionResource]interface{}, error
return gvrs, nil
}

// ValidateSettings returns an error if an invalid set of options have been set in the flags.
// It must be called after the flags have been parsed
func ValidateSettings() error {
if !FlagSet.Parsed() {
return fmt.Errorf("ValidateSettings called on unparsed flags")
}

if GitTrack == GTMEnabled && Namespace != "" && ClusterGitTrack == CGTMIncludeNamespaced {
return fmt.Errorf("Cannot use gittrack-mode enabled with namespace %q and clustergittrack-mode set to IncludeNamespaced", Namespace)
}
return nil
}

// ClusterGitTrackMode specifies which mode we're running ClusterGitTracks in
type ClusterGitTrackMode int

Expand Down

0 comments on commit c8edd7a

Please sign in to comment.