Skip to content

Commit 362d5b1

Browse files
committed
use fleet metadata for nginx, appside and devside
1 parent ccaa189 commit 362d5b1

File tree

4 files changed

+43
-68
lines changed

4 files changed

+43
-68
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.vagrant
2+
user-data_*

coreos/Vagrantfile

+41-28
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@
22
# -*- coding: utf-8 -*-
33

44
require 'fileutils'
5-
6-
require './coreos_config.rb'
5+
require 'open-uri'
6+
require 'yaml'
77

88
Vagrant.require_version '>= 1.6.0'
99

1010
CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), 'user-data')
1111

12+
update_channel = 'alpha'
13+
image_version = 'current'
14+
vm_memory = 512
15+
vm_cpus = 1
16+
17+
cluster = [
18+
{ name: 'core-01', hostname: 'core-01', ip: '172.17.8.101', metadata: 'role=nginx' },
19+
{ name: 'core-02', hostname: 'core-02', ip: '172.17.8.102', metadata: 'role=appside' },
20+
{ name: 'core-03', hostname: 'core-03', ip: '172.17.8.103', metadata: 'role=devside' }
21+
]
22+
23+
# Used to fetch a new discovery token for a cluster of size 3
24+
new_discovery_url = "https://discovery.etcd.io/new?size=#{ cluster.size }"
25+
token = open(new_discovery_url).read
26+
1227
Vagrant.configure('2') do |config|
1328
# always use Vagrants insecure key
1429
config.ssh.insert_key = false
1530

16-
config.vm.box = "coreos-%s" % $update_channel
17-
if $image_version != 'current'
18-
config.vm.box_version = $image_version
19-
end
20-
config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json" % [$update_channel, $image_version]
31+
config.vm.box = "coreos-%s" % update_channel
32+
config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json" % [update_channel, image_version]
2133

2234
config.vm.provider :virtualbox do |v|
2335
# On VirtualBox, we don't have guest additions or a functional vboxsf
@@ -26,33 +38,34 @@ Vagrant.configure('2') do |config|
2638
v.functional_vboxsf = false
2739
end
2840

29-
(1..$num_instances).each do |i|
30-
config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
31-
config.vm.hostname = vm_name
32-
33-
if $enable_serial_logging
34-
logdir = File.join(File.dirname(__FILE__), 'log')
35-
FileUtils.mkdir_p(logdir)
36-
37-
serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
38-
FileUtils.touch(serialFile)
39-
end
40-
41-
$forwarded_ports.each do |guest, host|
42-
config.vm.network 'forwarded_port', guest: guest, host: host, auto_correct: true
43-
end
41+
cluster.each do |node|
42+
config.vm.define node[:name] do |config|
43+
config.vm.hostname = node[:hostname]
4444

4545
config.vm.provider :virtualbox do |v|
46-
v.name = vm_name
47-
v.memory = $vm_memory
48-
v.cpus = $vm_cpus
46+
v.name = node[:name]
47+
v.memory = vm_memory
48+
v.cpus = vm_cpus
4949
end
5050

51-
ip = "172.17.8.#{ i+100 }"
52-
config.vm.network :private_network, ip: ip
51+
config.vm.network :private_network, ip: node[:ip]
5352

5453
# cloudconfig-init
55-
config.vm.provision :file, :source => "#{ CLOUD_CONFIG_PATH }", :destination => '/tmp/vagrantfile-user-data'
54+
data = YAML.load(IO.readlines('user-data')[1..-1].join)
55+
56+
# Add discovery url
57+
data['coreos']['etcd2']['discovery'] = token
58+
59+
# Add metadata
60+
data['coreos']['fleet']['metadata'] = node[:metadata]
61+
62+
yaml = YAML.dump(data)
63+
64+
source_file = File.join(File.dirname(__FILE__), "user-data_#{ node[:name] }")
65+
FileUtils.rm source_file if File.exists?(source_file)
66+
File.open(source_file, 'w') { |file| file.write("#cloud-config\n\n#{ yaml }") }
67+
68+
config.vm.provision :file, :source => source_file, :destination => '/tmp/vagrantfile-user-data'
5669
config.vm.provision :shell, :inline => 'mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/', :privileged => true
5770
end
5871
end

coreos/coreos_config.rb

-40
This file was deleted.

coreos/user-data

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ coreos:
1010
discovery: https://discovery.etcd.io/<token>
1111
fleet:
1212
public-ip: $public_ipv4
13+
metadata: <metadata>
1314
flannel:
1415
interface: $public_ipv4
1516
units:

0 commit comments

Comments
 (0)