Skip to content

Commit 088e6e2

Browse files
authored
Merge pull request #342 from daemon1024/fixes-and-enhancements
feat/fix(install): add verify flag and revert timeout
2 parents e4b8563 + 152d1cb commit 088e6e2

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

cmd/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var installCmd = &cobra.Command{
1818
Short: "Install KubeArmor in a Kubernetes Cluster",
1919
Long: `Install KubeArmor in a Kubernetes Clusters`,
2020
RunE: func(cmd *cobra.Command, args []string) error {
21-
installOptions.Animation = true
2221
if err := installOptions.Env.CheckAndSetValidEnvironmentOption(cmd.Flag("env").Value.String()); err != nil {
2322
return fmt.Errorf("error in checking environment option: %v", err)
2423
}
@@ -40,6 +39,7 @@ func init() {
4039
installCmd.Flags().StringVarP(&installOptions.Block, "block", "b", "", "Kubearmor Block Posture Context [all,file,network,capabilities]")
4140
installCmd.Flags().StringVarP(&installOptions.Visibility, "viz", "", "", "Kubearmor Telemetry Visibility [process,file,network,none]")
4241
installCmd.Flags().BoolVar(&installOptions.Save, "save", false, "Save KubeArmor Manifest ")
42+
installCmd.Flags().BoolVar(&installOptions.Verify, "verify", true, "Verify whether all KubeArmor resources are created, running and also probes whether KubeArmor has armored the cluster or not")
4343
installCmd.Flags().BoolVar(&installOptions.Local, "local", false, "Use Local KubeArmor Images (sets ImagePullPolicy to 'IfNotPresent') ")
4444
installCmd.Flags().StringVarP(&installOptions.Env.Environment, "env", "e", "", "Supported KubeArmor Environment [k3s,microK8s,minikube,gke,bottlerocket,eks,docker,oke,generic]")
4545

cmd/uninstall.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ var uninstallCmd = &cobra.Command{
1616
Short: "Uninstall KubeArmor from a Kubernetes Cluster",
1717
Long: `Uninstall KubeArmor from a Kubernetes Clusters`,
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
uninstallOptions.Animation = true
20-
if err := install.K8sUninstaller(client, uninstallOptions); err != nil {
21-
return err
22-
}
23-
return nil
19+
err := install.K8sUninstaller(client, uninstallOptions)
20+
return err
2421
},
2522
}
2623

2724
func init() {
2825
rootCmd.AddCommand(uninstallCmd)
2926

3027
uninstallCmd.Flags().StringVarP(&uninstallOptions.Namespace, "namespace", "n", "kube-system", "Namespace for resources")
31-
uninstallCmd.Flags().BoolVar(&uninstallOptions.Force, "force", false, "Force remove kubearmor annotations from deployments. (Deployments might be restarted)")
28+
uninstallCmd.Flags().BoolVar(&uninstallOptions.Force, "force", false, "Force remove KubeArmor annotations from deployments. (Deployments might be restarted)")
29+
uninstallCmd.Flags().BoolVar(&uninstallOptions.Verify, "verify", true, "Verify whether all KubeArmor resources are cleaned up or not")
3230
}

install/install.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Options struct {
4141
Force bool
4242
Local bool
4343
Save bool
44-
Animation bool
44+
Verify bool
4545
Env envOption
4646
}
4747

@@ -50,7 +50,7 @@ type envOption struct {
5050
Environment string
5151
}
5252

53-
var animation bool
53+
var verify bool
5454
var progress int
5555
var cursorcount int
5656
var validEnvironments = []string{"k3s", "microK8s", "minikube", "gke", "bottlerocket", "eks", "docker", "oke", "generic"}
@@ -102,17 +102,17 @@ func printBar(msg string, total int) int {
102102
func printAnimation(msg string, flag bool) int {
103103
clearLine(90)
104104
fmt.Printf(msg + "\n")
105-
if flag {
106-
progress++
105+
if verify {
106+
if flag {
107+
progress++
108+
}
109+
printBar("\tKubeArmor Installing ", 17)
107110
}
108-
printBar("\tKubeArmor Installing ", 17)
109111
return 0
110112
}
111113

112114
func printMessage(msg string, flag bool) int {
113-
if animation {
114-
printAnimation(msg, flag)
115-
}
115+
printAnimation(msg, flag)
116116
return 0
117117
}
118118

@@ -142,7 +142,8 @@ func checkPods(c *k8s.Client, o Options) {
142142
}
143143
}
144144
fmt.Print("\n🔧\tVerifying KubeArmor functionality (this may take upto a minute) ...")
145-
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
145+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
146+
146147
defer cancel()
147148

148149
for {
@@ -210,7 +211,7 @@ func checkTerminatingPods(c *k8s.Client) int {
210211

211212
// K8sInstaller for karmor install
212213
func K8sInstaller(c *k8s.Client, o Options) error {
213-
animation = o.Animation
214+
verify = o.Verify
214215
var env string
215216
if o.Env.Auto {
216217
env = k8s.AutoDetectEnvironment(c)
@@ -353,8 +354,9 @@ func K8sInstaller(c *k8s.Client, o Options) error {
353354
if o.Block == "all" || strings.Contains(o.Block, "capabilities") {
354355
daemonset.Spec.Template.Spec.Containers[0].Args = append(daemonset.Spec.Template.Spec.Containers[0].Args, "-defaultCapabilitiesPosture=block")
355356
}
356-
s := strings.Join(daemonset.Spec.Template.Spec.Containers[0].Args, " ")
357-
printMessage("🛡\tKubeArmor DaemonSet - Init "+daemonset.Spec.Template.Spec.InitContainers[0].Image+", Container "+daemonset.Spec.Template.Spec.Containers[0].Image+s+" ", true)
357+
358+
args := strings.Join(daemonset.Spec.Template.Spec.Containers[0].Args, " ")
359+
printMessage("🛡\tKubeArmor DaemonSet - Init "+daemonset.Spec.Template.Spec.InitContainers[0].Image+", Container "+daemonset.Spec.Template.Spec.Containers[0].Image+" "+args+" ", true)
358360

359361
if !o.Save {
360362
if _, err := c.K8sClientset.AppsV1().DaemonSets(o.Namespace).Create(context.Background(), daemonset, metav1.CreateOptions{}); err != nil {
@@ -369,7 +371,7 @@ func K8sInstaller(c *k8s.Client, o Options) error {
369371

370372
caCert, tlsCrt, tlsKey, err := GeneratePki(o.Namespace, deployments.KubeArmorControllerWebhookServiceName)
371373
if err != nil {
372-
printMessage("C\tldn't generate TLS secret ", false)
374+
printMessage("Couldn't generate TLS secret ", false)
373375
return err
374376
}
375377
kubearmorControllerTLSSecret := deployments.GetKubeArmorControllerTLSSecret(o.Namespace, caCert.String(), tlsCrt.String(), tlsKey.String())
@@ -561,7 +563,7 @@ func K8sInstaller(c *k8s.Client, o Options) error {
561563
printMessage("🤩\tKubeArmor manifest file saved to \033[1m"+s3+"\033[0m", false)
562564

563565
}
564-
if animation && !o.Save {
566+
if verify && !o.Save {
565567
checkPods(c, o)
566568
}
567569
return nil
@@ -616,7 +618,7 @@ func removeAnnotations(c *k8s.Client) {
616618

617619
// K8sUninstaller for karmor uninstall
618620
func K8sUninstaller(c *k8s.Client, o Options) error {
619-
animation = o.Animation
621+
verify = o.Verify
620622

621623
fmt.Print("❌ KubeArmor Deployments ...\n")
622624
kaDeployments, _ := c.K8sClientset.AppsV1().Deployments("").List(context.TODO(), metav1.ListOptions{LabelSelector: "kubearmor-app"})
@@ -787,7 +789,7 @@ func K8sUninstaller(c *k8s.Client, o Options) error {
787789

788790
removeAnnotations(c)
789791
}
790-
if animation {
792+
if verify {
791793
checkTerminatingPods(c)
792794
}
793795
return nil

0 commit comments

Comments
 (0)