-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak Dockerfile to install bins on k8s
- Loading branch information
1 parent
ed9f217
commit 2628758
Showing
4 changed files
with
91 additions
and
2 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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
FROM debian:jessie | ||
MAINTAINER projectcalico | ||
|
||
# Add python | ||
RUN apt-get update | ||
RUN apt-get install -y python | ||
|
||
# Add binaries to image. | ||
RUN mkdir -p /opt/cni/bin | ||
ADD ./dist/calico /opt/cni/bin | ||
ADD ./dist/calico-ipam /opt/cni/bin | ||
|
||
# Add CNI install script. | ||
ADD ./scripts/install-cni.sh /install-cni.sh | ||
ADD ./scripts/conf_writer.py /conf_writer.py | ||
|
||
# Set volume, environment, and working directory. | ||
VOLUME /opt/cni | ||
ENV PATH=$PATH:/opt/cni/bin | ||
WORKDIR /opt/cni/bin |
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,46 @@ | ||
# Writes a Calico CNI network config to disk using | ||
# the provided environment. | ||
import os | ||
import json | ||
|
||
# Standard network config file. Will be populated based on | ||
# the environment. | ||
conf_dict = { | ||
"type": "calico", | ||
"ipam": { | ||
"type": "calico-ipam" | ||
}, | ||
} | ||
|
||
# Check if a kubeconfig was given. | ||
if os.environ.get("KUBECONFIG"): | ||
conf_dict["kubernetes"] = {} | ||
conf_dict["kubernetes"]["kubeconfig"] = os.environ.get("KUBECONFIG") | ||
|
||
# Check for policy type. | ||
if os.environ.get("POLICY_TYPE"): | ||
p = conf_dict.setdefault("policy", {}) | ||
p["type"] = os.environ.get("POLICY_TYPE") | ||
|
||
# Check for a k8s API root. | ||
if os.environ.get("K8S_API"): | ||
p["k8s_api_root"] = os.environ.get("K8S_API") | ||
|
||
# Check for certificates. | ||
if os.environ.get("K8S_CLIENT_CERT"): | ||
p["k8s_client_certificate"] = os.environ.get("K8S_CLIENT_CERT") | ||
if os.environ.get("K8S_CLIENT_KEY"): | ||
p["k8s_client_key"] = os.environ.get("K8S_CLIENT_KEY") | ||
if os.environ.get("K8S_CERT_AUTHORITY"): | ||
p["k8s_certificate_authority"] = os.environ.get("K8S_CERT_AUTHORITY") | ||
|
||
# Check for token. | ||
if os.environ.get("K8S_TOKEN"): | ||
p["k8s_auth_token"] = os.environ.get("K8S_TOKEN") | ||
|
||
# Set log level. | ||
conf_dict["log_level"] = os.environ.get("LOG_LEVEL", "info").lower() | ||
|
||
# Print the generated network config. | ||
conf = json.dumps(conf_dict, indent=2) | ||
print conf |
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,31 @@ | ||
#!/bin/bash | ||
|
||
# Script to install Calico CNI on a Kubernetes host. | ||
# Expects the CNI binary path to be mounted in to the | ||
# `calico/cni` container at /host/opt/cni/bin. | ||
# Expects the CNI network config path to be mounted in | ||
# to the `calico/cni` container at /host/etc/cni/net.d. | ||
|
||
# Clean up any existing binaries. | ||
rm -f /host/opt/cni/bin/calico /host/opt/cni/bin/calico-ipam | ||
|
||
# Place the new binaries. | ||
cp /opt/cni/bin/calico /host/opt/cni/bin/calico | ||
cp /opt/cni/bin/calico-ipam /host/opt/cni/bin/calico-ipam | ||
echo "Wrote Calico CNI binaries to /host/opt/cni/bin/" | ||
echo "Version: $(/host/opt/cni/bin/calico -v)" | ||
|
||
# Make the network configuration file. | ||
cat >/host/etc/cni/net.d/10-calico.conf <<EOF | ||
$(/usr/bin/python /conf_writer.py) | ||
EOF | ||
|
||
echo "Wrote CNI config to disk: $(cat /host/etc/cni/net.d/10-calico.conf)" | ||
|
||
# Unless told otherwise, sleep forever. | ||
# This prevents Kubernetes from restarting the pod repeatedly. | ||
should_sleep=${SLEEP:-"true"} | ||
echo "Done configuring CNI. Sleep=$should_sleep" | ||
while [ "$should_sleep" == "true" ]; do | ||
sleep 1; | ||
done |