Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README_GCE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Get a gce service key
---------------------
1. ping twiest and ask for a GCE service key

Note: If your GCE project doesn't show a Service Account under <Project>/APIs & auth/Credentials, you will need to use "Create new
Client ID" to create a Service Account.


Convert a GCE service key into a pem (for ansible)
--------------------------------------------------
Expand Down
45 changes: 31 additions & 14 deletions cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'yaml'
require 'securerandom'
require 'fileutils'
require 'parseconfig'

SCRIPT_DIR = File.expand_path(File.dirname(__FILE__))

Expand Down Expand Up @@ -111,22 +112,26 @@ def run_playbook(playbook)

cmds = []

#cmds << 'set -x'
cmds << %Q[export ANSIBLE_FILTER_PLUGINS="#{Dir.pwd}/filter_plugins"]

# We need this for launching instances, otherwise conflicting keys and what not kill it
cmds << %q[export ANSIBLE_TRANSPORT="ssh"]
cmds << %Q[export ANSIBLE_SSH_ARGS="-o ForwardAgent=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"]
cmds << %q[export ANSIBLE_SSH_ARGS="-o ForwardAgent=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"]

# We need pipelining off so that we can do sudo to enable the root account
cmds << %Q[export ANSIBLE_SSH_PIPELINING='#{@pipelining.to_s}']

ssh_key_arg = "--private-key=~/.ssh/mmcgrath_libra" if File.file?(ENV['HOME']+'/.ssh/mmcgrath_libra.pem')
ssh_key_arg = %q[--private-key=~/.ssh/mmcgrath_libra] if File.file?(ENV['HOME']+'/.ssh/mmcgrath_libra.pem')

cmds << %Q[time -p ansible-playbook -i #{@inventory} #{@verbosity} #{playbook} #{ssh_key_arg} --extra-vars '@#{tmpfile.path}']

cmd = cmds.join(' ; ')

system(cmd)
unless system(cmd)
puts %Q[Following command failed with exit code: #{$?.exitstatus}\n#{cmd}]
puts %Q[extra_vars: #{@extra_vars.to_json}]
end
tmpfile.unlink
end

Expand All @@ -135,19 +140,31 @@ def merge_extra_vars_file(file)
@extra_vars.merge!(vars)
end

def self.for_gce()
ah = AnsibleHelper.new()
def self.for_gce
ah = AnsibleHelper.new

# GCE specific configs
ah.extra_vars['gce_pem_file'] = "#{ENV['HOME']}/.ssh/os302gce_priv_key.pem"
ah.extra_vars['gce_service_account_email'] = '198287808360-f457cs26hutqeosmlje1eosfeqo0krlg@developer.gserviceaccount.com'
ah.extra_vars['gce_project_id'] = 'corded-cable-672'
gce_ini = "#{SCRIPT_DIR}/inventory/gce/gce.ini"
config = ParseConfig.new(gce_ini)

ah.inventory = 'inventory/gce/gce.py'
if config['gce']['gce_project_id'].to_s.empty?
raise %Q['gce_project_id' not set in #{gce_ini}]
end
ah.extra_vars['gce_project_id'] = config['gce']['gce_project_id']

if config['gce']['gce_service_account_pem_file_path'].to_s.empty?
raise %Q['gce_service_account_pem_file_path' not set in #{gce_ini}]
end
ah.extra_vars['gce_pem_file'] = config['gce']['gce_service_account_pem_file_path']

if config['gce']['gce_service_account_email_address'].to_s.empty?
raise %Q['gce_service_account_email_address' not set in #{gce_ini}]
end
ah.extra_vars['gce_service_account_email'] = config['gce']['gce_service_account_email_address']

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love all of these.

However, would you mind removing the || defaults?

We have these set in the ini file as well, so it should work for us out of the box.

If not, I'll do the work to make my setup function. I appreciate you trying to not break us, but I don't want this info out in the repo anyway.

Maybe instead of having default values, we should raise if they're not set. These are required to be set, otherwise the code will simply not work.

ah.inventory = 'inventory/gce/gce.py'
return ah
end

end

class GceCommand < Thor
Expand Down Expand Up @@ -181,10 +198,10 @@ def launch()
ah.extra_vars['oo_new_inst_tags'] << GceHelper.generate_env_host_type_tag(options[:env], options[:type])

puts
puts "Creating instance(s) in GCE..."
puts 'Creating instance(s) in GCE...'
puts
puts " .---- Disregard this (ansible bug 6407) ----."
puts " V V"
puts %q[ .---- Spurious warning "It is unnecessary to use '{{' in loops" (ansible bug 6407) ----.]
puts %q[ V V]


ah.run_playbook("playbooks/gce/#{options[:type]}/launch.yml")
Expand Down Expand Up @@ -268,7 +285,7 @@ def scp_from(*ssh_ops, host)
else
cmd += " #{user}@"
end

if dest.nil?
download = File.join(Dir.pwd, 'download')
FileUtils.mkdir_p(download) unless File.exists?(download)
Expand Down
10 changes: 10 additions & 0 deletions roles/kubernetes_kubelet/files/registry-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "dockerregistry",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 8888,
"selector": {
"name": "docker-registry"
}
}

30 changes: 30 additions & 0 deletions roles/pods/files/pods/docker-registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"kind": "Pod",
"version": "v1beta1",
"desiredState": {
"manifest": {
"version": "v1beta1",
"containers": [{
"name": "docker-registry",
"image": "registry",
"volumeMounts": [{
"name": "data",
"mountPath": "/var/lib/docker-registry"
}],
"ports": [{
"containerPort": 5000,
"hostPort": 9999
}]
}],
"volumes": [{
"name": "data",
"source": {
"emptyDir": true
}
}]
}
},
"labels": {
"name": "docker-registry"
}
}