Skip to content

Commit

Permalink
feat: use label to select leader to avoid pod status misleading
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Dec 3, 2019
1 parent fc77355 commit 06eceb3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions dist/images/Dockerfile.db
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ RUN rpm -ivh https://github.com/alauda/ovs/releases/download/${OVS_VERSION}-${OV

RUN mkdir -p /var/run/openvswitch

ENV KUBE_VERSION="v1.13.2"
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64/kubectl -o /usr/bin/kubectl \
&& chmod +x /usr/bin/kubectl

COPY ovn-healthcheck.sh /root/ovn-healthcheck.sh
COPY ovn-is-leader.sh /root/ovn-is-leader.sh

Expand Down
8 changes: 7 additions & 1 deletion dist/images/ovn-is-leader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ ovn-ctl status_ovnnb
ovn-ctl status_ovnsb

# For data consistency, only store leader address in endpoint
ovsdb-client query tcp:127.0.0.1:6641 "[\"_Server\",{\"table\":\"Database\",\"where\":[[\"name\",\"==\", \"OVN_Northbound\"]],\"columns\": [\"leader\"],\"op\":\"select\"}]" | grep true
leader=$(ovsdb-client query tcp:127.0.0.1:6641 "[\"_Server\",{\"table\":\"Database\",\"where\":[[\"name\",\"==\", \"OVN_Northbound\"]],\"columns\": [\"leader\"],\"op\":\"select\"}]")
if [[ $leader =~ "true" ]]
then
kubectl label --overwrite pod $POD_NAME -n $POD_NAMESPACE ovn-db-leader=true
else
kubectl label pod $POD_NAME -n $POD_NAMESPACE ovn-db-leader-
fi
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ You can use `--default-cidr` flags below to config default Pod CIDR or create a
```bash
--iface: The iface used to inter-host pod communication, default: the default route iface
--mtu: The MTU used by pod iface, default: iface MTU - 58
--mtu: The MTU used by pod iface, default: iface MTU - 100
--enable-mirror: Enable traffic mirror, default: false
--mirror-iface: The mirror nic name that will be created by kube-ovn, default: mirror0
--service-cluster-ip-range: The kubernetes service cluster ip range, default: 10.96.0.0/12
Expand Down
1 change: 1 addition & 0 deletions yamls/kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ networking:
nodes:
- role: control-plane
- role: worker
- role: worker
10 changes: 10 additions & 0 deletions yamls/ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ spec:
type: ClusterIP
selector:
app: ovn-central
ovn-db-leader: "true"
sessionAffinity: None

---
Expand All @@ -116,6 +117,7 @@ spec:
type: ClusterIP
selector:
app: ovn-central
ovn-db-leader: "true"
sessionAffinity: None

---
Expand Down Expand Up @@ -165,6 +167,14 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources:
requests:
cpu: 500m
Expand Down

0 comments on commit 06eceb3

Please sign in to comment.