Skip to content

Commit

Permalink
Added operator configuration
Browse files Browse the repository at this point in the history
Signed-off-by: rootxrishabh <[email protected]>
  • Loading branch information
rootxrishabh committed Feb 16, 2024
1 parent b87ddbe commit e591363
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func init() {
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", "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.Tag, "tag", "t", "", "Change image tag/version for default kubearmor images (This will overwrite the tags provided in --image/--init-image)")
Expand Down
30 changes: 28 additions & 2 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Options struct {
InitImage string
KubearmorImage string
ControllerImage string
OperatorImage string
RelayImage string
ImageRegistry string
Tag string
Expand Down Expand Up @@ -877,12 +878,37 @@ func writeHelmManifests(manifests string, filename string, printYAML []interface
return nil
}

func getOperatorConfig(o Options) map[string]interface{} {
var operatorImagePullPolicy string = "Always"
var opeartorImageTag string = "latest"

if o.Local {
operatorImagePullPolicy = "IfNotPresent"
}
if o.Tag != "" {
opeartorImageTag = o.Tag
}
if o.ImageRegistry != "" {
o.OperatorImage = o.ImageRegistry + "/" + o.OperatorImage
}
return map[string]interface{}{
"kubearmorOperator": map[string]interface{}{
"image": map[string]interface{}{
"repository": o.OperatorImage,
"tag": opeartorImageTag,
},
"imagePullPolicy": operatorImagePullPolicy,
},
}
}

// K8sInstaller using operator for karmor
func K8sInstaller(c *k8s.Client, o Options) error {
var printYAML []interface{}
ns := o.Namespace
releaseName := "kubearmor-operator"
kubearmorConfig := getOperatorCR(o)
values := getOperatorConfig(o)
settings := cli.New()
settings.SetNamespace(ns)

Expand Down Expand Up @@ -928,7 +954,7 @@ func K8sInstaller(c *k8s.Client, o Options) error {
return fmt.Errorf("failed to load Helm chart: %w", err)
}
log.SetOutput(io.Discard)
upgradeInstaller, err := client.Run(releaseName, chartRequested, nil)
upgradeInstaller, err := client.Run(releaseName, chartRequested, values)
log.SetOutput(os.Stdout)
if err != nil {
client.Install = true
Expand All @@ -955,7 +981,7 @@ func K8sInstaller(c *k8s.Client, o Options) error {
}

log.SetOutput(io.Discard)
installRunner, err := clientInstall.Run(chartRequested, nil)
installRunner, err := clientInstall.Run(chartRequested, values)
log.SetOutput(os.Stdout)
if o.Save {
return writeHelmManifests(installRunner.Manifest, "kubearmor.yaml", printYAML, kubearmorConfig)
Expand Down

0 comments on commit e591363

Please sign in to comment.