Skip to content

Commit

Permalink
Merge pull request #11 from romana/feature/dynamic-segments
Browse files Browse the repository at this point in the history
Implement dynamic romana segment creation via CNI plugin
  • Loading branch information
pritesh committed Jun 8, 2016
2 parents 108d71a + 4b920f1 commit 4ac5970
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CNI/net.d/10-romana.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "romana-k8s-network",
"type": "romana",
"kube_master_ip": "192.168.99.10",
"romana_cli_config": "/home/ubuntu/.romana.yaml",
"ipam": {
"type": "romana-ipam"
}
}
14 changes: 14 additions & 0 deletions CNI/romana
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exec &>> $LOGFILE
NETWORK_NAME="romana-k8s-network"
PLUGIN_TYPE="romana"
IPAM_TYPE="romana-ipam"
ROMANA_CLI="romana"

# -- Helpers
get_pod () { while read line; do [[ ${line/=*/} == "K8S_POD_NAME" ]] && echo ${line/*=/} || :; done; }
Expand Down Expand Up @@ -93,6 +94,9 @@ for k in $(echo $INPUT | jq -r 'keys[]'); do
romana_master_ip)
ROMANA_MASTER_IP=$(get_config_item $k)
;;
romana_cli_config)
ROMANA_CLI="$ROMANA_CLI -c $(get_config_item $k)"
;;
esac
done

Expand Down Expand Up @@ -152,6 +156,16 @@ set_up_pod () {
[[ $NS_ISOLATION != "on" ]] && NS_ISOLATION="off"
log "--- NS_ISOLATION = $NS_ISOLATION ---"

# Ensure segment exists
log "-- Ensuring segment for tenant $NAMESPACE --"
SEGMENT_CHECK=$($ROMANA_CLI segment list $NAMESPACE -f json | jq -r --arg seg $SEGMENT '.[] |.Segments[] | if .Name==$seg then "OK" else empty end')
if ! [[ $SEGMENT_CHECK ]]; then
log "--- SEGMENT $SEGMENT does not exist - creating ---"
$ROMANA_CLI segment add $NAMESPACE $SEGMENT -i $SEGMENT
else
log "--- SEGMENT $SEGMENT exists ---"
fi

# Asking romana ipam for an IP address, based on `tenant` label.
log "--- PRE-IPAM ---"
[[ $SEGMENT ]] || SEGMENT=default
Expand Down

0 comments on commit 4ac5970

Please sign in to comment.