Skip to content

Commit 80a6035

Browse files
feat: add verbosity control for kube-network-policies
Add `kubeNetworkPoliciesVerbose` to the KubeFlannelCNIConfig document, controlling the `--v` flag passed to the kube-network-policies sidecar container Flannel deploys when `kubeNetworkPoliciesEnabled` is set. When true (the default, preserving prior behavior), the container runs with `--v=2`; when explicitly set to false, it runs with `--v=0`. The field is a pointer so "unset" can be distinguished from "explicitly false" and still resolve to the previous always-verbose behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0163WRSUYoVAHZRGXzrgx23S Signed-off-by: Oliver Gregorius <oliver@gregorius.dev>
1 parent a42ea1d commit 80a6035

18 files changed

Lines changed: 274 additions & 3 deletions

File tree

api/resource/definitions/k8s/k8s.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ message BootstrapManifestsConfigSpec {
9696
google.protobuf.Struct proxy_config = 27;
9797
Resources proxy_resources = 28;
9898
string proxy_config_checksum = 29;
99+
bool flannel_kube_network_policies_verbose = 30;
99100
}
100101

101102
// ConfigStatusSpec describes status of rendered secrets.

internal/app/machined/pkg/controllers/k8s/control_plane.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ func NewControlPlaneBootstrapManifestsController() *ControlPlaneBootstrapManifes
475475
res.TypedSpec().FlannelKubeServiceHost = flannelKubeServiceHost
476476
res.TypedSpec().FlannelKubeServicePort = flannelKubeServicePort
477477
res.TypedSpec().FlannelKubeNetworkPoliciesEnabled = k8sFlannelCNIConfig.KubeNetworkPoliciesEnabled()
478+
res.TypedSpec().FlannelKubeNetworkPoliciesVerbose = k8sFlannelCNIConfig.KubeNetworkPoliciesVerbose()
478479
res.TypedSpec().FlannelKubeNetworkPoliciesImage = images.KubeNetworkPolicies().String()
479480
res.TypedSpec().CNIName = constants.FlannelCNI
480481
} else {
@@ -489,6 +490,7 @@ func NewControlPlaneBootstrapManifestsController() *ControlPlaneBootstrapManifes
489490
res.TypedSpec().FlannelKubeServiceHost = ""
490491
res.TypedSpec().FlannelKubeServicePort = ""
491492
res.TypedSpec().FlannelKubeNetworkPoliciesEnabled = false
493+
res.TypedSpec().FlannelKubeNetworkPoliciesVerbose = true
492494
res.TypedSpec().FlannelKubeNetworkPoliciesImage = ""
493495
res.TypedSpec().CNIName = constants.NoneCNI
494496
}

internal/app/machined/pkg/controllers/k8s/internal/k8stemplates/flannel.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,18 @@ func FlannelDaemonSetTemplate(spec *k8s.BootstrapManifestsConfigSpec) (runtime.O
311311
}
312312

313313
if spec.FlannelKubeNetworkPoliciesEnabled {
314+
verbosity := "--v=0"
315+
if spec.FlannelKubeNetworkPoliciesVerbose {
316+
verbosity = "--v=2"
317+
}
318+
314319
containers = append(containers, corev1.Container{
315320
Name: "kube-network-policies",
316321
Image: spec.FlannelKubeNetworkPoliciesImage,
317322
Command: []string{
318323
"/bin/netpol",
319324
"--hostname-override=$(MY_NODE_NAME)",
320-
"--v=2",
325+
verbosity,
321326
},
322327
Env: []corev1.EnvVar{
323328
{

internal/app/machined/pkg/controllers/k8s/internal/k8stemplates/k8stemplates_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,32 @@ func TestTemplates(t *testing.T) {
542542
},
543543
FlannelKubeNetworkPoliciesEnabled: true,
544544
FlannelKubeNetworkPoliciesImage: "registry.k8s.io/networking/kube-network-policies:v0.7.0",
545+
FlannelKubeNetworkPoliciesVerbose: true,
546+
})
547+
require.NoError(t, err)
548+
549+
return spec
550+
},
551+
},
552+
{
553+
name: "flannel-daemonset-with-network-policies-non-verbose",
554+
obj: func() runtime.Object {
555+
spec, err := k8stemplates.FlannelDaemonSetTemplate(&k8s.BootstrapManifestsConfigSpec{
556+
FlannelImage: "quay.io/coreos/flannel:v0.14.0",
557+
FlannelExtraArgs: []string{"--foo=bar"},
558+
FlannelResources: k8s.Resources{
559+
Requests: map[string]string{
560+
"cpu": "100m",
561+
"memory": "50Mi",
562+
},
563+
Limits: map[string]string{
564+
"cpu": "200m",
565+
"memory": "100Mi",
566+
},
567+
},
568+
FlannelKubeNetworkPoliciesEnabled: true,
569+
FlannelKubeNetworkPoliciesImage: "registry.k8s.io/networking/kube-network-policies:v0.7.0",
570+
FlannelKubeNetworkPoliciesVerbose: false,
545571
})
546572
require.NoError(t, err)
547573

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
labels:
5+
k8s-app: flannel
6+
tier: node
7+
name: kube-flannel
8+
namespace: kube-system
9+
spec:
10+
selector:
11+
matchLabels:
12+
k8s-app: flannel
13+
tier: node
14+
template:
15+
metadata:
16+
labels:
17+
k8s-app: flannel
18+
tier: node
19+
spec:
20+
affinity:
21+
nodeAffinity:
22+
requiredDuringSchedulingIgnoredDuringExecution:
23+
nodeSelectorTerms:
24+
- matchExpressions:
25+
- key: kubernetes.io/os
26+
operator: In
27+
values:
28+
- linux
29+
containers:
30+
- args:
31+
- --ip-masq
32+
- --kube-subnet-mgr
33+
- --foo=bar
34+
command:
35+
- /opt/bin/flanneld
36+
env:
37+
- name: POD_NAME
38+
valueFrom:
39+
fieldRef:
40+
fieldPath: metadata.name
41+
- name: POD_NAMESPACE
42+
valueFrom:
43+
fieldRef:
44+
fieldPath: metadata.namespace
45+
- name: EVENT_QUEUE_DEPTH
46+
value: "5000"
47+
- name: CONT_WHEN_CACHE_NOT_READY
48+
value: "false"
49+
- name: GOMEMLIMIT
50+
value: "99614720"
51+
image: quay.io/coreos/flannel:v0.14.0
52+
name: kube-flannel
53+
resources:
54+
limits:
55+
cpu: 200m
56+
memory: 100Mi
57+
requests:
58+
cpu: 100m
59+
memory: 50Mi
60+
securityContext:
61+
capabilities:
62+
add:
63+
- NET_ADMIN
64+
- NET_RAW
65+
privileged: false
66+
volumeMounts:
67+
- mountPath: /run/flannel
68+
name: run
69+
- mountPath: /etc/kube-flannel/
70+
name: flannel-cfg
71+
- command:
72+
- /bin/netpol
73+
- --hostname-override=$(MY_NODE_NAME)
74+
- --v=0
75+
env:
76+
- name: MY_NODE_NAME
77+
valueFrom:
78+
fieldRef:
79+
fieldPath: spec.nodeName
80+
image: registry.k8s.io/networking/kube-network-policies:v0.7.0
81+
name: kube-network-policies
82+
resources:
83+
requests:
84+
cpu: 100m
85+
memory: 50Mi
86+
securityContext:
87+
capabilities:
88+
add:
89+
- NET_ADMIN
90+
privileged: true
91+
volumeMounts:
92+
- mountPath: /lib/modules
93+
name: lib-modules
94+
readOnly: true
95+
hostNetwork: true
96+
initContainers:
97+
- args:
98+
- -f
99+
- /etc/kube-flannel/cni-conf.json
100+
- /etc/cni/net.d/10-flannel.conflist
101+
command:
102+
- cp
103+
image: quay.io/coreos/flannel:v0.14.0
104+
name: install-config
105+
resources: {}
106+
volumeMounts:
107+
- mountPath: /etc/cni/net.d
108+
name: cni
109+
- mountPath: /etc/kube-flannel/
110+
name: flannel-cfg
111+
priorityClassName: system-node-critical
112+
serviceAccountName: flannel
113+
tolerations:
114+
- effect: NoSchedule
115+
operator: Exists
116+
- effect: NoExecute
117+
operator: Exists
118+
volumes:
119+
- hostPath:
120+
path: /run/flannel
121+
name: run
122+
- hostPath:
123+
path: /etc/cni/net.d
124+
name: cni
125+
- configMap:
126+
name: kube-flannel-cfg
127+
name: flannel-cfg
128+
- hostPath:
129+
path: /usr/lib/modules
130+
name: lib-modules
131+
updateStrategy: {}
132+
status:
133+
currentNumberScheduled: 0
134+
desiredNumberScheduled: 0
135+
numberMisscheduled: 0
136+
numberReady: 0

pkg/machinery/api/resource/definitions/k8s/k8s.pb.go

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/api/resource/definitions/k8s/k8s_vtproto.pb.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/config/config/k8s.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type K8sFlannelCNIConfig interface {
115115
Resources() Resources
116116
ExtraArgs() []string
117117
KubeNetworkPoliciesEnabled() bool
118+
KubeNetworkPoliciesVerbose() bool
118119
}
119120

120121
// K8sAdmissionControlPluginConfig defines the configuration options for kube-apiserver admission control plugins.

pkg/machinery/config/schemas/config.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,13 @@
27852785
"description": "Deploys kube-network-policies along with Flannel.\n\nThis enables Kubernetes Network Policies support in the cluster.\n",
27862786
"markdownDescription": "Deploys kube-network-policies along with Flannel.\n\nThis enables Kubernetes Network Policies support in the cluster.",
27872787
"x-intellij-html-description": "\u003cp\u003eDeploys kube-network-policies along with Flannel.\u003c/p\u003e\n\n\u003cp\u003eThis enables Kubernetes Network Policies support in the cluster.\u003c/p\u003e\n"
2788+
},
2789+
"kubeNetworkPoliciesVerbose": {
2790+
"type": "boolean",
2791+
"title": "kubeNetworkPoliciesVerbose",
2792+
"description": "Enables verbose logging for kube-network-policies.\n\nThis enables verbose logging for the kube-network-policies container.\n",
2793+
"markdownDescription": "Enables verbose logging for kube-network-policies.\n\nThis enables verbose logging for the kube-network-policies container.",
2794+
"x-intellij-html-description": "\u003cp\u003eEnables verbose logging for kube-network-policies.\u003c/p\u003e\n\n\u003cp\u003eThis enables verbose logging for the kube-network-policies container.\u003c/p\u003e\n"
27882795
}
27892796
},
27902797
"additionalProperties": false,

pkg/machinery/config/types/k8s/deep_copy.generated.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)