Skip to content

Commit a05b1a7

Browse files
committed
Review comments
1 parent ca5e6f9 commit a05b1a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+13741
-59
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ DOCKER_CMD ?= docker
5555
DOCKER_CLI_EXPERIMENTAL ?= enabled
5656
PROXY_SERVER_IP ?= 127.0.0.1
5757

58-
KIND_IMAGE ?= kindest/node
58+
KIND_IMAGE ?= kindest/node:v1.30.2
5959
CONNECTION_MODE ?= grpc
6060
## --------------------------------------
6161
## Testing

cmd/agent/app/server.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"google.golang.org/grpc/keepalive"
4141
"k8s.io/apimachinery/pkg/labels"
4242
"k8s.io/client-go/kubernetes"
43+
coordinationv1lister "k8s.io/client-go/listers/coordination/v1"
4344
"k8s.io/client-go/tools/clientcmd"
4445
"k8s.io/klog/v2"
4546
"k8s.io/utils/clock"
@@ -49,8 +50,9 @@ import (
4950
)
5051

5152
const (
52-
ReadHeaderTimeout = 60 * time.Second
53-
LeaseNamespace = "kube-system"
53+
ReadHeaderTimeout = 60 * time.Second
54+
LeaseNamespace = "kube-system"
55+
LeaseInformerResync = time.Second * 10
5456
)
5557

5658
func NewAgentCommand(a *Agent, o *options.GrpcProxyAgentOptions) *cobra.Command {
@@ -150,10 +152,13 @@ func (a *Agent) runProxyConnection(o *options.GrpcProxyAgentOptions, drainCh, st
150152
if err != nil {
151153
return nil, fmt.Errorf("failed to create kubernetes clientset: %v", err)
152154
}
155+
leaseInformer := agent.NewLeaseInformerWithMetrics(k8sClient, "", LeaseInformerResync)
156+
go leaseInformer.Run(stopCh)
157+
leaseLister := coordinationv1lister.NewLeaseLister(leaseInformer.GetIndexer())
153158
serverLeaseSelector, _ := labels.Parse("k8s-app=konnectivity-server")
154159
serverLeaseCounter := agent.NewServerLeaseCounter(
155160
clock.RealClock{},
156-
k8sClient,
161+
leaseLister,
157162
serverLeaseSelector,
158163
LeaseNamespace,
159164
)

e2e/lease_count_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package e2e
217

318
import (

e2e/main_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package e2e
217

318
import (
@@ -218,13 +233,6 @@ func deleteDeployment(obj client.Object) func(context.Context, *testing.T, *envc
218233
}
219234
}
220235

221-
func sleepFor(duration time.Duration) func(context.Context, *testing.T, *envconf.Config) context.Context {
222-
return func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
223-
time.Sleep(duration)
224-
return ctx
225-
}
226-
}
227-
228236
func waitForDeployment(obj client.Object) func(context.Context, *testing.T, *envconf.Config) context.Context {
229237
return func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
230238
deployment, ok := obj.(*appsv1api.Deployment)
@@ -235,7 +243,7 @@ func waitForDeployment(obj client.Object) func(context.Context, *testing.T, *env
235243
k8sClient := kubernetes.NewForConfigOrDie(cfg.Client().RESTConfig())
236244
err := wait.For(
237245
conditions.New(cfg.Client().Resources(deployment.Namespace)).DeploymentAvailable(deployment.Name, deployment.Namespace),
238-
wait.WithTimeout(60*time.Second),
246+
wait.WithTimeout(120*time.Second),
239247
wait.WithInterval(5*time.Second),
240248
)
241249
if err != nil {

e2e/metrics_assertions_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package e2e
217

318
import (

e2e/static_count_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package e2e
217

318
import (
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
networking:
4+
ipFamily: ipv4
5+
nodes:
6+
- role: control-plane
7+
kubeadmConfigPatchesJSON6902:
8+
- kind: ClusterConfiguration
9+
patch: |
10+
- op: add
11+
path: /apiServer/certSANs/-
12+
value: konnectivity-server.kube-system.svc.cluster.local
13+
kubeadmConfigPatches:
14+
- |
15+
kind: ClusterConfiguration
16+
apiServer:
17+
extraArgs:
18+
"egress-selector-config-file": "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
19+
extraVolumes:
20+
- name: egress-selector-config-file
21+
hostPath: "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
22+
mountPath: "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
23+
readOnly: true
24+
- name: konnectivity-server
25+
hostPath: "/etc/kubernetes/konnectivity-server"
26+
mountPath: "/etc/kubernetes/konnectivity-server"
27+
readOnly: true
28+
extraMounts:
29+
- hostPath: ./egress_selector_configuration.yaml
30+
containerPath: /etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml
31+
- role: control-plane
32+
kubeadmConfigPatchesJSON6902:
33+
- kind: ClusterConfiguration
34+
patch: |
35+
- op: add
36+
path: /apiServer/certSANs/-
37+
value: konnectivity-server.kube-system.svc.cluster.local
38+
kubeadmConfigPatches:
39+
- |
40+
kind: ClusterConfiguration
41+
apiServer:
42+
extraArgs:
43+
"egress-selector-config-file": "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
44+
extraVolumes:
45+
- name: egress-selector-config-file
46+
hostPath: "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
47+
mountPath: "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
48+
readOnly: true
49+
- name: konnectivity-server
50+
hostPath: "/etc/kubernetes/konnectivity-server"
51+
mountPath: "/etc/kubernetes/konnectivity-server"
52+
readOnly: true
53+
extraMounts:
54+
- hostPath: ./egress_selector_configuration.yaml
55+
containerPath: /etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml
56+
- role: control-plane
57+
kubeadmConfigPatchesJSON6902:
58+
- kind: ClusterConfiguration
59+
patch: |
60+
- op: add
61+
path: /apiServer/certSANs/-
62+
value: konnectivity-server.kube-system.svc.cluster.local
63+
kubeadmConfigPatches:
64+
- |
65+
kind: ClusterConfiguration
66+
apiServer:
67+
extraArgs:
68+
"egress-selector-config-file": "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
69+
extraVolumes:
70+
- name: egress-selector-config-file
71+
hostPath: "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
72+
mountPath: "/etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml"
73+
readOnly: true
74+
- name: konnectivity-server
75+
hostPath: "/etc/kubernetes/konnectivity-server"
76+
mountPath: "/etc/kubernetes/konnectivity-server"
77+
readOnly: true
78+
extraMounts:
79+
- hostPath: ./egress_selector_configuration.yaml
80+
containerPath: /etc/kubernetes/konnectivity-server-config/egress_selector_configuration.yaml
81+
- role: worker
82+
- role: worker
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: system:konnectivity-agent
5+
labels:
6+
kubernetes.io/cluster-service: "true"
7+
rules:
8+
- apiGroups: ["coordination.k8s.io"]
9+
resources: ["leases"]
10+
verbs: ["get", "watch", "list"]
11+
---
12+
apiVersion: rbac.authorization.k8s.io/v1
13+
kind: ClusterRoleBinding
14+
metadata:
15+
name: system:konnectivity-agent
16+
labels:
17+
kubernetes.io/cluster-service: "true"
18+
subjects:
19+
- kind: ServiceAccount
20+
name: konnectivity-agent
21+
namespace: kube-system
22+
roleRef:
23+
kind: ClusterRole
24+
name: system:konnectivity-agent
25+
apiGroup: rbac.authorization.k8s.io
26+
---
27+
apiVersion: v1
28+
kind: ServiceAccount
29+
metadata:
30+
name: konnectivity-agent
31+
namespace: kube-system
32+
labels:
33+
kubernetes.io/cluster-service: "true"
34+
---
35+
apiVersion: apps/v1
36+
kind: DaemonSet
37+
metadata:
38+
labels:
39+
k8s-app: konnectivity-agent
40+
namespace: kube-system
41+
name: konnectivity-agent
42+
spec:
43+
selector:
44+
matchLabels:
45+
k8s-app: konnectivity-agent
46+
updateStrategy:
47+
type: RollingUpdate
48+
template:
49+
metadata:
50+
labels:
51+
k8s-app: konnectivity-agent
52+
spec:
53+
priorityClassName: system-cluster-critical
54+
tolerations:
55+
- key: "CriticalAddonsOnly"
56+
operator: "Exists"
57+
- operator: "Exists"
58+
effect: "NoExecute"
59+
nodeSelector:
60+
kubernetes.io/os: linux
61+
dnsPolicy: ClusterFirstWithHostNet
62+
containers:
63+
- name: konnectivity-agent-container
64+
image: gcr.io/carreter-dev2/proxy-agent-amd64:01e3cce3bd4c8e4cff2366d1169c0326a2f1af02
65+
resources:
66+
requests:
67+
cpu: 50m
68+
limits:
69+
memory: 30Mi
70+
command: [ "/proxy-agent"]
71+
args: [
72+
"--logtostderr=true",
73+
"--ca-cert=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
74+
"--proxy-server-host=konnectivity-server.kube-system.svc.cluster.local",
75+
"--proxy-server-port=8091",
76+
"--sync-interval=5s",
77+
"--sync-interval-cap=30s",
78+
"--sync-forever",
79+
"--probe-interval=5s",
80+
"--service-account-token-path=/var/run/secrets/tokens/konnectivity-agent-token",
81+
"--agent-identifiers=ipv4=${HOST_IP}",
82+
"--count-server-leases",
83+
]
84+
env:
85+
- name: POD_NAME
86+
valueFrom:
87+
fieldRef:
88+
fieldPath: metadata.name
89+
- name: POD_NAMESPACE
90+
valueFrom:
91+
fieldRef:
92+
fieldPath: metadata.namespace
93+
- name: HOST_IP
94+
valueFrom:
95+
fieldRef:
96+
fieldPath: status.hostIP
97+
livenessProbe:
98+
httpGet:
99+
scheme: HTTP
100+
port: 8093
101+
path: /healthz
102+
initialDelaySeconds: 15
103+
timeoutSeconds: 15
104+
readinessProbe:
105+
httpGet:
106+
scheme: HTTP
107+
port: 8093
108+
path: /readyz
109+
initialDelaySeconds: 15
110+
timeoutSeconds: 15
111+
volumeMounts:
112+
- mountPath: /var/run/secrets/tokens
113+
name: konnectivity-agent-token
114+
serviceAccountName: konnectivity-agent
115+
volumes:
116+
- name: konnectivity-agent-token
117+
projected:
118+
sources:
119+
- serviceAccountToken:
120+
path: konnectivity-agent-token
121+
audience: system:konnectivity-server

0 commit comments

Comments
 (0)