diff --git a/daemon/daemon.go b/daemon/daemon.go index f6048898..14c3f952 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -40,7 +40,6 @@ type networkService struct { //networkResourceMgr ResourceManager mgrForResource map[string]ResourceManager pendingPods map[string]interface{} - patchPodIP bool pendingPodsLock sync.RWMutex sync.RWMutex } @@ -199,7 +198,6 @@ func (networkService *networkService) AllocIP(grpcContext context.Context, r *rp } // 3. Allocate network resource for pod - var podIP string switch podinfo.PodNetworkType { case podNetworkTypeENIMultiIP: var eniMultiIP *types.ENIIP @@ -221,7 +219,6 @@ func (networkService *networkService) AllocIP(grpcContext context.Context, r *rp if err != nil { return nil, errors.Wrapf(err, "error put resource into store") } - podIP = eniMultiIP.SecAddress.String() allocIPReply.IPType = rpc.IPType_TypeENIMultiIP allocIPReply.Success = true allocIPReply.NetworkInfo = &rpc.AllocIPReply_ENIMultiIP{ @@ -261,7 +258,6 @@ func (networkService *networkService) AllocIP(grpcContext context.Context, r *rp if err != nil { return nil, errors.Wrapf(err, "error put resource into store") } - podIP = vpcEni.Address.IP.String() allocIPReply.IPType = rpc.IPType_TypeVPCENI allocIPReply.Success = true allocIPReply.NetworkInfo = &rpc.AllocIPReply_VpcEni{ @@ -323,14 +319,7 @@ func (networkService *networkService) AllocIP(grpcContext context.Context, r *rp return nil, errors.Wrapf(err, "error on grpc connection") } - // 4. patch podIP to kube-apiserver - if allocIPReply.Success && podIP != "" && networkService.patchPodIP { - if _, err := networkService.k8s.PatchAllocatedPodIP(podinfo, podIP); err != nil { - return nil, errors.Wrapf(err, fmt.Sprintf("failed to patch podIP to pod %s.", podInfoKey(podinfo.Namespace, podinfo.Name))) - } - } - - // 5. return allocate result + // 4. return allocate result return allocIPReply, err } @@ -550,10 +539,9 @@ func (networkService *networkService) startGarbageCollectionLoop() { }() } -func newNetworkService(configFilePath, kubeconfig, master, daemonMode string, patchPodIP bool) (rpc.TerwayBackendServer, error) { +func newNetworkService(configFilePath, kubeconfig, master, daemonMode string) (rpc.TerwayBackendServer, error) { log.Debugf("start network service with: %s, %s", configFilePath, daemonMode) netSrv := &networkService{ - patchPodIP: patchPodIP, pendingPods: map[string]interface{}{}, pendingPodsLock: sync.RWMutex{}, } diff --git a/daemon/k8s.go b/daemon/k8s.go index 2bebeb99..cd90460b 100644 --- a/daemon/k8s.go +++ b/daemon/k8s.go @@ -55,7 +55,6 @@ type Kubernetes interface { GetServiceCidr() *net.IPNet GetNodeCidr() *net.IPNet SetNodeAllocatablePod(count int) error - PatchAllocatedPodIP(podInfo *podInfo, podIP string) (*corev1.Pod, error) } type k8s struct { @@ -403,26 +402,6 @@ func (k *k8s) GetLocalPods() ([]*podInfo, error) { return ret, nil } -func (k *k8s) PatchAllocatedPodIP(podInfo *podInfo, podIP string) (*corev1.Pod, error) { - pod, err := k.client.CoreV1().Pods(podInfo.Namespace).Get(podInfo.Name, metav1.GetOptions{ - ResourceVersion: "0", - }) - if err != nil || pod == nil { - k.reconnectOnTimeoutError(err) - return nil, err - } - if pod.Status.PodIP != "" { - return nil, err - } - pod.Status.PodIP = podIP - pod, err = k.client.CoreV1().Pods(podInfo.Namespace).UpdateStatus(pod) - if err != nil { - k.reconnectOnTimeoutError(err) - return nil, err - } - return pod, nil -} - func (k *k8s) GetServiceCidr() *net.IPNet { return k.svcCidr } diff --git a/daemon/server.go b/daemon/server.go index a6143fec..a76a9823 100644 --- a/daemon/server.go +++ b/daemon/server.go @@ -49,7 +49,7 @@ func stackTriger() { } // Run terway daemon -func Run(pidFilePath, socketFilePath, debugSocketListen, configFilePath, kubeconfig, master, daemonMode, logLevel string, patchPodIP bool) error { +func Run(pidFilePath, socketFilePath, debugSocketListen, configFilePath, kubeconfig, master, daemonMode, logLevel string) error { level, err := log.ParseLevel(logLevel) if err != nil { return errors.Wrapf(err, "error set log level: %s", logLevel) @@ -84,7 +84,7 @@ func Run(pidFilePath, socketFilePath, debugSocketListen, configFilePath, kubecon return fmt.Errorf("error listen at %s: %v", socketFilePath, err) } - networkService, err := newNetworkService(configFilePath, kubeconfig, master, daemonMode, patchPodIP) + networkService, err := newNetworkService(configFilePath, kubeconfig, master, daemonMode) if err != nil { return err } diff --git a/main.go b/main.go index d7257c0f..e0d118a8 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,6 @@ var ( readonlyListen string kubeconfig string master string - patchPodIP bool ) func init() { @@ -28,14 +27,13 @@ func init() { flag.StringVar(&readonlyListen, "readonly-listen", debugSocketPath, "terway readonly listen") flag.StringVar(&master, "master", "", "The address of the Kubernetes API server (overrides any value in kubeconfig).") flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.") - flag.BoolVar(&patchPodIP, "patch-podip", false, "Whether patch the podIP to kube-apiserver after setting up the pod network.") } func main() { flag.Parse() log.Infof("Starting terway of version: %s", gitVer) - if err := daemon.Run(defaultPidPath, defaultSocketPath, readonlyListen, defaultConfigPath, kubeconfig, master, daemonMode, logLevel, patchPodIP); err != nil { + if err := daemon.Run(defaultPidPath, defaultSocketPath, readonlyListen, defaultConfigPath, kubeconfig, master, daemonMode, logLevel); err != nil { log.Fatal(err) } }