diff --git a/.github/workflows/ci-go.yml b/.github/workflows/ci-go.yml index 730df586..025cb55d 100644 --- a/.github/workflows/ci-go.yml +++ b/.github/workflows/ci-go.yml @@ -7,6 +7,19 @@ on: branches: [main] jobs: + go-build: + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: v1.16 + + - name: Build karmor + run: make + go-fmt: runs-on: ubuntu-latest steps: diff --git a/cmd/install.go b/cmd/install.go index 1fdf312d..42dcd421 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -27,4 +27,5 @@ func init() { rootCmd.AddCommand(installCmd) installCmd.Flags().StringVarP(&installOptions.Namespace, "namespace", "n", "kube-system", "Namespace for resources") + installCmd.Flags().StringVarP(&installOptions.KubearmorImage, "image", "i", "kubearmor/kubearmor:latest", "Kubearmor daemonset image to use") } diff --git a/cmd/vm.go b/cmd/vm.go index c429a134..a728aa84 100644 --- a/cmd/vm.go +++ b/cmd/vm.go @@ -4,6 +4,8 @@ package cmd import ( + "fmt" + "github.com/kubearmor/kubearmor-client/vm" "github.com/spf13/cobra" ) @@ -34,5 +36,8 @@ func init() { vmCmd.Flags().StringVarP(&vmOptions.File, "file", "f", "none", "Filename with path to store the configured vm installation script") // Marking this flag as markedFlag and mandatory - vmCmd.MarkFlagRequired("kvm") + err := vmCmd.MarkFlagRequired("kvm") + if err != nil { + _ = fmt.Errorf("kvm option not supplied") + } } diff --git a/go.mod b/go.mod index 59141638..cf6076fb 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,8 @@ require ( github.com/spf13/cobra v1.2.1 golang.org/x/mod v0.5.1 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.26.0 k8s.io/api v0.22.3 k8s.io/apiextensions-apiserver v0.22.3 k8s.io/apimachinery v0.22.3 diff --git a/install/install.go b/install/install.go index de6f1862..47fe0d75 100644 --- a/install/install.go +++ b/install/install.go @@ -14,10 +14,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// Options for karmor install type Options struct { - Namespace string + Namespace string + KubearmorImage string } +// K8sInstaller for karmor install func K8sInstaller(c *k8s.Client, o Options) error { env := autoDetectEnvironment(c) if env == "none" { @@ -66,8 +69,8 @@ func K8sInstaller(c *k8s.Client, o Options) error { } fmt.Print("KubeArmor Relay Deployment already exists ...\n") } - fmt.Print("KubeArmor DaemonSet ...\n") - if _, err := c.K8sClientset.AppsV1().DaemonSets(o.Namespace).Create(context.Background(), generateDaemonSet(env), metav1.CreateOptions{}); err != nil { + fmt.Printf("KubeArmor DaemonSet %s...\n", o.KubearmorImage) + if _, err := c.K8sClientset.AppsV1().DaemonSets(o.Namespace).Create(context.Background(), generateDaemonSet(env, o), metav1.CreateOptions{}); err != nil { if !strings.Contains(err.Error(), "already exists") { return err } @@ -104,6 +107,7 @@ func K8sInstaller(c *k8s.Client, o Options) error { return nil } +// K8sUninstaller for karmor uninstall func K8sUninstaller(c *k8s.Client, o Options) error { fmt.Print("Service Account ...\n") if err := c.K8sClientset.CoreV1().ServiceAccounts(o.Namespace).Delete(context.Background(), serviceAccountName, metav1.DeleteOptions{}); err != nil { diff --git a/install/resource.go b/install/resource.go index 89391a5a..f171c76a 100644 --- a/install/resource.go +++ b/install/resource.go @@ -265,7 +265,7 @@ var hostPolicyManagerDeployment = &appsv1.Deployment{ }, } -func generateDaemonSet(env string) *appsv1.DaemonSet { +func generateDaemonSet(env string, o Options) *appsv1.DaemonSet { var label = map[string]string{ "kubearmor-app": kubearmor, @@ -388,7 +388,7 @@ func generateDaemonSet(env string) *appsv1.DaemonSet { Containers: []corev1.Container{ { Name: kubearmor, - Image: "kubearmor/kubearmor:latest", + Image: o.KubearmorImage, // "kubearmor/kubearmor:latest", //imagePullPolicy is Always since image has latest tag SecurityContext: &corev1.SecurityContext{ Privileged: &privileged, diff --git a/version/version.go b/version/version.go index 8be30746..69f0dc67 100644 --- a/version/version.go +++ b/version/version.go @@ -12,9 +12,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// GitSummary for karmor git build var GitSummary string + +// BuildDate for karmor git build var BuildDate string +// PrintVersion handler for karmor version func PrintVersion(c *k8s.Client) error { fmt.Printf("karmor version %s %s/%s BuildDate=%s\n", GitSummary, runtime.GOOS, runtime.GOARCH, BuildDate) kubearmorVersion, err := getKubeArmorVersion(c) diff --git a/vm/vm.go b/vm/vm.go index bde75ae4..1cd83a09 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -14,6 +14,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// Options for karmor vm type Options struct { Port string VMName string @@ -80,6 +81,7 @@ func getClusterIP(c *k8s.Client, options Options) (string, error) { return externalIP, err } +// FileDownload handler for karmor vm --file func FileDownload(c *k8s.Client, options Options) error { // Get the list of namespaces in kubernetes context