Skip to content

Commit

Permalink
fix pinger's compatibility for k8s v1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Dec 6, 2021
1 parent 90f62fd commit ea300d2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
4 changes: 0 additions & 4 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2134,10 +2134,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: HOST_IP
valueFrom:
fieldRef:
Expand Down
3 changes: 0 additions & 3 deletions dist/images/update/1.7-1.8.1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,6 @@ echo "[Step 6/8] Update kube-ovn-pinger"
if [[ $(kubectl get ds -n kube-system kube-ovn-pinger -o jsonpath='{.spec.template}') =~ "tolerations" ]]; then
kubectl patch ds/kube-ovn-pinger -n kube-system --type='json' -p='[{"op": "remove", "path": "/spec/template/spec/tolerations"}]'
fi
if [[ ! $(kubectl get ds -n kube-system kube-ovn-pinger -o jsonpath='{.spec.template}') =~ "POD_IPS" ]]; then
kubectl patch ds/kube-ovn-pinger -n kube-system --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/env/-", "value": {"name": "POD_IPS", "valueFrom": {"fieldRef": {"fieldPath": "status.podIPs"}}}}]'
fi
kubectl set image ds/kube-ovn-pinger -n kube-system pinger="$IMAGE"
kubectl rollout status daemonset/kube-ovn-pinger -n kube-system
echo "-------------------------------"
Expand Down
20 changes: 13 additions & 7 deletions pkg/pinger/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package pinger

import (
"context"
"flag"
"os"
"strings"
"time"

"github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -30,7 +31,6 @@ type Configuration struct {
HostIP string
PodName string
PodIP string
PodIPs []string
PodProtocols []string
ExternalAddress string
NetworkMode string
Expand Down Expand Up @@ -111,7 +111,6 @@ func ParseFlags() (*Configuration, error) {
InternalDNS: *argInternalDns,
ExternalDNS: *argExternalDns,
PodIP: os.Getenv("POD_IP"),
PodIPs: strings.Split(os.Getenv("POD_IPS"), ","),
HostIP: os.Getenv("HOST_IP"),
NodeName: os.Getenv("NODE_NAME"),
PodName: os.Getenv("POD_NAME"),
Expand All @@ -133,15 +132,22 @@ func ParseFlags() (*Configuration, error) {
ServiceOvnControllerFileLogPath: *argServiceOvnControllerFileLogPath,
ServiceOvnControllerFilePidPath: *argServiceOvnControllerFilePidPath,
}
config.PodProtocols = make([]string, len(config.PodIPs))
for i, podIP := range config.PodIPs {
config.PodProtocols[i] = util.CheckProtocol(podIP)
if err := config.initKubeClient(); err != nil {
return nil, err
}

if err := config.initKubeClient(); err != nil {
name := os.Getenv("POD_NAME")
pod, err := config.KubeClient.CoreV1().Pods("kube-system").Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get self pod kube-system/%s: %v", name, err)
return nil, err
}

config.PodProtocols = make([]string, len(pod.Status.PodIPs))
for i, podIP := range pod.Status.PodIPs {
config.PodProtocols[i] = util.CheckProtocol(podIP.IP)
}

klog.Infof("pinger config is %+v", config)
return config, nil
}
Expand Down
4 changes: 0 additions & 4 deletions yamls/kube-ovn-ipv6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: HOST_IP
valueFrom:
fieldRef:
Expand Down
4 changes: 0 additions & 4 deletions yamls/kube-ovn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,6 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: HOST_IP
valueFrom:
fieldRef:
Expand Down

0 comments on commit ea300d2

Please sign in to comment.