biosphere 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b933e04081d1108ed1b590179d5d619c15d132f2
4
- data.tar.gz: 438ca2745302cae2516d3ae23b14c16b870140de
3
+ metadata.gz: af41c8485d5ec0811a8bc7cbbab11204a2bf6063
4
+ data.tar.gz: c2978b2f6b0365cefcfeaee24ac8e22eb257df4f
5
5
  SHA512:
6
- metadata.gz: 822377222d2d70e70b85424284bfdb5f00ba9e7e699778298473c91c20fbf834e384a8ed4cbae94909ab98b128869e96bb368b8a49d6bbbb103992657c24d6eb
7
- data.tar.gz: ee4ace64c82f8a9eb645253d7a9f8a368dfdd5ea80ed33d2f43b8f6178b1609c2d0977df1985deddfdcc90636122466b94b3ecd0d5a15100ce49a27aa3ef2eb7
6
+ metadata.gz: eac28688a1713bb4868c218594d40f6ed4668429dd6fcdd58a7def99c9d02b89003376591d4113f2847c790c68f542c80022d77ed86b84050f8221f06f11bef9
7
+ data.tar.gz: 8af9ff67b5a1c4e64224d1011aa37d5202ec0bf6909fbbd38408b67f494d3ef3e6e11c42549eed5197fe0b2c3e64409d79b367c2cd3c9025e15bb73130ac5949
@@ -117,6 +117,20 @@ if options.src
117
117
  state.load()
118
118
  end
119
119
 
120
+ unless state.node[:deployments][""].nil?
121
+ answer = ""
122
+ while answer.empty? || (answer != "y" && answer != "n")
123
+ puts "\e[31mDeployment with an empty name, do you want to clean these out now? [y/n]\e[0m"
124
+ answer = STDIN.gets.chomp
125
+ end
126
+
127
+ if answer == "n"
128
+ puts "Remember to clean these out later, this state won't work with Kubernetes"
129
+ elsif answer == "y"
130
+ state.node[:deployments].delete("")
131
+ puts "\e[32mRemoved deployment with empty name\e[0m"
132
+ end
133
+ end
120
134
  end
121
135
 
122
136
  if ARGV[0] == "build" && options.src
@@ -7,29 +7,31 @@ class Biosphere
7
7
 
8
8
  attr_reader :export, :name, :_settings, :feature_manifests, :target_groups, :resources
9
9
  attr_accessor :state, :node
10
- def initialize(*args)
11
10
 
11
+ def initialize(parent, name, settings={})
12
12
  @parent = nil
13
13
  @name = ""
14
- if args[0].kind_of?(::Biosphere::Deployment) || args[0].kind_of?(::Biosphere::Suite)
15
- @parent = args.shift
14
+ if parent.kind_of?(::Biosphere::Deployment) || parent.kind_of?(::Biosphere::Suite)
15
+ @parent = parent
16
+ else
17
+ raise ArgumentError, "Deployment takes a parent Biosphere::Deployment or Biosphere::Suite as it's first parameter"
16
18
  end
17
- if args[0].kind_of?(String)
18
- @name = args.shift
19
+
20
+ if name.kind_of?(String) && name.length > 0
21
+ @name = name
22
+ else
23
+ raise ArgumentError, "Deployment takes the deployment name as the first parameter, or as the second parameter if no parent is defined. Name can't be empty."
19
24
  end
20
25
 
21
- settings = {}
22
26
  @_settings = {}
23
- if args[0].kind_of?(Hash)
24
- settings = args.shift
27
+ if settings.kind_of?(Hash)
28
+ @_settings = settings
29
+ elsif settings.kind_of?(::Biosphere::Settings)
25
30
  @_settings = settings
26
- elsif args[0].kind_of?(::Biosphere::Settings)
27
- @_settings = args.shift
28
31
  settings = @_settings.settings
29
32
  @feature_manifests = @_settings.feature_manifests
30
33
  end
31
34
 
32
-
33
35
  @export = {
34
36
  "provider" => {},
35
37
  "resource" => {},
@@ -41,10 +43,14 @@ class Biosphere
41
43
 
42
44
  if @parent.is_a?(::Biosphere::Suite)
43
45
  @parent.register(self)
46
+ @target_groups = {}
47
+
44
48
  elsif @parent
45
49
  @node = @parent.node
46
50
  @state = @parent.state
47
51
  @export = @parent.export
52
+ @target_groups = @parent.target_groups
53
+
48
54
  @parent.register(self)
49
55
 
50
56
  else
@@ -56,7 +62,6 @@ class Biosphere
56
62
  @actions = {}
57
63
  @deployments = []
58
64
  @outputs = []
59
- @target_groups = {}
60
65
 
61
66
  if @feature_manifests
62
67
  node[:feature_manifests] = @feature_manifests
@@ -31,8 +31,11 @@ class Biosphere
31
31
  @clients = []
32
32
 
33
33
  @clients << ::Kubeclient::Client.new("#{hostname}/api" , "v1", ssl_options: ssl_options)
34
+ @clients << ::Kubeclient::Client.new("#{hostname}/apis/apps/" , "v1beta1", ssl_options: ssl_options)
34
35
  @clients << ::Kubeclient::Client.new("#{hostname}/apis/extensions/" , "v1beta1", ssl_options: ssl_options)
35
36
  @clients << ::Kubeclient::Client.new("#{hostname}/apis/batch/" , "v2alpha1", ssl_options: ssl_options)
37
+ @clients << ::Kubeclient::Client.new("#{hostname}/apis/storage.k8s.io/" , "v1", ssl_options: ssl_options)
38
+ @clients << ::Kubeclient::Client.new("#{hostname}/apis/autoscaling/" , "v1", ssl_options: ssl_options)
36
39
 
37
40
  @clients.each { |c| c.discover }
38
41
  end
@@ -51,7 +54,7 @@ class Biosphere
51
54
  def get_client(resource)
52
55
  kind = resource[:kind].underscore_case
53
56
  @clients.each do |c|
54
- if c.instance_variable_get("@entities")[kind]
57
+ if c.instance_variable_get("@api_group") + c.instance_variable_get("@api_version") == resource[:apiVersion]
55
58
  return c
56
59
  end
57
60
  end
@@ -68,7 +71,6 @@ class Biosphere
68
71
  end
69
72
 
70
73
  ns_prefix = client.build_namespace_prefix(resource[:metadata][:namespace])
71
- ns_prefix = ns_prefix.empty? ? "namespaces/default/" : ns_prefix
72
74
  ret = client.rest_client[ns_prefix + resource_name].post(resource.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(client.instance_variable_get("@headers")))
73
75
  return {
74
76
  action: :post,
@@ -131,6 +133,12 @@ class Biosphere
131
133
  response = post(resource)
132
134
  puts "Created resource #{response[:resource]}"
133
135
  responses << response
136
+ rescue RestClient::NotFound => e
137
+ pp e
138
+ pp JSON.parse(e.response.body)
139
+ puts "404 when applying resources might mean one of the following:"
140
+ puts "\t * You're trying to apply a non-namespaced manifest."
141
+ puts "\t Confirm if your manifests metadata should contain a namespace field or not"
134
142
  rescue RestClient::UnprocessableEntity => e
135
143
  pp e
136
144
  pp JSON.parse(e.response.body)
@@ -1,3 +1,3 @@
1
1
  class Biosphere
2
- Version = "0.2.4"
2
+ Version = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biosphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juho Mäkinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.1.0
61
+ version: 2.4.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.1.0
68
+ version: 2.4.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hashdiff
71
71
  requirement: !ruby/object:Gem::Requirement