Skip to content

Commit 21e47a8

Browse files
committed
save temp
Signed-off-by: clyi <[email protected]>
1 parent 2ade8ff commit 21e47a8

File tree

16 files changed

+472
-29
lines changed

16 files changed

+472
-29
lines changed

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ build-go-arm:
134134
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GO_BUILD_FLAGS) -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-controller -v ./cmd/controller
135135

136136
.PHONY: build-kube-ovn
137-
build-kube-ovn: build-debug build-go
137+
build-kube-ovn: build-go
138138
docker build -t $(REGISTRY)/kube-ovn:$(RELEASE_TAG) --build-arg VERSION=$(RELEASE_TAG) -f dist/images/Dockerfile dist/images/
139-
docker build -t $(REGISTRY)/kube-ovn:$(LEGACY_TAG) --build-arg VERSION=$(LEGACY_TAG) -f dist/images/Dockerfile dist/images/
140139

141140
.PHONY: build-kube-ovn-dpdk
142141
build-kube-ovn-dpdk: build-go

dist/images/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# syntax = docker/dockerfile:experimental
22
ARG VERSION
33
ARG BASE_TAG=$VERSION
4-
FROM kubeovn/kube-ovn-base:$BASE_TAG AS setcap
4+
FROM yichanglu/kube-ovn-base:$BASE_TAG AS setcap
55

66
COPY *.sh /kube-ovn/
77
COPY kubectl-ko /kube-ovn/kubectl-ko
@@ -22,7 +22,7 @@ RUN ln -s /kube-ovn/kube-ovn-cmd /kube-ovn/kube-ovn-monitor && \
2222
setcap CAP_NET_RAW,CAP_NET_BIND_SERVICE+eip /kube-ovn/kube-ovn-controller && \
2323
setcap CAP_NET_ADMIN,CAP_NET_RAW,CAP_NET_BIND_SERVICE,CAP_SYS_ADMIN+eip /kube-ovn/kube-ovn-daemon
2424

25-
FROM kubeovn/kube-ovn-base:$BASE_TAG
25+
FROM yichanglu/kube-ovn-base:$BASE_TAG
2626

2727
COPY --chmod=0644 logrotate/* /etc/logrotate.d/
2828
COPY grace_stop_ovn_controller /usr/share/ovn/scripts/grace_stop_ovn_controller

dist/images/install.sh

+13-8
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ OVSDB_INACTIVITY_TIMEOUT=${OVSDB_INACTIVITY_TIMEOUT:-10}
4848
ENABLE_LIVE_MIGRATION_OPTIMIZE=${ENABLE_LIVE_MIGRATION_OPTIMIZE:-true}
4949

5050
# debug
51-
DEBUG_WRAPPER=${DEBUG_WRAPPER:-}
51+
DEBUG_WRAPPER=${DEBUG_WRAPPER:-true}
5252
RUN_AS_USER=65534 # run as nobody
5353
if [ "$ENABLE_OVN_IPSEC" = "true" -o -n "$DEBUG_WRAPPER" ]; then
5454
RUN_AS_USER=0
5555
fi
5656

57+
RUN_AS_USER=0
58+
5759
KUBELET_DIR=${KUBELET_DIR:-/var/lib/kubelet}
5860
LOG_DIR=${LOG_DIR:-/var/log}
5961

@@ -2810,6 +2812,8 @@ spec:
28102812
type: boolean
28112813
enableMulticastSnoop:
28122814
type: boolean
2815+
isExternalLBAddressPool:
2816+
type: boolean
28132817
routeTable:
28142818
type: string
28152819
namespaceSelectors:
@@ -3666,6 +3670,7 @@ rules:
36663670
- ovn-eips/status
36673671
- nodes
36683672
- pods
3673+
- vips
36693674
verbs:
36703675
- get
36713676
- list
@@ -3957,7 +3962,7 @@ spec:
39573962
- /kube-ovn/start-db.sh
39583963
securityContext:
39593964
runAsUser: ${RUN_AS_USER}
3960-
privileged: false
3965+
privileged: true
39613966
capabilities:
39623967
add:
39633968
- NET_BIND_SERVICE
@@ -4303,7 +4308,7 @@ spec:
43034308
- /kube-ovn/start-ovs.sh
43044309
securityContext:
43054310
runAsUser: ${RUN_AS_USER}
4306-
privileged: false
4311+
privileged: true
43074312
capabilities:
43084313
add:
43094314
- NET_ADMIN
@@ -4731,7 +4736,7 @@ spec:
47314736
- --image=$REGISTRY/kube-ovn:$VERSION
47324737
securityContext:
47334738
runAsUser: ${RUN_AS_USER}
4734-
privileged: false
4739+
privileged: true
47354740
capabilities:
47364741
add:
47374742
- NET_BIND_SERVICE
@@ -4924,7 +4929,7 @@ spec:
49244929
- --set-vxlan-tx-off=$SET_VXLAN_TX_OFF
49254930
securityContext:
49264931
runAsUser: 0
4927-
privileged: false
4932+
privileged: true
49284933
capabilities:
49294934
add:
49304935
- NET_ADMIN
@@ -5139,7 +5144,7 @@ spec:
51395144
imagePullPolicy: $IMAGE_PULL_POLICY
51405145
securityContext:
51415146
runAsUser: ${RUN_AS_USER}
5142-
privileged: false
5147+
privileged: true
51435148
capabilities:
51445149
add:
51455150
- NET_BIND_SERVICE
@@ -5290,7 +5295,7 @@ spec:
52905295
- --enable-metrics=$ENABLE_METRICS
52915296
securityContext:
52925297
runAsUser: ${RUN_AS_USER}
5293-
privileged: false
5298+
privileged: true
52945299
capabilities:
52955300
add:
52965301
- NET_BIND_SERVICE
@@ -5513,7 +5518,7 @@ spec:
55135518
- --alsologtostderr=true
55145519
securityContext:
55155520
runAsUser: ${RUN_AS_USER}
5516-
privileged: false
5521+
privileged: true
55175522
capabilities:
55185523
add:
55195524
- NET_BIND_SERVICE

mocks/pkg/ovs/interface.go

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kubeovn/v1/subnet.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ type SubnetSpec struct {
8080

8181
NatOutgoingPolicyRules []NatOutgoingPolicyRule `json:"natOutgoingPolicyRules,omitempty"`
8282

83-
U2OInterconnectionIP string `json:"u2oInterconnectionIP,omitempty"`
84-
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
85-
EnableLb *bool `json:"enableLb,omitempty"`
86-
EnableEcmp bool `json:"enableEcmp,omitempty"`
87-
EnableMulticastSnoop bool `json:"enableMulticastSnoop,omitempty"`
83+
U2OInterconnectionIP string `json:"u2oInterconnectionIP,omitempty"`
84+
U2OInterconnection bool `json:"u2oInterconnection,omitempty"`
85+
EnableLb *bool `json:"enableLb,omitempty"`
86+
EnableEcmp bool `json:"enableEcmp,omitempty"`
87+
EnableMulticastSnoop bool `json:"enableMulticastSnoop,omitempty"`
88+
IsExternalLBAddressPool bool `json:"isExternalLBAddressPool,omitempty"`
8889

8990
RouteTable string `json:"routeTable,omitempty"`
9091
NamespaceSelectors []metav1.LabelSelector `json:"namespaceSelectors,omitempty"`

pkg/controller/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Configuration struct {
9393
EnableEcmp bool
9494
EnableKeepVMIP bool
9595
EnableLbSvc bool
96+
EnableLbSvcPolicyLocal bool
9697
EnableMetrics bool
9798
EnableANP bool
9899
EnableOVNIPSec bool
@@ -175,6 +176,7 @@ func ParseFlags() (*Configuration, error) {
175176
argEnableEcmp = pflag.Bool("enable-ecmp", false, "Enable ecmp route for centralized subnet")
176177
argKeepVMIP = pflag.Bool("keep-vm-ip", true, "Whether to keep ip for kubevirt pod when pod is rebuild")
177178
argEnableLbSvc = pflag.Bool("enable-lb-svc", false, "Whether to support loadbalancer service")
179+
argEnableLbSvcPolicyLocal = pflag.Bool("enable-lb-svc-policy-local", true, "Whether to support external loadbalancer")
178180
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")
179181
argEnableANP = pflag.Bool("enable-anp", false, "Enable support for admin network policy and baseline admin network policy")
180182
argEnableOVNIPSec = pflag.Bool("enable-ovn-ipsec", false, "Whether to enable ovn ipsec")
@@ -271,6 +273,7 @@ func ParseFlags() (*Configuration, error) {
271273
GCInterval: *argGCInterval,
272274
InspectInterval: *argInspectInterval,
273275
EnableLbSvc: *argEnableLbSvc,
276+
EnableLbSvcPolicyLocal: *argEnableLbSvcPolicyLocal,
274277
EnableMetrics: *argEnableMetrics,
275278
EnableOVNIPSec: *argEnableOVNIPSec,
276279
EnableLiveMigrationOptimize: *argEnableLiveMigrationOptimize,

pkg/controller/endpoint.go

+51-7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
7575
vip, vpcName, subnetName string
7676
ok bool
7777
ignoreHealthCheck = true
78+
isPreferLocalBackend = false
7879
)
7980

8081
if vip, ok = svc.Annotations[util.SwitchLBRuleVipsAnnotation]; ok {
@@ -93,6 +94,20 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
9394
return nil
9495
}
9596

97+
// 注意这些东西只有在ovn lb开关打开的时候才能用
98+
if svc.Spec.Type == v1.ServiceTypeLoadBalancer && svc.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeLocal {
99+
if externalIP := util.GetLoadBalancerIP(*svc); err == nil && externalIP != "" {
100+
lbVips = append(lbVips, externalIP)
101+
} else if err != nil {
102+
klog.Errorf("failed to get external load balancer IP for service %s/%s: %v", namespace, name, err)
103+
return err
104+
}
105+
isPreferLocalBackend = true
106+
} else if svc.Spec.Type == v1.ServiceTypeClusterIP && svc.Spec.InternalTrafficPolicy != nil && *svc.Spec.InternalTrafficPolicy == v1.ServiceInternalTrafficPolicyLocal {
107+
isPreferLocalBackend = true
108+
}
109+
110+
klog.Errorf("clyi lbVips %v", lbVips)
96111
if pods, err = c.podsLister.Pods(namespace).List(labels.Set(svc.Spec.Selector).AsSelector()); err != nil {
97112
klog.Errorf("failed to get pods for service %s in namespace %s: %v", name, namespace, err)
98113
return err
@@ -157,19 +172,40 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
157172
backends []string
158173
ipPortMapping, externals map[string]string
159174
)
160-
161-
if !ignoreHealthCheck {
175+
isGenIPPortMapping := !ignoreHealthCheck || isPreferLocalBackend
176+
if isGenIPPortMapping {
162177
if checkIP, err = c.getHealthCheckVip(subnetName, lbVip); err != nil {
163178
klog.Error(err)
164179
return err
165180
}
181+
182+
// subnet, err := c.subnetsLister.Get(subnetName)
183+
// if err != nil {
184+
// klog.Errorf("failed to get subnet %s: %v", subnetName, err)
185+
// return err
186+
// }
187+
188+
// if subnet.Spec.IsExternalLBAddressPool {
189+
// vipName := fmt.Sprintf("%s.%s", svc.Name, svc.Namespace)
190+
// vip := &kubeovnv1.Vip{
191+
// ObjectMeta: metav1.ObjectMeta{
192+
// Name: vipName,
193+
// },
194+
// Spec: kubeovnv1.VipSpec{
195+
// Subnet: subnetName,
196+
// },
197+
// }
198+
// if _, err = c.config.KubeOvnClient.KubeovnV1().Vips().Create(context.Background(), vip, metav1.CreateOptions{}); err != nil {
199+
// klog.Errorf("failed to create vip %s, %v", vipName, err)
200+
// return err
201+
// }
202+
// }
203+
166204
externals = map[string]string{
167205
util.SwitchLBRuleSubnet: subnetName,
168206
}
169207
}
170-
171-
ipPortMapping, backends = getIPPortMappingBackend(ep, pods, port, lbVip, checkIP, ignoreHealthCheck)
172-
208+
ipPortMapping, backends = getIPPortMappingBackend(ep, pods, port, lbVip, checkIP, isGenIPPortMapping)
173209
// for performance reason delete lb with no backends
174210
if len(backends) != 0 {
175211
vip = util.JoinHostPort(lbVip, port.Port)
@@ -178,6 +214,14 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
178214
klog.Errorf("failed to add vip %s with backends %s to LB %s: %v", lbVip, backends, lb, err)
179215
return err
180216
}
217+
218+
if isPreferLocalBackend {
219+
if err = c.OVNNbClient.LoadBalancerUpdateIPPortMapping(lb, vip, ipPortMapping); err != nil {
220+
klog.Errorf("failed to update ip port mapping %s for vip %s to LB %s: %v", ipPortMapping, vip, lb, err)
221+
return err
222+
}
223+
}
224+
181225
if !ignoreHealthCheck && len(ipPortMapping) != 0 {
182226
klog.Infof("add health check ip port mapping %v to LB %s", ipPortMapping, lb)
183227
if err = c.OVNNbClient.LoadBalancerAddHealthCheck(lb, vip, ignoreHealthCheck, ipPortMapping, externals); err != nil {
@@ -321,7 +365,7 @@ func (c *Controller) getHealthCheckVip(subnetName, lbVip string) (string, error)
321365
return checkIP, nil
322366
}
323367

324-
func getIPPortMappingBackend(endpoints *v1.Endpoints, pods []*v1.Pod, servicePort v1.ServicePort, serviceIP, checkVip string, ignoreHealthCheck bool) (map[string]string, []string) {
368+
func getIPPortMappingBackend(endpoints *v1.Endpoints, pods []*v1.Pod, servicePort v1.ServicePort, serviceIP, checkVip string, isGenIPPortMapping bool) (map[string]string, []string) {
325369
var (
326370
ipPortMapping = map[string]string{}
327371
backends = []string{}
@@ -341,7 +385,7 @@ func getIPPortMappingBackend(endpoints *v1.Endpoints, pods []*v1.Pod, servicePor
341385
}
342386

343387
for _, address := range subset.Addresses {
344-
if !ignoreHealthCheck && address.TargetRef.Name != "" {
388+
if isGenIPPortMapping && address.TargetRef.Name != "" {
345389
ipName := fmt.Sprintf("%s.%s", address.TargetRef.Name, endpoints.Namespace)
346390
ipPortMapping[address.IP] = fmt.Sprintf(util.HealthCheckNamedVipTemplate, ipName, checkVip)
347391
}

pkg/controller/init.go

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ func (c *Controller) initLB(name, protocol string, sessionAffinity bool) error {
251251
}
252252
}
253253

254+
err = c.OVNNbClient.SetLoadBalancerPreferLocalBackend(name, c.config.EnableLbSvcPolicyLocal)
255+
if err != nil {
256+
klog.Errorf("failed to set prefer local backend for load balancer %s: %v", name, err)
257+
return err
258+
}
259+
254260
return nil
255261
}
256262

pkg/controller/subnet.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
681681

682682
needRouter := subnet.Spec.Vlan == "" || subnet.Spec.LogicalGateway ||
683683
(subnet.Status.U2OInterconnectionIP != "" && subnet.Spec.U2OInterconnection)
684+
685+
if subnet.Spec.Vlan != "" && subnet.Spec.IsExternalLBAddressPool {
686+
needRouter = true
687+
}
688+
684689
// 1. overlay subnet, should add lrp, lrp ip is subnet gw
685690
// 2. underlay subnet use logical gw, should add lrp, lrp ip is subnet gw
686691
randomAllocateGW := !subnet.Spec.LogicalGateway && vpc.Spec.EnableExternal && subnet.Name == c.config.ExternalGatewaySwitch
@@ -1852,8 +1857,12 @@ func (c *Controller) reconcileSubnetSpecialIPs(subnet *kubeovnv1.Subnet) (bool,
18521857
if subnet.Spec.Vlan != "" && !subnet.Spec.LogicalGateway {
18531858
u2oInterconnName := fmt.Sprintf(util.U2OInterconnName, subnet.Spec.Vpc, subnet.Name)
18541859
u2oInterconnLrpName := fmt.Sprintf("%s-%s", subnet.Spec.Vpc, subnet.Name)
1860+
1861+
klog.Errorf("changlu subnet.Spec.IsExternalLBAddressPool %v ", subnet.Spec.IsExternalLBAddressPool)
1862+
needAllocateU2OIP := false
1863+
needAllocateU2OIP = subnet.Spec.U2OInterconnection || subnet.Spec.IsExternalLBAddressPool
18551864
var v4ip, v6ip string
1856-
if subnet.Spec.U2OInterconnection {
1865+
if needAllocateU2OIP {
18571866
v4ip, v6ip, _, err = c.acquireU2OIP(subnet, u2oInterconnName, u2oInterconnLrpName)
18581867
if err != nil {
18591868
return isU2OIPChanged, isMcastQuerierIPChanged, err
@@ -1862,7 +1871,7 @@ func (c *Controller) reconcileSubnetSpecialIPs(subnet *kubeovnv1.Subnet) (bool,
18621871
if v4ip != "" || v6ip != "" {
18631872
isU2OIPChanged = true
18641873
}
1865-
} else if subnet.Status.U2OInterconnectionIP != "" {
1874+
} else if !needAllocateU2OIP && subnet.Status.U2OInterconnectionIP != "" {
18661875
err = c.releaseU2OIP(subnet, u2oInterconnName)
18671876
if err != nil {
18681877
return isU2OIPChanged, isMcastQuerierIPChanged, err

0 commit comments

Comments
 (0)