Skip to content

Commit

Permalink
Rename back and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesc committed Nov 29, 2018
1 parent 52feaae commit 127c845
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cmd/octopus/octopus.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func cmdAdd(args *skel.CmdArgs) error {
}

// 3. Get annotations from k8s_client via K8S_POD_NAME and K8S_POD_NAMESPACE.
_, annot, err := k8s.GetK8sPodInfo(k8sClient, string(k8sArgs.PodName), string(k8sArgs.PodNamespace))
_, annot, err := k8s.GetK8sPodInfo(k8sClient, string(k8sArgs.K8S_POD_NAME), string(k8sArgs.K8S_POD_NAMESPACE))
if err != nil {
return fmt.Errorf("failed to read annotaions for pod " + err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/anchor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data:
"kubeconfig": "__KUBECONFIG_FILEPATH__"
},
"ipam": {
"type": "anchor-ipam",
"type": "anchor",
"etcd_endpoints": "__ETCD_ENDPOINTS__",
"etcd_key_file": "__ETCD_KEY_FILE__",
"etcd_cert_file": "__ETCD_CERT_FILE__",
Expand Down
13 changes: 6 additions & 7 deletions internal/app/anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ func newAllocator(args *skel.CmdArgs, conf *config.IPAMConf) (*anchor.Allocator,
}

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

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

return anchor.NewAllocator(store, string(k8sArgs.PodName),
string(k8sArgs.PodNamespace), customized)
return anchor.NewAllocator(store, string(k8sArgs.K8S_POD_NAME),
string(k8sArgs.K8S_POD_NAMESPACE), customized)
}

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

return anchor.NewCleaner(store,
string(k8sArgs.PodName),
string(k8sArgs.PodNamespace))
string(k8sArgs.K8S_POD_NAME),
string(k8sArgs.K8S_POD_NAMESPACE))
}
6 changes: 3 additions & 3 deletions pkg/runtime/k8s/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Kubernetes struct {
type Args struct {
types.CommonArgs
IP net.IP
PodName types.UnmarshallableString
PodNamespace types.UnmarshallableString
PodInfraContainerID types.UnmarshallableString
K8S_POD_NAME types.UnmarshallableString
K8S_POD_NAMESPACE types.UnmarshallableString
K8S_POD_INFRA_CONTAINER_ID types.UnmarshallableString
}
20 changes: 3 additions & 17 deletions pkg/store/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"crypto/tls"
"fmt"
"net"
"reflect"
"strings"
"time"

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

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

for _, item := range resp.Kvs {
parts := strings.Split(string(item.Value), ",")
_, n, err := net.ParseCIDR(parts[0])
if err != nil {
// ommit the error.
continue
}
// TODO: if go-cmp better?
if reflect.DeepEqual(subnet, n) {
gw := net.ParseIP(parts[1])
return gw
}
}
return nil
}

// RetrieveAllocated retrieves allocated IPs in subnet for namespace.
func (e *Etcd) RetrieveAllocated(namespace string, subnet *net.IPNet) (*utils.RangeSet, error) {
resp, err := e.kv.Get(context.TODO(), userPrefix+namespace)
resp, err := e.kv.Get(context.TODO(), userPrefix + namespace)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 127c845

Please sign in to comment.