Skip to content

Commit

Permalink
Merge pull request #28 from nyrahul/main
Browse files Browse the repository at this point in the history
  • Loading branch information
daemon1024 committed Nov 29, 2021
2 parents 83199ee + 7d44a7e commit 9ac3b09
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
7 changes: 6 additions & 1 deletion cmd/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package cmd

import (
"fmt"

"github.com/kubearmor/kubearmor-client/vm"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -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")
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions install/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Options for karmor vm
type Options struct {
Port string
VMName string
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ac3b09

Please sign in to comment.