Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated install command to receive env as argument #265

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"fmt"
"github.com/kubearmor/kubearmor-client/install"
"github.com/spf13/cobra"
)
Expand All @@ -17,6 +18,9 @@ var installCmd = &cobra.Command{
Long: `Install KubeArmor in a Kubernetes Clusters`,
RunE: func(cmd *cobra.Command, args []string) error {
installOptions.Animation = true
if err := installOptions.Env.CheckAndSetValidEnvironmentOption(cmd.Flag("env").Value.String()); err != nil {
return fmt.Errorf("error in checking environment option: %v", err)
}
if err := install.K8sInstaller(client, installOptions); err != nil {
return err
}
Expand All @@ -32,5 +36,6 @@ func init() {
installCmd.Flags().StringVarP(&installOptions.Audit, "audit", "a", "", "Kubearmor Audit Posture Context [all,file,network,capabilities]")
installCmd.Flags().StringVarP(&installOptions.Block, "block", "b", "", "Kubearmor Block Posture Context [all,file,network,capabilities]")
installCmd.Flags().BoolVar(&installOptions.Save, "save", false, "Save KubeArmor Manifest ")
installCmd.Flags().StringVarP(&installOptions.Env.Environment, "env", "e", "", "Supported KubeArmor Environment [k3s,microK8s,minikube,gke,bottlerocket,eks,docker,oke,generic]")

}
37 changes: 33 additions & 4 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,34 @@ type Options struct {
Force bool
Save bool
Animation bool
Env envOption
}

type envOption struct {
Auto bool
Environment string
}

var animation bool
var progress int
var cursorcount int
var validEnvironments = []string{"k3s", "microK8s", "minikube", "gke", "bottlerocket", "eks", "docker", "oke", "generic"}

// Checks if passed string is a valid environment
func (env *envOption) CheckAndSetValidEnvironmentOption(envOption string) error {
if envOption == "" {
env.Auto = true
return nil
}
for _, v := range validEnvironments {
if v == envOption {
env.Environment = envOption
env.Auto = false
return nil
}
}
return errors.New("Invalid environment passed")
}

func clearLine(size int) int {
for i := 0; i < size; i++ {
Expand Down Expand Up @@ -147,11 +170,17 @@ func checkTerminatingPods(c *k8s.Client) int {
// K8sInstaller for karmor install
func K8sInstaller(c *k8s.Client, o Options) error {
animation = o.Animation
env := AutoDetectEnvironment(c)
if env == "none" {
return errors.New("unsupported environment or cluster not configured correctly")
var env string
if o.Env.Auto {
env = AutoDetectEnvironment(c)
if env == "none" {
return errors.New("unsupported environment or cluster not configured correctly")
}
printMessage("😄 Auto Detected Environment : "+env, true)
} else {
env = o.Env.Environment
printMessage("😄 Environment : "+env, true)
}
printMessage("😄 Auto Detected Environment : "+env, true)

var printYAML []interface{}

Expand Down
1 change: 1 addition & 0 deletions utils/portforward.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package utils provides utility for port forwarding.
package utils

import (
Expand Down