seira 0.4.10 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d13e90be6c49b6c588feb4e4f5ebd824eced2c816e889ee6b1a4902624a66493
4
- data.tar.gz: 3681880d3d4d0e4e172c1951b177469e1ebba7328d32d3576633d8d4142c8fc4
3
+ metadata.gz: 75b53632541063c8bd33733ac62c7a668191b47f069eff4e63e6380459c9869e
4
+ data.tar.gz: b1bce085818c5f3686009026eafbb8093def1508de90ab632e928fbde3ca3e10
5
5
  SHA512:
6
- metadata.gz: 29da919be3b42250f0e6e7bc804570bfdef3700de147cffe2a4bed370b11ea1599ea1270b402e7c9314baaf9ecab4ffe694999fa73bdc5fd6e5efc2d5d2c0a21
7
- data.tar.gz: b746c04b397f57f08ace72f133b4d9638d5a053037672ea518193c4929548170c22cd45bf6eee089c19bd8a007221c991c63bf68100044dab78e43c59da5a55a
6
+ metadata.gz: 2cbf59bce9f817597cf68954e0962ad1fbe403521016bc458da371ff464c2995f6294d295b74eb38d8b49bf11088a168818f205300443ab21e8012a5835ac132
7
+ data.tar.gz: f3eff8d111e66c49b51ce6beeab4d4c3d2acbc51bf1b95863e19e1ec774bf030a8c2f6971bea00bc97aaaffc8f0a52097ef0a15e484982cef325c18711d6a440
data/README.md CHANGED
@@ -48,27 +48,30 @@ A configuration file is expected at `.seira.yml` relative path. Below is an exam
48
48
  ```
49
49
  seira:
50
50
  organization_id: "11111"
51
- default_zone: "us-central1-a"
52
51
  clusters:
53
52
  internal:
54
53
  project: org-internal
55
54
  cluster: gke_org-internal_us-central1-a_internal
55
+ region: us-central1
56
56
  zone: us-central1-b
57
57
  aliases:
58
58
  - "i"
59
59
  staging:
60
60
  project: org-staging
61
61
  cluster: gke_org-staging_us-central1-a_staging
62
+ region: us-central1
62
63
  aliases:
63
64
  - "s"
64
65
  demo:
65
66
  project: org-demo
66
67
  cluster: gke_org-demo_us-central1-a_demo
68
+ region: us-central1
67
69
  aliases:
68
70
  - "d"
69
71
  production:
70
72
  project: org-production
71
73
  cluster: gke_org-production_us-central1-a_production
74
+ region: us-central1
72
75
  aliases:
73
76
  - "p"
74
77
  applications:
@@ -80,6 +83,10 @@ seira:
80
83
 
81
84
  This specification is read in and used to determine what `gcloud` context to use and what `kubectl` cluster to use when operating commands. For example, `seira internal` will connect to `org-internal` gcloud configuration and `gke_org-internal_us-central1-a_internal` kubectl cluster. For shorthand, `seira i` shorthand is specified as an alias.
82
85
 
86
+ ### Regions and Zones
87
+
88
+ All clusters should have a `region` option specified. For zonal clusters (clusters that are NOT regional) should also specify their `zone`.
89
+
83
90
  ### Manifest Files
84
91
 
85
92
  Seira expects your Kubernetes manifests to exist in the "kubernetes/cluster-name/app-name" directory. When a deploy is run on `foo` app in `staging` cluster, it looks to `kubernetes/staging/foo` directory for the manifest files.
data/lib/seira.rb CHANGED
@@ -136,7 +136,8 @@ module Seira
136
136
  cluster: cluster,
137
137
  project: project,
138
138
  settings: settings,
139
- default_zone: settings.default_zone,
139
+ region: cluster['region'],
140
+ zone: cluster['zone'],
140
141
  app: app,
141
142
  action: action,
142
143
  args: args
data/lib/seira/app.rb CHANGED
@@ -80,6 +80,11 @@ module Seira
80
80
  revision = nil
81
81
  deployment = :all
82
82
 
83
+ warn_env = context[:settings].expected_environment_variable_during_deploys
84
+ if warn_env && ENV[warn_env].nil?
85
+ exit(1) unless HighLine.agree("WARNING: Expected '#{warn_env}' to be present, but is not. This might mean your are running a deploy in an environment that is not safe. Are you sure you want to continue? This command will apply your *local* kubernetes configs. If you continue, make sure you have the latest master changes and valid local YAML.")
86
+ end
87
+
83
88
  args.each do |arg|
84
89
  if arg == '--async'
85
90
  async = true
@@ -204,30 +204,8 @@ module Seira
204
204
 
205
205
  def write_pgbouncer_yaml
206
206
  # TODO: Clean this up by moving into a proper templated yaml file
207
- # TODO: Fix warning from cloudsql-proxy. We use context[:default_zone] for the DB Instance name
208
- # which causes this error: got region "us-central1-c", want "us-central1".
209
207
  pgbouncer_yaml = <<-FOO
210
208
  ---
211
- apiVersion: v1
212
- kind: ConfigMap
213
- metadata:
214
- name: #{pgbouncer_configs_name}
215
- namespace: #{app}
216
- data:
217
- DB_HOST: "127.0.0.1"
218
- DB_PORT: "5432"
219
- LISTEN_PORT: "6432"
220
- LISTEN_ADDRESS: "*"
221
- TCP_KEEPALIVE: "1"
222
- TCP_KEEPCNT: "5"
223
- TCP_KEEPIDLE: "300" # see: https://git.io/vi0Aj
224
- TCP_KEEPINTVL: "300"
225
- LOG_DISCONNECTIONS: "0" # spammy, not needed
226
- MAX_CLIENT_CONN: "500"
227
- MAX_DB_CONNECTIONS: "90"
228
- DEFAULT_POOL_SIZE: "90"
229
- POOL_MODE: "transaction"
230
- ---
231
209
  apiVersion: extensions/v1beta1
232
210
  kind: Deployment
233
211
  metadata:
@@ -239,7 +217,6 @@ metadata:
239
217
  database: #{name}
240
218
  spec:
241
219
  replicas: 2
242
- minReadySeconds: 20
243
220
  strategy:
244
221
  type: RollingUpdate
245
222
  rollingUpdate:
@@ -268,6 +245,34 @@ spec:
268
245
  value: "6432"
269
246
  - name: "PGDATABASE"
270
247
  value: "#{@database_name || default_database_name}"
248
+ - name: "DB_HOST"
249
+ value: "127.0.0.1" # Exposed by cloudsql proxy
250
+ - name: "DB_PORT"
251
+ value: "5432"
252
+ - name: "LISTEN_PORT"
253
+ value: "6432"
254
+ - name: "LISTEN_ADDRESS"
255
+ value: "*"
256
+ - name: "TCP_KEEPALIVE"
257
+ value: "1"
258
+ - name: "TCP_KEEPCNT"
259
+ value: "5"
260
+ - name: "TCP_KEEPIDLE"
261
+ value: "300" # see: https://git.io/vi0Aj
262
+ - name: "TCP_KEEPINTVL"
263
+ value: "300"
264
+ - name: "LOG_DISCONNECTIONS"
265
+ value: "0" # spammy, not needed
266
+ - name: "MAX_CLIENT_CONN"
267
+ value: "1000"
268
+ - name: "MIN_POOL_SIZE"
269
+ value: "20" # This and DEFAULT should be roughly cpu cores * 2. Don't set too high.
270
+ - name: "DEFAULT_POOL_SIZE"
271
+ value: "20"
272
+ - name: "MAX_DB_CONNECTIONS"
273
+ value: "20"
274
+ - name: "POOL_MODE"
275
+ value: "transaction"
271
276
  readinessProbe:
272
277
  exec:
273
278
  command: ["psql", "-c", "SELECT 1;"]
@@ -287,7 +292,7 @@ spec:
287
292
  command:
288
293
  - /cloud_sql_proxy
289
294
  - --dir=/cloudsql
290
- - -instances=#{context[:project]}:#{context[:default_zone]}:#{name}=tcp:5432
295
+ - -instances=#{context[:project]}:#{context[:region]}:#{name}=tcp:5432
291
296
  - -credential_file=/secrets/cloudsql/credentials.json
292
297
  ports:
293
298
  - containerPort: 5432
data/lib/seira/random.rb CHANGED
@@ -11,10 +11,18 @@ module Seira
11
11
  name = "#{adjective}-#{animal}"
12
12
  attempts += 1
13
13
  return name unless existing.include? name
14
+ return name unless unallowed_name?(name)
14
15
  fail "Too many failed unique name attempts" if attempts > MAX_UNIQUE_NAME_ATTEMPTS
15
16
  end
16
17
  end
17
18
 
19
+ def self.unallowed_name?(name)
20
+ # Robin always keeps his cool
21
+ return true if name == "exasperated-robin"
22
+
23
+ false
24
+ end
25
+
18
26
  # List sourced from https://www.mobap.edu/wp-content/uploads/2013/01/list_of_adjectives.pdf
19
27
  def self.adjective
20
28
  adjectives_lis_file = File.join(File.expand_path('../..', File.dirname(__FILE__)), 'resources', 'adjectives.txt')
@@ -20,10 +20,6 @@ module Seira
20
20
  settings['seira']['organization_id']
21
21
  end
22
22
 
23
- def default_zone
24
- settings['seira']['default_zone']
25
- end
26
-
27
23
  def applications
28
24
  settings['seira']['applications'].map { |app| app['name'] }
29
25
  end
@@ -60,6 +56,10 @@ module Seira
60
56
  settings['seira']['clusters'][cluster]['project']
61
57
  end
62
58
 
59
+ def expected_environment_variable_during_deploys
60
+ settings['seira']['expected_environment_variable_during_deploys']
61
+ end
62
+
63
63
  private
64
64
 
65
65
  def parse_settings
data/lib/seira/setup.rb CHANGED
@@ -76,13 +76,33 @@ module Seira
76
76
  system("gcloud auth login")
77
77
  end
78
78
 
79
+ # All cluster configs must specify a project and region. Region is required, even
80
+ # if cluster is zonal, for other things like databases.
79
81
  system("gcloud config set project #{cluster_metadata['project']}")
80
- system("gcloud config set compute/zone #{cluster_metadata['zone'] || settings.default_zone}")
82
+ system("gcloud config set compute/region #{cluster_metadata['region']}")
83
+
84
+ # Regional and zonal clusters have slightly different behavior. We need
85
+ # to make sure that the zone is *not* set for regional cluster, or gcloud
86
+ # will complain. And zone *needs* to be set for zonal clusters.
87
+ if cluster_metadata['zone']
88
+ system("gcloud config set compute/zone #{cluster_metadata['zone']}")
89
+ else
90
+ system("gcloud config unset compute/zone")
91
+ end
92
+
81
93
  puts "Your new gcloud setup for #{cluster_name}:"
82
94
  system("gcloud config configurations describe #{cluster_name}")
83
95
 
84
- puts "Configuring kubectl for interactions with this project's kubernetes cluster"
85
- system("gcloud container clusters get-credentials #{cluster_name} --project #{cluster_metadata['project']}")
96
+ puts "Configuring kubectl for interactions with this project's kubernetes cluster with region #{cluster_metadata['region']} and zone #{cluster_metadata['zone']}"
97
+
98
+ # For regional clusters, we use the beta --region option. For zonal clusters, we pass --zone. Regional
99
+ # clusters are in the beta feature of gcloud.
100
+ if cluster_metadata['zone']
101
+ system("gcloud container clusters get-credentials #{cluster_name} --project #{cluster_metadata['project']} --zone #{cluster_metadata['zone']}")
102
+ else
103
+ system("gcloud beta container clusters get-credentials #{cluster_name} --project #{cluster_metadata['project']} --region #{cluster_metadata['region']}")
104
+ end
105
+
86
106
  puts "Your kubectl is set up with:"
87
107
  system("kubectl config current-context")
88
108
  end
data/lib/seira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seira
2
- VERSION = "0.4.10".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-02 00:00:00.000000000 Z
11
+ date: 2018-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline