mirror of
https://github.com/vee1e/kubearmor-client.git
synced 2026-09-01 18:28:04 +00:00
* update default namespace to "kubearmor" Signed-off-by: Ankur Kothiwal <ankur.kothiwal99@gmail.com> * create default ns(kubearmor) before installing KubeArmor Signed-off-by: Ankur Kothiwal <ankur.kothiwal99@gmail.com> --------- Signed-off-by: Ankur Kothiwal <ankur.kothiwal99@gmail.com>
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2021 Authors of KubeArmor
|
|
|
|
// Package version checks the current CLI version and if there's a need to update it
|
|
package version
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"runtime"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/kubearmor/kubearmor-client/k8s"
|
|
"github.com/kubearmor/kubearmor-client/selfupdate"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
// PrintVersion handler for karmor version
|
|
func PrintVersion(c *k8s.Client) error {
|
|
fmt.Printf("karmor version %s %s/%s BuildDate=%s\n", selfupdate.GitSummary, runtime.GOOS, runtime.GOARCH, selfupdate.BuildDate)
|
|
latest, latestVer := selfupdate.IsLatest(selfupdate.GitSummary)
|
|
if !latest {
|
|
color.HiMagenta("update available version " + latestVer)
|
|
color.HiMagenta("use [karmor selfupdate] to update to latest")
|
|
}
|
|
kubearmorVersion, err := getKubeArmorVersion(c)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
if kubearmorVersion == "" {
|
|
fmt.Printf("kubearmor not running\n")
|
|
return nil
|
|
}
|
|
fmt.Printf("kubearmor image (running) version %s\n", kubearmorVersion)
|
|
return nil
|
|
}
|
|
|
|
func getKubeArmorVersion(c *k8s.Client) (string, error) {
|
|
pods, err := c.K8sClientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{LabelSelector: "kubearmor-app=kubearmor"})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if len(pods.Items) > 0 {
|
|
image := pods.Items[0].Spec.Containers[0].Image
|
|
return image, nil
|
|
}
|
|
return "", nil
|
|
}
|