Skip to content

Commit

Permalink
Improvements for kube-proxy detection and replacement
Browse files Browse the repository at this point in the history
The current implementation tries to replace  the kube-proxy for k3s and doesn't honor the value set for kube-proxy replacement by users. This PR fixes those issues.

Fixes: #1004
Signed-off-by: shankeerthan-kasilingam <[email protected]>
  • Loading branch information
ksankeerth committed Nov 9, 2022
1 parent 5ccea19 commit 57d80c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion install/autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,17 @@ func (k *K8sInstaller) autodetectAndValidate(ctx context.Context) error {
}

func (k *K8sInstaller) autodetectKubeProxy(ctx context.Context) error {
if k.params.UserSetKubeProxyReplacement {
return nil
} else if k.flavor.Kind == k8s.KindK3s {
return nil
}

kubeSysNameSpace := "kube-system"

dsList, err := k.client.ListDaemonSet(ctx, kubeSysNameSpace, metav1.ListOptions{})
if err != nil {
k.Log("⏭️ Skipping auto kube-proxy detction")
k.Log("⏭️ Skipping auto kube-proxy detection")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion install/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (k *K8sInstaller) generateManifests(ctx context.Context) error {

// TODO: remove when removing "kube-proxy-replacement" flag (marked as
// deprecated), kept for backwards compatibility
if k.params.KubeProxyReplacement != "" {
if k.params.KubeProxyReplacement != "" && k.params.UserSetKubeProxyReplacement {
helmMapOpts["kubeProxyReplacement"] = k.params.KubeProxyReplacement
}

Expand Down
2 changes: 2 additions & 0 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ type Parameters struct {
// APIVersions defines extra kubernetes api resources that can be passed to helm for capabilities validation,
// specifically for CRDs.
APIVersions []string
// UserSetKubeProxyReplacement will be set as true if user passes helm opt or commadline flag for the Kube-Proxy replacement.
UserSetKubeProxyReplacement bool
}

type rollbackStep func(context.Context)
Expand Down
10 changes: 10 additions & 0 deletions internal/cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/hubble"
Expand All @@ -35,6 +37,14 @@ cilium install --context kind-cluster1 --cluster-id 1 --cluster-name cluster1
RunE: func(cmd *cobra.Command, args []string) error {
params.Namespace = namespace

cmd.Flags().Visit(func(f *pflag.Flag) {
if f.Name == "kube-proxy-replacement" {
params.UserSetKubeProxyReplacement = true
} else if f.Name == "helm-set" && strings.Contains(f.Value.String(), "kubeProxyReplacement") {
params.UserSetKubeProxyReplacement = true
}
})

installer, err := install.NewK8sInstaller(k8sClient, params)
if err != nil {
return err
Expand Down

0 comments on commit 57d80c8

Please sign in to comment.