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

Enabled operator installation for karmor #402

Merged
merged 3 commits into from
Mar 14, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci-ginkgo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
steps:
- name: Checkout Source
uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: "v1.21"
go-version-file: './go.mod'
- name: Create k8s Kind Cluster
uses: helm/[email protected]
- name: Test connectivity
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v2

- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: "v1.21"
go-version-file: './go.mod'

- name: Build karmor
run: make
Expand All @@ -29,9 +29,9 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v2

- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: "v1.21"
go-version-file: './go.mod'

- name: Check gofmt
run: make gofmt
Expand All @@ -42,9 +42,9 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v2

- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: "v1.21"
go-version-file: './go.mod'

- name: Run Gosec Security Scanner
run: make gosec
Expand All @@ -66,9 +66,9 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v2

- uses: actions/setup-go@v2
- uses: actions/setup-go@v5
with:
go-version: "v1.21"
go-version-file: './go.mod'

- name: Run unit tests
run: make test
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -70,4 +74,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
32 changes: 25 additions & 7 deletions cmd/install.go
rootxrishabh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,53 @@ var installCmd = &cobra.Command{
Short: "Install KubeArmor in a Kubernetes Cluster",
Long: `Install KubeArmor in a Kubernetes Clusters`,
RunE: func(cmd *cobra.Command, args []string) error {
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
if installOptions.Legacy {
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.K8sLegacyInstaller(client, installOptions); err != nil {
return fmt.Errorf("error installing kubearmor in legacy mode: %v", err)
}
} else {
if err := install.K8sInstaller(client, installOptions); err != nil {
return fmt.Errorf("error installing kubearmor: %v", err)
}
}
return nil
},
}

func markDeprecated(cmd *cobra.Command, flag, message string) {
if err := cmd.Flags().MarkDeprecated(flag, message); err != nil {
fmt.Printf("Error marking '%s' as deprecated: %v\n", flag, err)
}
}

func init() {
rootCmd.AddCommand(installCmd)

installCmd.Flags().StringVarP(&installOptions.Namespace, "namespace", "n", "kubearmor", "Namespace for resources")
installCmd.Flags().StringVarP(&installOptions.KubearmorImage, "image", "i", "kubearmor/kubearmor:stable", "Kubearmor daemonset image to use")
installCmd.Flags().StringVarP(&installOptions.InitImage, "init-image", "", "kubearmor/kubearmor-init:stable", "Kubearmor daemonset init container image to use")
installCmd.Flags().StringVarP(&installOptions.OperatorImage, "operator-image", "", "kubearmor/kubearmor-operator:latest", "Kubearmor operator container image to use")
installCmd.Flags().StringVarP(&installOptions.ControllerImage, "controller-image", "", "kubearmor/kubearmor-controller:latest", "Kubearmor controller image to use")
installCmd.Flags().StringVarP(&installOptions.RelayImage, "relay-image", "", "kubearmor/kubearmor-relay-server:latest", "Kubearmor relay image to use")
installCmd.Flags().StringVarP(&installOptions.KubeArmorTag, "tag", "t", "", "Change image tag/version for default kubearmor images (This will overwrite the tags provided in --image/--init-image)")
installCmd.Flags().StringVarP(&installOptions.KubeArmorRelayTag, "relay-tag", "", "", "Change image tag/version for default kubearmor-relay image (This will overwrite the tag provided in --relay-image)")
installCmd.Flags().StringVarP(&installOptions.KubeArmorControllerTag, "controller-tag", "", "", "Change image tag/version for default kubearmor-controller image (This will overwrite the tag provided in --controller-image)")
installCmd.Flags().StringVarP(&installOptions.KubeArmorOperatorTag, "operator-tag", "", "", "Change image tag/version for default kubearmor-operator image (This will overwrite the tag provided in --operator-image)")
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().StringVarP(&installOptions.Visibility, "viz", "", "", "Kubearmor Telemetry Visibility [process,file,network,none]")
installCmd.Flags().BoolVar(&installOptions.Save, "save", false, "Save KubeArmor Manifest ")
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")
rootxrishabh marked this conversation as resolved.
Show resolved Hide resolved
installCmd.Flags().BoolVar(&installOptions.Local, "local", false, "Use Local KubeArmor Images (sets ImagePullPolicy to 'IfNotPresent') ")
installCmd.Flags().StringVarP(&installOptions.Env.Environment, "env", "e", "", "Supported KubeArmor Environment [k0s,k3s,microK8s,minikube,gke,bottlerocket,eks,docker,oke,generic]")
installCmd.Flags().StringVarP(&installOptions.ImageRegistry, "registry", "r", "", "Image registry to use to pull the images")
installCmd.Flags().BoolVar(&installOptions.Legacy, "legacy", false, "Installs kubearmor in legacy mode if set to true")
rootxrishabh marked this conversation as resolved.
Show resolved Hide resolved
installCmd.Flags().BoolVar(&installOptions.SkipDeploy, "skip-deploy", false, "Saves kubearmor operator CR manifest rather than deploying it")
installCmd.Flags().BoolVar(&installOptions.PreserveUpstream, "preserve-upstream", true, "Do not override the image registry when using -r flag, prefix only")

installCmd.Flags().StringVarP(&installOptions.Env.Environment, "env", "e", "", "Supported KubeArmor Environment [k0s,k3s,microK8s,minikube,gke,bottlerocket,eks,docker,oke,generic]")
installCmd.MarkFlagsMutuallyExclusive("verify", "save")
markDeprecated(installCmd, "env", "Only relevant when using legacy")
markDeprecated(installCmd, "legacy", "KubeArmor now utilizes operator-based installation. This command may not set up KubeArmor in the intended way.")
}
8 changes: 6 additions & 2 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ var uninstallCmd = &cobra.Command{
Short: "Uninstall KubeArmor from a Kubernetes Cluster",
Long: `Uninstall KubeArmor from a Kubernetes Clusters`,
RunE: func(cmd *cobra.Command, args []string) error {
err := install.K8sUninstaller(client, uninstallOptions)
return err
if err := install.K8sUninstaller(client, uninstallOptions); err != nil {
if err := install.K8sLegacyUninstaller(client, uninstallOptions); err != nil {
return err
}
}
rootxrishabh marked this conversation as resolved.
Show resolved Hide resolved
return nil
},
}

Expand Down
Loading
Loading