Skip to content

Commit

Permalink
helm: improve KPR autodetection logic
Browse files Browse the repository at this point in the history
Make sure that the autodetected values don't override possible user
configurations. Additionally, adapt the kubeProxyReplacement value
based on the CIlium version, as strict got deprevated in v1.14.

Signed-off-by: Marco Iorio <[email protected]>
  • Loading branch information
giorio94 authored and michi-covalent committed Mar 12, 2024
1 parent 9f61556 commit ad3a82c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions install/autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cilium/cilium-cli/k8s"

"github.com/cilium/cilium/pkg/versioncheck"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
Expand Down Expand Up @@ -138,11 +139,11 @@ func (k *K8sInstaller) autodetectAndValidate(ctx context.Context, helmValues map
return err
}

k.autodetectKubeProxy(ctx)
k.autodetectKubeProxy(ctx, helmValues)
return nil
}

func (k *K8sInstaller) autodetectKubeProxy(ctx context.Context) error {
func (k *K8sInstaller) autodetectKubeProxy(ctx context.Context, helmValues map[string]interface{}) error {
if k.flavor.Kind == k8s.KindK3s {
return nil
}
Expand Down Expand Up @@ -197,11 +198,25 @@ func (k *K8sInstaller) autodetectKubeProxy(ctx context.Context) error {
if apiServerHost != "" && apiServerPort != "" {
k.Log("🔮 Auto-detected kube-proxy has not been installed")
k.Log("ℹ️ Cilium will fully replace all functionalities of kube-proxy")

setIfUnset := func(key, value string) {
_, found, _ := unstructured.NestedFieldNoCopy(helmValues, key)
if !found {
k.params.HelmOpts.Values = append(k.params.HelmOpts.Values,
fmt.Sprintf("%s=%s", key, value))
}
}

// Use HelmOpts to set auto kube-proxy installation
k.params.HelmOpts.Values = append(k.params.HelmOpts.Values,
"kubeProxyReplacement=strict",
fmt.Sprintf("k8sServiceHost=%s", apiServerHost),
fmt.Sprintf("k8sServicePort=%s", apiServerPort))
setIfUnset("kubeProxyReplacement", func() string {
if !versioncheck.MustCompile(">=1.14.0")(k.chartVersion) {
return "true"
}
return "strict"
}())

setIfUnset("k8sServiceHost", apiServerHost)
setIfUnset("k8sServicePort", apiServerPort)
}

return nil
Expand Down

0 comments on commit ad3a82c

Please sign in to comment.