sct 0.1.13 → 0.1.14

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: 8bd1ac3662dc8475d5837a4736765063bdbbc5ed1b3471a6c26ab8d007be85b6
4
- data.tar.gz: 3ed935254cd71bbe3b505046ef2243c1a3a4df4b23826a7fcfbe2d64c28da0fe
3
+ metadata.gz: 2377fe5a5cfd760e9a8ed93321849ac8207588721325ce48aa2d6bd8cf8f631e
4
+ data.tar.gz: 5952de0af59fb21add421797a785584763a27286f94feb8303aadfaa3e57cc91
5
5
  SHA512:
6
- metadata.gz: 4111e359e86ebcf1a8df22534acc55f0ad6ebed32540c1068f4b094718156e49a1b2083fd9c1391e04eca44763c2dfa0f847fee4f48d4ffe6eb052f1a6640364
7
- data.tar.gz: 0ab52f35394748422cad25e3745daf770846a82add1a0601cbbf9b8641b04694db78651d075ef10c1ebaa396167998650d41b1728e80cb98f320827114fb9294
6
+ metadata.gz: 85ce38ef50434f38d01560de81c688aeea4c5ae9362c9f7b6eab2ea77acb8381906a2adcc506d8f4e2f812ec4d191ae8fc6d80e6c49e1ebcf4ac9de0a711ccf2
7
+ data.tar.gz: 1678c667cf147b5c406819bfe5b2aa00624de2f08a42776d49725cc8416457e89bf3c96f06f8b25cdd02182e12aab191cb42ca83c166f8cdffb2b809d2d44e5e
data/.DS_Store CHANGED
File without changes
data/.rspec CHANGED
File without changes
File without changes
File without changes
data/Gemfile CHANGED
File without changes
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -5,54 +5,113 @@ module Sct
5
5
  class ClusterCommand
6
6
 
7
7
  IS_PUBLIC_COMMAND = true
8
- SYNTAX = 'sct cluster up | sct cluster down | sct cluster update-config'
9
- SUMMARY = 'Starts/stops or updates the config of the minikube cluster'
10
- EXAMPLE = 'sct cluster up | sct cluster down | sct cluster update-config'
11
- EXAMPLE_DESCRIPTION = 'Starts/stops or updates the config of the minikube cluster'
12
- DESCRIPTION = "Sct cluster allows you to start, stop or update the config of the Spend Cloud minikube cluster"
8
+ SYNTAX = 'sct cluster up | sct cluster down | sct cluster reset | sct cluster update-config'
9
+ SUMMARY = 'Starts/stops/resets or updates the config of the minikube cluster.'
10
+ EXAMPLE = 'sct cluster up | sct cluster down | sct cluster reset | sct cluster update-config'
11
+ EXAMPLE_DESCRIPTION = 'Starts/stops/resets or updates the config of the minikube cluster.'
12
+ DESCRIPTION = "sct cluster allows you to start, stop, reset or update the config of the Spend Cloud minikube cluster."
13
13
 
14
14
  OPTIONS = []
15
15
 
16
16
  def execute(args, options)
17
17
  return puts "SCT has not been initialized. Run 'sct init' first.".red unless Sct::Config.exists
18
18
 
19
- if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
20
- minikube = "minikube.exe"
21
- else
22
- minikube = "minikube"
23
- end
24
-
25
19
  case args[0]
26
20
  when "up"
27
- system("#{minikube} start")
28
- system("#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'")
29
- update_config
30
- system("kubectl config use-context minikube")
31
- system("kubectl delete pod -n kube-system $(kubectl get pods -n kube-system | grep registry-creds | awk '{print $1}')")
32
- system("sudo sct hostfile")
33
- puts "\n✔️ You can now visit your environment at 👉 https://spend-cloud.spend.cloud.local 👌"
21
+ up
34
22
  when "down"
35
- system("#{minikube} stop")
23
+ down
36
24
  when "update-config"
37
25
  update_config
26
+ when "reset"
27
+ reset
38
28
  else
39
29
  puts "Unknown or missing argument. Please run 'sct cluster up','sct cluster down' or 'sct cluster update-config'".red
40
30
  end
41
31
  end
42
32
 
33
+ def up
34
+ start
35
+ system "kubectl delete pod -n kube-system $(kubectl get pods -n kube-system | grep registry-creds | awk '{print $1}')"
36
+ system "kubectl rollout status -n kube-system deployment/registry-creds"
37
+ post_start
38
+ end
39
+
40
+ def down
41
+ system "#{minikube} stop"
42
+ end
43
+
43
44
  def update_config
44
- return puts "Skipping minikube config (only needed for Windows)".yellow unless Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
45
+ if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
46
+ windows_home_path = Sct::Helpers.windowsHomePath
47
+ kube_file_path = windows_home_path+"/.kube/config"
48
+
49
+ if !File.exists?(kube_file_path)
50
+ return puts "#{kube_file_path} doesn't exist".red
51
+ end
45
52
 
46
- windows_home_path = Sct::Helpers.windowsHomePath
47
- kube_file_path = windows_home_path+"/.kube/config"
53
+ system("sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config")
48
54
 
49
- if !File.exists?(kube_file_path)
50
- return puts "#{kube_file_path} doesn't exist".red
55
+ puts "#{kube_file_path} copied to ~/.kube/minikube-config".green
51
56
  end
52
57
 
53
- system("sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config")
58
+ system "kubectl config use-context minikube"
59
+ end
60
+
61
+ def reset
62
+ system "#{minikube} delete"
63
+ start
64
+ system "kubectl create secret generic gcloud-credentials --from-file=\"$(echo ~)/.config/gcloud/application_default_credentials.json\""
65
+ system "kubectl create secret generic -n kube-system registry-creds-dpr --from-literal DOCKER_PRIVATE_REGISTRY_PASSWORD=changeme --from-literal DOCKER_PRIVATE_REGISTRY_SERVER=changeme --from-literal DOCKER_PRIVATE_REGISTRY_USER=changeme"
66
+ system "kubectl patch secret -n kube-system registry-creds-dpr -p='{\"metadata\": {\"labels\": { \"app\": \"registry-creds\", \"cloud\": \"dpr\", \"kubernetes.io/minikube-addons\": \"registry-creds\"}}}'"
67
+ system "kubectl create secret generic -n kube-system registry-creds-ecr --from-literal AWS_ACCESS_KEY_ID=changeme --from-literal AWS_SECRET_ACCESS_KEY=changeme --from-literal AWS_SESSION_TOKEN=\"\" --from-literal aws-account=changeme --from-literal aws-assume-role=changeme --from-literal aws-region=changeme"
68
+ system "kubectl patch secret -n kube-system registry-creds-ecr -p='{\"metadata\": {\"labels\": { \"app\": \"registry-creds\", \"cloud\": \"ecr\", \"kubernetes.io/minikube-addons\": \"registry-creds\"}}}'"
69
+ system "kubectl create secret generic -n kube-system registry-creds-gcr --from-file=\"$(echo ~)/.config/gcloud/application_default_credentials.json\" --from-literal=gcrurl=\"https://eu.gcr.io\""
70
+ system "kubectl patch secret -n kube-system registry-creds-gcr -p='{\"metadata\": {\"labels\": { \"app\": \"registry-creds\", \"cloud\": \"gcr\", \"kubernetes.io/minikube-addons\": \"registry-creds\"}}}'"
71
+ system "kubectl create secret generic -n kube-system registry-creds-acr --from-literal ACR_PASSWORD=changeme --from-literal ACR_CLIENT_ID=changeme --from-literal ACR_URL=changeme"
72
+ system "kubectl patch secret -n kube-system registry-creds-acr -p='{\"metadata\": {\"labels\": { \"app\": \"registry-creds\", \"cloud\": \"acr\", \"kubernetes.io/minikube-addons\": \"registry-creds\"}}}'"
73
+ system "#{minikube} addons enable registry-creds"
74
+ system "#{minikube} addons enable ingress"
75
+ system "kubectl rollout status -n kube-system deployment/registry-creds"
76
+ system "kubectl rollout status -n kube-system deployment/nginx-ingress-controller"
77
+ wait_for_gcr_secret
78
+ system "kubectl apply -f ~/development/spend-cloud/k8s/"
79
+ post_start
80
+ end
54
81
 
55
- return puts "Windows minikube config copied to ~/.kube/minikube-config".green
82
+ def start
83
+ system "#{minikube} start --cpus=$(cat /proc/cpuinfo | grep processor | wc -l) --memory=16G"
84
+ system "#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'"
85
+ update_config
86
+ end
87
+
88
+ def post_start
89
+ system "kubectl rollout status deployment/spend-cloud-api"
90
+ system "sudo sct hostfile"
91
+ puts "\n✔️ You can visit your environment at 👉 https://spend-cloud.spend.cloud.local 👌 (might still take a few minutes)"
92
+ end
93
+
94
+ def wait_for_gcr_secret
95
+ puts "Waiting for Google Cloud Registry secret to become available...".yellow
96
+
97
+ while true
98
+ secrets = `kubectl get secrets`
99
+
100
+ if secrets.include? "gcr-secret"
101
+ puts "Google Cloud Registry secret is now available.".green
102
+ break
103
+ else
104
+ sleep 1
105
+ end
106
+ end
107
+ end
108
+
109
+ def minikube
110
+ if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
111
+ return "minikube.exe"
112
+ else
113
+ return "minikube"
114
+ end
56
115
  end
57
116
 
58
117
  implements CommandInterface
File without changes
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reshad Farid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: class_interface