Skip to content

Commit

Permalink
Merge pull request #91 from stormgbs/master
Browse files Browse the repository at this point in the history
Remove patching pod IP which will be overwritten by kubelet
  • Loading branch information
BSWANG authored Apr 7, 2020
2 parents 9fb42df + 6835a2f commit 7a5a1bf
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 40 deletions.
16 changes: 2 additions & 14 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type networkService struct {
//networkResourceMgr ResourceManager
mgrForResource map[string]ResourceManager
pendingPods map[string]interface{}
patchPodIP bool
pendingPodsLock sync.RWMutex
sync.RWMutex
}
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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{},
}
Expand Down
21 changes: 0 additions & 21 deletions daemon/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
readonlyListen string
kubeconfig string
master string
patchPodIP bool
)

func init() {
Expand All @@ -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)
}
}

0 comments on commit 7a5a1bf

Please sign in to comment.