-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable kube-route to be run as daemonset, now just run kubectl create…
… -f kube-router-daemonset.yaml
- Loading branch information
Murali Reddy
committed
Apr 26, 2017
1 parent
6ecb4bb
commit f8fbb42
Showing
9 changed files
with
162 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine | ||
RUN apk add --no-cache iptables ipset | ||
COPY kube-router / | ||
|
||
ENTRYPOINT ["/kube-router"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
#all: push | ||
all: | ||
go build -o kube-router kube-router.go | ||
all: dockerimg | ||
|
||
dockerimg: build | ||
sudo docker build -t "cloudnativelabs/kube-router" . | ||
|
||
build: | ||
go build --ldflags '-extldflags "-static"' -o kube-router kube-router.go | ||
|
||
clean: | ||
rm -f kube-router | ||
|
||
run: | ||
./kube-router --kubeconfig=~/kubeconfig | ||
./kube-router --kubeconfig=/var/lib/kube-router/kubeconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: DaemonSet | ||
metadata: | ||
name: kube-router | ||
namespace: kube-system | ||
labels: | ||
app: kube-router | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
name: kube-router | ||
spec: | ||
hostNetwork: true | ||
containers: | ||
- name: kube-router | ||
image: cloudnativelabs/kube-router | ||
args: ["--run-router=false"] | ||
securityContext: | ||
privileged: true | ||
imagePullPolicy: Always | ||
env: | ||
- name: NODE_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: spec.nodeName | ||
volumeMounts: | ||
- mountPath: /lib/modules | ||
name: lib-modules | ||
readOnly: true | ||
- mountPath: /etc/cni/net.d/10-kuberouter.conf | ||
name: cni-conf-dir | ||
- mountPath: /var/lib/kube-router/kubeconfig | ||
name: kubeconfig | ||
volumes: | ||
- name: lib-modules | ||
hostPath: | ||
path: /lib/modules | ||
- name: cni-conf-dir | ||
hostPath: | ||
path: /etc/cni/net.d/10-kuberouter.conf | ||
- name: kubeconfig | ||
hostPath: | ||
path: /var/lib/kube-router/kubeconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,60 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
|
||
"github.com/containernetworking/cni/libcni" | ||
"github.com/containernetworking/cni/plugins/ipam/host-local/backend/allocator" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
func GetPodCidrDetails(cniConfFilePath string) (string, int, error) { | ||
func GetPodCidrFromCniSpec(cniConfFilePath string) (net.IPNet, error) { | ||
netconfig, err := libcni.ConfFromFile(cniConfFilePath) | ||
if err != nil { | ||
return "", 0, fmt.Errorf("Failed to load CNI conf: %s", err.Error()) | ||
return net.IPNet{}, fmt.Errorf("Failed to load CNI conf file: %s", err.Error()) | ||
} | ||
|
||
var ipamConfig *allocator.IPAMConfig | ||
ipamConfig, _, err = allocator.LoadIPAMConfig(netconfig.Bytes, "") | ||
if err != nil { | ||
return "", 0, fmt.Errorf("Failed to get IPAM details from the CNI conf file: %s", err.Error()) | ||
return net.IPNet{}, fmt.Errorf("Failed to get IPAM details from the CNI conf file: %s", err.Error()) | ||
} | ||
return net.IPNet(ipamConfig.Subnet), nil | ||
} | ||
|
||
func InsertPodCidrInCniSpec(cniConfFilePath string, cidr string) error { | ||
file, err := ioutil.ReadFile(cniConfFilePath) | ||
if err != nil { | ||
return fmt.Errorf("Failed to load CNI conf file: %s", err.Error()) | ||
} | ||
config := make(map[string]interface{}) | ||
err = json.Unmarshal(file, &config) | ||
if err != nil { | ||
return fmt.Errorf("Failed to parse JSON from CNI conf file: %s", err.Error()) | ||
} | ||
|
||
config["ipam"].(map[string]interface{})["subnet"] = cidr | ||
configJson, _ := json.Marshal(config) | ||
err = ioutil.WriteFile(cniConfFilePath, configJson, 0644) | ||
if err != nil { | ||
return fmt.Errorf("Failed to insert subnet cidr into CNI conf file: %s", err.Error()) | ||
} | ||
return nil | ||
} | ||
|
||
cidrlen, _ := ipamConfig.Subnet.Mask.Size() | ||
return ipamConfig.Subnet.IP.String(), cidrlen, nil | ||
func GetPodCidrFromNodeSpec(clientset *kubernetes.Clientset) (string, error) { | ||
nodeHostName, err := os.Hostname() | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
node, err := clientset.Core().Nodes().Get(nodeHostName, metav1.GetOptions{}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
return node.Spec.PodCIDR, nil | ||
} |