Skip to content

Commit

Permalink
100% code coverage of kubeconfig code.
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport committed May 23, 2016
1 parent 5ff3bbf commit d5da9da
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 52 deletions.
7 changes: 3 additions & 4 deletions calico.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from pykube.config import KubeConfig
from pykube.http import HTTPClient
from pykube.objects import Node
from pykube.query import Query

from calico_cni import __version__, __commit__, __branch__
from calico_cni.util import (configure_logging, parse_cni_args, print_cni_error,
Expand Down Expand Up @@ -456,8 +455,8 @@ def _call_ipam_plugin(self, env):
if self.network_config["ipam"].get("subnet") == "usePodCidr":
if not self.running_under_k8s:
print_cni_error(ERR_CODE_GENERIC, "Invalid network config",
"Must be running under Kubernetes to use \
'subnet: usePodCidr'")
"Must be running under Kubernetes to use 'subnet: usePodCidr'")
sys.exit(ERR_CODE_GENERIC)
_log.info("Using Kubernetes podCIDR for node: %s", self.k8s_node_name)
pod_cidr = self._get_kubernetes_pod_cidr()
self.network_config["ipam"]["subnet"] = str(pod_cidr)
Expand Down Expand Up @@ -493,8 +492,8 @@ def _get_kubernetes_pod_cidr(self):
api = HTTPClient(KubeConfig.from_file(self.kubeconfig_path))
node = None
for n in Node.objects(api):
_log.debug("Checking node: %s", n.obj["metadata"]["name"])
if n.obj["metadata"]["name"] == self.k8s_node_name:
_log.debug("Checking node: %s", n.obj["metadata"]["name"])
node = n
break
if not node:
Expand Down
3 changes: 0 additions & 3 deletions calico_cni/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import re
import socket

# The hostname of the current node.
HOSTNAME = socket.gethostname()

# Regex to parse CNI_ARGS. Looks for key value pairs separated by an equals
# sign and followed either the end of the string, or a colon (indicating
# that there is another CNI_ARG key/value pair.
Expand Down
1 change: 1 addition & 0 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The CNI plugin may need to authenticate with the Kubernetes API server. The foll
* `k8s_certificate_authority`
* Verifying the API certificate against a CA only works if connecting to the API server using a hostname.
* `kubeconfig`
* Path to a Kubernetes `kubeconfig` file.


[![Analytics](https://calico-ga-beacon.appspot.com/UA-52125893-3/calico-cni/configuration.md?pixel)](https://github.com/igrigorik/ga-beacon)
Loading

0 comments on commit d5da9da

Please sign in to comment.