Skip to content

Commit

Permalink
Merge pull request #4 from adidenko/master
Browse files Browse the repository at this point in the history
Calico support added
  • Loading branch information
mwhahaha committed May 20, 2016
2 parents 681b2d8 + 80ddc31 commit 83bbb74
Show file tree
Hide file tree
Showing 34 changed files with 598 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.build
*.pyc
deployment_scripts/puppet/modules/docker
.utils/skip-debs
Gemfile.lock
10 changes: 10 additions & 0 deletions .utils/build_all_debs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mkdir -p $TMPDIR
etcd_ver='2.3.3'
flannel_ver='0.5.5'
kubernetes_ver='1.2.4'
calico_ver='0.19.0'
calico_cni_ver='1.3.0'

pushd $TMPDIR
rm -rf etcd flannel kubernetes
Expand All @@ -20,6 +22,11 @@ mv flannel-${flannel_ver} flannel
wget -c -N https://github.com/kubernetes/kubernetes/releases/download/v${kubernetes_ver}/kubernetes.tar.gz
tar xzf kubernetes.tar.gz kubernetes/server/kubernetes-server-linux-amd64.tar.gz
tar xzf kubernetes/server/kubernetes-server-linux-amd64.tar.gz
wget -c -N https://github.com/projectcalico/calico-containers/releases/download/v${calico_ver}/calicoctl
chmod 755 calicoctl
wget -c -N https://github.com/projectcalico/calico-cni/releases/download/v${calico_cni_ver}/calico
wget -c -N https://github.com/projectcalico/calico-cni/releases/download/v${calico_cni_ver}/calico-ipam
chmod 755 calico calico-ipam
popd

$CWD/build_static_deb.sh etcd $etcd_ver $TMPDIR/etcd
Expand All @@ -28,6 +35,9 @@ for file in `find $TMPDIR/kubernetes/server -type f -executable`; do
fname=${file##*/}
$CWD/build_static_deb.sh $fname $kubernetes_ver $file
done
$CWD/build_static_deb.sh calicoctl $calico_ver $TMPDIR/calicoctl
$CWD/build_static_deb.sh calico $calico_cni_ver $TMPDIR/calico
$CWD/build_static_deb.sh calico-ipam $calico_cni_ver $TMPDIR/calico-ipam

#$CWD/build_static_deb.sh etcd $etcd_ver $CWD/../.binaries/etcd/v$etcd_ver
#$CWD/build_static_deb.sh flannel $flannel_ver $CWD/../.binaries/flannel/v$flannel_ver
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ curl $ip
```


Calico
------

It's possible to use Calico as a network provider for k8s. In order to do so
you need to choose it on the plugin Settings page.
Calico CLI commands example:

```
. /root/calicorc
calicoctl status
calicoctl pool show
calicoctl profile show --detailed
calicoctl profile calico-k8s-network rule show
```


Misc notes
----------

Expand Down
1 change: 1 addition & 0 deletions deployment_scripts/puppet/manifests/calico_master.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class { '::plugin_k8s::calico_master': }
1 change: 1 addition & 0 deletions deployment_scripts/puppet/manifests/calico_node.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class { '::plugin_k8s::calico_node': }
5 changes: 5 additions & 0 deletions deployment_scripts/puppet/modules/calico/.fixtures.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fixtures:
forge_modules:
stdlib: "puppetlabs/stdlib"
symlinks:
calico: "#{source_dir}"
2 changes: 2 additions & 0 deletions deployment_scripts/puppet/modules/calico/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Gemfile.lock
spec/fixtures
14 changes: 14 additions & 0 deletions deployment_scripts/puppet/modules/calico/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'metadata-json-lint'
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 1.0.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet'

# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
end
1 change: 1 addition & 0 deletions deployment_scripts/puppet/modules/calico/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# calico
17 changes: 17 additions & 0 deletions deployment_scripts/puppet/modules/calico/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
37 changes: 37 additions & 0 deletions deployment_scripts/puppet/modules/calico/manifests/calicoctl.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Class: calico::calicoctl
# ===========================
#
# Full description of class calico here.
#
# Parameters
# ----------
#
# * `etcd_servers`
# Specify list of etcd_servers.
#
# Examples
# --------
#
# @example
# class { 'calico':
# etcd_servers => 'http://127.0.0.1:4001'
# }
#
# Authors
# -------
#
# Author Name <[email protected]>
#
# Copyright
# ---------
#
# Copyright 2016 Your name here, unless otherwise noted.
#
class calico::calicoctl (
$etcd_servers = 'http://127.0.0.1:2379',
) {
package {'calicoctl':
ensure => installed,
tag => ['calico'],
}
}
67 changes: 67 additions & 0 deletions deployment_scripts/puppet/modules/calico/manifests/cni.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Class: calico::cni
# ===========================
#
# Full description of class calico here.
#
# Parameters
# ----------
#
# * `etcd_servers`
# Specify list of etcd_servers.
#
# Examples
# --------
#
# @example
# class { 'calico':
# etcd_servers => 'http://127.0.0.1:4001'
# }
#
# Authors
# -------
#
# Author Name <[email protected]>
#
# Copyright
# ---------
#
# Copyright 2016 Your name here, unless otherwise noted.
#
class calico::cni (
$etcd_servers = 'http://127.0.0.1:2379',
$confdir = '/etc/cni/net.d',
$log_level = 'info',
) {

package {['calico', 'calico-ipam']:
ensure => installed,
tag => ['calico'],
}

# TODO: (adidenko) figure out how to specify path to CNI bin
# and remove this symlink workaround. Or update package.
exec {"cni-workaround-dir":
command => "mkdir -p /opt/cni/bin",
unless => "test -d /opt/cni/bin"
} ->
file {"/opt/cni/bin/calico":
ensure => "/usr/bin/calico",
} ->
file {"/opt/cni/bin/calico-ipam":
ensure => "/usr/bin/calico-ipam",
}

exec {"create $confdir":
command => "mkdir -p $confdir",
unless => "test -d $confdir",
path => [ '/bin', '/usr/bin', '/usr/local/bin'],
} ->
file {"$confdir/10-calico.conf":
ensure => file,
content => template("${module_name}/cni.conf.erb"),
tag => ['calico'],
}

Package<| tag == 'calico' |> ->
File<| tag == 'calico' |>
}
53 changes: 53 additions & 0 deletions deployment_scripts/puppet/modules/calico/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Class: calico
# ===========================
#
# Full description of class calico here.
#
# Parameters
# ----------
#
# * `etcd_servers`
# Specify list of etcd_servers.
#
# Examples
# --------
#
# @example
# class { 'calico':
# etcd_servers => 'http://127.0.0.1:4001'
# }
#
# Authors
# -------
#
# Author Name <[email protected]>
#
# Copyright
# ---------
#
# Copyright 2016 Your name here, unless otherwise noted.
#
class calico (
$etcd_servers = 'http://127.0.0.1:2379',
$cni_conf_dir = '/etc/cni/net.d',
) {

include ::calico::calicoctl

# class {'::calico::node':
# etcd_servers => $etcd_servers,
# }
#
# class {'::calico::cni':
# etcd_servers => $etcd_servers,
# confdir => $cni_conf_dir,
# }
#
# class {'::calico::rcfile':
# etcd_servers => $etcd_servers,
# }
#
# Class['::calico::calicoctl'] ->
# Class['::calico::node']

}
51 changes: 51 additions & 0 deletions deployment_scripts/puppet/modules/calico/manifests/node.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Class: calico::node
# ===========================
#
# Full description of class calico here.
#
# Parameters
# ----------
#
# * `etcd_servers`
# Specify list of etcd_servers.
#
# Examples
# --------
#
# @example
# class { 'calico':
# etcd_servers => 'http://127.0.0.1:4001'
# }
#
# Authors
# -------
#
# Author Name <[email protected]>
#
# Copyright
# ---------
#
# Copyright 2016 Your name here, unless otherwise noted.
#
class calico::node (
$etcd_servers = 'http://127.0.0.1:2379',
) {

# Setup node
exec {'setup-calico-node':
command => 'calicoctl node',
environment => "ETCD_ENDPOINTS=$etcd_servers",
unless => "calicoctl node show | grep ' $::fqdn '",
tag => ['calico'],
# it's going to pull calico/node container, which may
# take some time
timeout => 900,
tries => 2,
}

#TODO: (adidenko) configure service

Exec<||> {
path => [ '/bin', '/usr/bin', '/usr/local/bin'],
}
}
41 changes: 41 additions & 0 deletions deployment_scripts/puppet/modules/calico/manifests/rcfile.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Class: calico::rcfile
# ===========================
#
# Full description of class calico here.
#
# Parameters
# ----------
#
# * `etcd_servers`
# Specify list of etcd_servers.
#
# Examples
# --------
#
# @example
# class { 'calico':
# etcd_servers => 'http://127.0.0.1:4001'
# }
#
# Authors
# -------
#
# Author Name <[email protected]>
#
# Copyright
# ---------
#
# Copyright 2016 Your name here, unless otherwise noted.
#
class calico::rcfile (
$etcd_servers = 'http://127.0.0.1:2379',
$rcfile = '/root/calicorc',
) {
file {$rcfile:
ensure => 'file',
content => "
export ETCD_ENDPOINTS='$etcd_servers'
",
tag => ['calico'],
}
}
15 changes: 15 additions & 0 deletions deployment_scripts/puppet/modules/calico/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "fuel-calico",
"version": "0.1.0",
"author": "fuel",
"summary": null,
"license": "Apache-2.0",
"source": "",
"project_page": null,
"issues_url": null,
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}
],
"data_provider": null
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'
describe 'calico::calicoctl' do

context 'with default values for all parameters' do
it {
should contain_package('calicoctl').with(
'ensure' => 'installed',
'tag' => ['calico']
)
}
end
end
Loading

0 comments on commit 83bbb74

Please sign in to comment.