Skip to content

Commit 127c845

Browse files
committed
Rename back and bug fix
1 parent 52feaae commit 127c845

File tree

5 files changed

+14
-29
lines changed

5 files changed

+14
-29
lines changed

cmd/octopus/octopus.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func cmdAdd(args *skel.CmdArgs) error {
136136
}
137137

138138
// 3. Get annotations from k8s_client via K8S_POD_NAME and K8S_POD_NAMESPACE.
139-
_, annot, err := k8s.GetK8sPodInfo(k8sClient, string(k8sArgs.PodName), string(k8sArgs.PodNamespace))
139+
_, annot, err := k8s.GetK8sPodInfo(k8sClient, string(k8sArgs.K8S_POD_NAME), string(k8sArgs.K8S_POD_NAMESPACE))
140140
if err != nil {
141141
return fmt.Errorf("failed to read annotaions for pod " + err.Error())
142142
}

deployment/anchor.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ data:
3737
"kubeconfig": "__KUBECONFIG_FILEPATH__"
3838
},
3939
"ipam": {
40-
"type": "anchor-ipam",
40+
"type": "anchor",
4141
"etcd_endpoints": "__ETCD_ENDPOINTS__",
4242
"etcd_key_file": "__ETCD_KEY_FILE__",
4343
"etcd_cert_file": "__ETCD_CERT_FILE__",

internal/app/anchor.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ func newAllocator(args *skel.CmdArgs, conf *config.IPAMConf) (*anchor.Allocator,
101101
}
102102

103103
// 3. Get annotations from k8s_client via K8S_POD_NAME and K8S_POD_NAMESPACE.
104-
label, annot, err := k8s.GetK8sPodInfo(runtime, string(k8sArgs.PodName),
105-
string(k8sArgs.PodNamespace))
104+
label, annot, err := k8s.GetK8sPodInfo(runtime, string(k8sArgs.K8S_POD_NAME), string(k8sArgs.K8S_POD_NAMESPACE))
106105
if err != nil {
107106
return nil, err
108107
}
@@ -117,13 +116,13 @@ func newAllocator(args *skel.CmdArgs, conf *config.IPAMConf) (*anchor.Allocator,
117116

118117
// It is friendly to show which controller the pods controled by.
119118
// TODO: maybe it is meaningless. the pod name starts with the controller name.
120-
controllerName, _ := k8s.ResourceControllerName(runtime, string(k8sArgs.PodName), string(k8sArgs.PodNamespace))
119+
controllerName, _ := k8s.ResourceControllerName(runtime, string(k8sArgs.K8S_POD_NAME), string(k8sArgs.K8S_POD_NAMESPACE))
121120
if controllerName != "" {
122121
customized["cni.anchor.org/controller"] = controllerName
123122
}
124123

125-
return anchor.NewAllocator(store, string(k8sArgs.PodName),
126-
string(k8sArgs.PodNamespace), customized)
124+
return anchor.NewAllocator(store, string(k8sArgs.K8S_POD_NAME),
125+
string(k8sArgs.K8S_POD_NAMESPACE), customized)
127126
}
128127

129128
func newCleaner(args *skel.CmdArgs, ipamConf *config.IPAMConf) (*anchor.Cleaner, error) {
@@ -148,6 +147,6 @@ func newCleaner(args *skel.CmdArgs, ipamConf *config.IPAMConf) (*anchor.Cleaner,
148147
}
149148

150149
return anchor.NewCleaner(store,
151-
string(k8sArgs.PodName),
152-
string(k8sArgs.PodNamespace))
150+
string(k8sArgs.K8S_POD_NAME),
151+
string(k8sArgs.K8S_POD_NAMESPACE))
153152
}

pkg/runtime/k8s/types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Kubernetes struct {
3434
type Args struct {
3535
types.CommonArgs
3636
IP net.IP
37-
PodName types.UnmarshallableString
38-
PodNamespace types.UnmarshallableString
39-
PodInfraContainerID types.UnmarshallableString
37+
K8S_POD_NAME types.UnmarshallableString
38+
K8S_POD_NAMESPACE types.UnmarshallableString
39+
K8S_POD_INFRA_CONTAINER_ID types.UnmarshallableString
4040
}

pkg/store/etcd/etcd.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"crypto/tls"
1313
"fmt"
1414
"net"
15-
"reflect"
1615
"strings"
1716
"time"
1817

@@ -99,30 +98,17 @@ func (e *Etcd) Close() error {
9998

10099
// RetrieveGateway retrieves gateway for subnet.
101100
func (e *Etcd) RetrieveGateway(subnet *net.IPNet) net.IP {
102-
resp, err := e.kv.Get(context.TODO(), gatewayPrefix, clientv3.WithPrefix())
101+
resp, err := e.kv.Get(context.TODO(), gatewayPrefix + subnet.String())
103102
if err != nil {
104103
return nil
105104
}
105+
return net.ParseIP(string(resp.Kvs[0].Value))
106106

107-
for _, item := range resp.Kvs {
108-
parts := strings.Split(string(item.Value), ",")
109-
_, n, err := net.ParseCIDR(parts[0])
110-
if err != nil {
111-
// ommit the error.
112-
continue
113-
}
114-
// TODO: if go-cmp better?
115-
if reflect.DeepEqual(subnet, n) {
116-
gw := net.ParseIP(parts[1])
117-
return gw
118-
}
119-
}
120-
return nil
121107
}
122108

123109
// RetrieveAllocated retrieves allocated IPs in subnet for namespace.
124110
func (e *Etcd) RetrieveAllocated(namespace string, subnet *net.IPNet) (*utils.RangeSet, error) {
125-
resp, err := e.kv.Get(context.TODO(), userPrefix+namespace)
111+
resp, err := e.kv.Get(context.TODO(), userPrefix + namespace)
126112
if err != nil {
127113
return nil, err
128114
}

0 commit comments

Comments
 (0)