Skip to content

Commit

Permalink
Nobletrout/add kubectx support (#719)
Browse files Browse the repository at this point in the history
* See #699 add support for kubecontext selection

* Update cli.md
  • Loading branch information
nobletrout authored Mar 15, 2022
1 parent 06322dc commit f429f19
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/polaris/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var disallowExemptions, disallowConfigExemptions, disallowAnnotationExemptions b
var logLevel string
var auditPath string
var displayName string
var kubeContext string

var (
version string
Expand All @@ -37,6 +38,7 @@ var (
func init() {
// Flags
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "Location of Polaris configuration file.")
rootCmd.PersistentFlags().StringVarP(&kubeContext, "context", "x", "", "Set the kube context.")
rootCmd.PersistentFlags().BoolVarP(&disallowExemptions, "disallow-exemptions", "", false, "Disallow any configured exemption.")
rootCmd.PersistentFlags().BoolVarP(&disallowConfigExemptions, "disallow-config-exemptions", "", false, "Disallow exemptions set within the configuration file.")
rootCmd.PersistentFlags().BoolVarP(&disallowAnnotationExemptions, "disallow-annotation-exemptions", "", false, "Disallow any exemption defined as a controller annotation.")
Expand Down Expand Up @@ -68,6 +70,7 @@ var rootCmd = &cobra.Command{
config.DisallowExemptions = disallowExemptions
config.DisallowConfigExemptions = disallowConfigExemptions
config.DisallowAnnotationExemptions = disallowAnnotationExemptions
config.KubeContext = kubeContext
},
Run: func(cmd *cobra.Command, args []string) {
logrus.Error("You must specify a sub-command.")
Expand Down
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ webhook
# global flags
-c, --config string Location of Polaris configuration file.
-x, --context string Set the kube context.
--disallow-exemptions Disallow any exemptions from configuration file.
--disallow-config-exemptions Disallow exemptions set within the configuration file.
--disallow-annotation-exemptions Disallow any exemption defined as a controller annotation.
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Configuration struct {
DisallowExemptions bool `json:"disallowExemptions"`
DisallowConfigExemptions bool `json:"disallowConfigExemptions"`
DisallowAnnotationExemptions bool `json:"disallowAnnotationExemptions"`
KubeContext string `json:"kubeContext"`
}

// Exemption represents an exemption to normal rules
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func CreateResourceProviderFromPath(directory string) (*ResourceProvider, error)

// CreateResourceProviderFromCluster creates a new ResourceProvider using live data from a cluster
func CreateResourceProviderFromCluster(ctx context.Context, c conf.Configuration) (*ResourceProvider, error) {
kubeConf, configError := config.GetConfig()
kubeConf, configError := config.GetConfigWithContext(c.KubeContext)
if configError != nil {
logrus.Errorf("Error fetching KubeConfig: %v", configError)
return nil, configError
Expand Down

0 comments on commit f429f19

Please sign in to comment.