Skip to content

Commit

Permalink
policy: enable KPR
Browse files Browse the repository at this point in the history
Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Jan 13, 2025
1 parent b2e1146 commit dc9976c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cmd/terway-cli/cni_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@ func allowEBPFNetworkPolicy(require bool) (bool, error) {
func checkKernelVersion(k, major, minor int) bool {
return kernel.CheckKernelVersion(k, major, minor)
}

func enableKPR() bool {

Check failure on line 67 in cmd/terway-cli/cni_linux.go

View workflow job for this annotation

GitHub Actions / lint

func `enableKPR` is unused (unused)
if !utilfeature.DefaultFeatureGate.Enabled(terwayfeature.KubeProxyReplacement) {
return false
}

prev := nodecap.GetNodeCapabilities(nodecap.NodeCapabilityKubeProxyReplacement)
if prev == True {
fmt.Println("kpr enabled")
return true
}

_, err := netlink.LinkByName("cilium_net")
return errors.As(err, &netlink.LinkNotFoundError{})
}
13 changes: 13 additions & 0 deletions cmd/terway-cli/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type PolicyConfig struct {
IPv6 bool
InClusterLoadBalance bool
HasCiliumChainer bool
EnableKPR bool
}

type CNIConfig struct {
Expand Down Expand Up @@ -76,6 +77,7 @@ func getPolicyConfig(capFilePath string) (*PolicyConfig, error) {
cfg.Datapath = store.Get(nodecap.NodeCapabilityDataPath)
cfg.PolicyProvider = store.Get(nodecap.NodeCapabilityNetworkPolicyProvider)
cfg.HasCiliumChainer = store.Get(nodecap.NodeCapabilityHasCiliumChainer) == True
cfg.EnableKPR = store.Get(nodecap.NodeCapabilityKubeProxyReplacement) == True

cfg.HealthCheckPort = os.Getenv("FELIX_HEALTHPORT")
if cfg.HealthCheckPort == "" {
Expand Down Expand Up @@ -209,6 +211,12 @@ func runCilium(cfg *PolicyConfig) error {
"--enable-bandwidth-manager=true",
"--agent-health-port=" + cfg.HealthCheckPort,
}
if cfg.IPv6 {
args = append(args, "--enable-ipv6=true")
} else {
args = append(args, "--enable-ipv6=false")
}

if cfg.EnableNetworkPolicy {
args = append(args, "--enable-policy=default")
} else {
Expand All @@ -221,6 +229,11 @@ func runCilium(cfg *PolicyConfig) error {
args = append(args, "--datapath-mode=ipvlan")
case dataPathV2:
args = append(args, "--datapath-mode=veth")

if cfg.EnableKPR {
args = append(args, "--enable-node-port=true")
}

default:
args = append(args, "--kube-proxy-replacement=disabled")
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ func init() {
const (
// AutoDataPathV2 enable the new datapath feature.
AutoDataPathV2 featuregate.Feature = "AutoDataPathV2"

KubeProxyReplacement featuregate.Feature = "KubeProxyReplacement"
)

var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
AutoDataPathV2: {Default: true, PreRelease: featuregate.Alpha},
AutoDataPathV2: {Default: true, PreRelease: featuregate.Alpha},
KubeProxyReplacement: {Default: true, PreRelease: featuregate.Alpha},
}
1 change: 1 addition & 0 deletions pkg/utils/nodecap/node_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
NodeCapabilityDataPath = "datapath"
NodeCapabilityNetworkPolicyProvider = "network_policy_provider"
NodeCapabilityHasCiliumChainer = "has_cilium_chainer"
NodeCapabilityKubeProxyReplacement = "kube_proxy_replacement"
)

// NodeCapabilitiesStore defines an interface for node capabilities operations
Expand Down

0 comments on commit dc9976c

Please sign in to comment.