uffizzi-cli 2.3.4 → 2.4.0

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
  SHA256:
3
- metadata.gz: 9881a62c56ed3ef3171721ef7e6f6374482f4068f268aa1f5a0b5864b6c8cec6
4
- data.tar.gz: cc60bbc447f3f30759a74fa7fa916aab28134b9e05d97ecd1f0a69c8ba042cae
3
+ metadata.gz: 1267ece15e161c558b60dd16dc1d6562417f1555eefb3fcf2f65cb2f32223295
4
+ data.tar.gz: 4d5a80140a3436822c56a5cb1f3930ccb18082d93359c5cda3cf2343348cc282
5
5
  SHA512:
6
- metadata.gz: 03c1494d690dd6bf8ef266cb815d08260bb0c609a22215f9e3ba8e9618a9598345c7161b6bdee18bafb5a45927f17c821239b069c50781a52420ab1746564a21
7
- data.tar.gz: 847557bd05438144d2d964308a15dbc270105eb97c19c1971402e7b83c1ac82b90e611609ae0777ebd20f7e778e57ba0b4c1189db5c64c5a9fb58eefc3d6064e
6
+ metadata.gz: f2092483072296f1fd039d8acf049b53f4ef2b799c09063eb7ce0251f747837865c09f5d222f5e011c65826991fc4eb35cc7cd85d08dfaa8b3418c7270a6bb06
7
+ data.tar.gz: 20a062cf54e7f5b9a04d618e0066cacbf837254bb5f5c6abc7e26a0ed959a814012cceb8af3bfbefb675ad2d431fee6fa0c250229e57a4480a838929b9ff2fa1
@@ -96,9 +96,9 @@ module Uffizzi
96
96
  when 'disconnect'
97
97
  ClusterDisconnectService.handle(options)
98
98
  when 'sleep'
99
- handle_sleep_command(project_slug, command_args)
99
+ handle_sleep_command(command_args)
100
100
  when 'wake'
101
- handle_wake_command(project_slug, command_args)
101
+ handle_wake_command(command_args)
102
102
  end
103
103
  end
104
104
 
@@ -141,7 +141,7 @@ module Uffizzi
141
141
 
142
142
  spinner = TTY::Spinner.new("[:spinner] Creating cluster #{cluster_name}...", format: :dots)
143
143
  spinner.auto_spin
144
- cluster_data = ClusterService.wait_cluster_deploy(project_slug, cluster_name, oidc_token)
144
+ cluster_data = ClusterService.wait_cluster_deploy(cluster_name, cluster_api_connection_params)
145
145
 
146
146
  if ClusterService.failed?(cluster_data[:state])
147
147
  spinner.error
@@ -220,41 +220,27 @@ module Uffizzi
220
220
  return if options[:quiet]
221
221
 
222
222
  Uffizzi.ui.say("Kubeconfig was updated by the path: #{kubeconfig_path}")
223
+
224
+ synced_cluster_data = ClusterService.sync_cluster_data(command_args[:cluster_name], server: server, project_slug: project_slug)
225
+ cluster_state = synced_cluster_data[:state]
226
+ return if ClusterService.deployed?(cluster_state)
227
+
228
+ Uffizzi.ui.say(ClusterService.cluster_status_text_map[cluster_state])
229
+ handle_scale_up_cluster(cluster_name, cluster_api_connection_params) if ClusterService.scaled_down?(cluster_state)
223
230
  end
224
231
 
225
- def handle_sleep_command(project_slug, command_args)
232
+ def handle_sleep_command(command_args)
226
233
  cluster_name = command_args[:cluster_name] || ConfigFile.read_option(:current_cluster)&.fetch(:name)
227
234
  return handle_missing_cluster_name_error if cluster_name.nil?
228
235
 
229
- response = scale_down_cluster(ConfigFile.read_option(:server), project_slug, cluster_name)
230
- return ResponseHelper.handle_failed_response(response) unless ResponseHelper.ok?(response)
231
-
232
- spinner = TTY::Spinner.new("[:spinner] Scaling down cluster #{cluster_name}...", format: :dots)
233
- spinner.auto_spin
234
- ClusterService.wait_cluster_scale_down(project_slug, cluster_name)
235
-
236
- spinner.success
237
- Uffizzi.ui.say("Cluster #{cluster_name} was successfully scaled down")
236
+ handle_scale_down_cluster(cluster_name, cluster_api_connection_params)
238
237
  end
239
238
 
240
- def handle_wake_command(project_slug, command_args)
239
+ def handle_wake_command(command_args)
241
240
  cluster_name = command_args[:cluster_name] || ConfigFile.read_option(:current_cluster)&.fetch(:name)
242
241
  return handle_missing_cluster_name_error if cluster_name.nil?
243
242
 
244
- response = scale_up_cluster(ConfigFile.read_option(:server), project_slug, cluster_name)
245
- return ResponseHelper.handle_failed_response(response) unless ResponseHelper.ok?(response)
246
-
247
- spinner = TTY::Spinner.new("[:spinner] Waking up cluster #{cluster_name}...", format: :dots)
248
- spinner.auto_spin
249
- cluster_data = ClusterService.wait_cluster_scale_up(project_slug, cluster_name)
250
-
251
- if ClusterService.failed_scaling_up?(cluster_data[:state])
252
- spinner.error
253
- Uffizzi.ui.say_error_and_exit("Failed to wake up cluster #{cluster_name}.")
254
- end
255
-
256
- spinner.success
257
- Uffizzi.ui.say("Cluster #{cluster_name} was successfully scaled up")
243
+ handle_scale_up_cluster(cluster_name, cluster_api_connection_params)
258
244
  end
259
245
 
260
246
  def say_error_update_kubeconfig(cluster_data)
@@ -355,6 +341,35 @@ module Uffizzi
355
341
  Psych.safe_load(Base64.decode64(kubeconfig))
356
342
  end
357
343
 
344
+ def handle_scale_up_cluster(cluster_name, cluster_api_connection_params)
345
+ response = scale_up_cluster(cluster_api_connection_params[:server], project_slug, cluster_name)
346
+ return ResponseHelper.handle_failed_response(response) unless ResponseHelper.ok?(response)
347
+
348
+ spinner = TTY::Spinner.new("[:spinner] Waking up cluster #{cluster_name}...", format: :dots)
349
+ spinner.auto_spin
350
+ cluster_data = ClusterService.wait_cluster_scale_up(cluster_name, cluster_api_connection_params)
351
+
352
+ if ClusterService.failed_scaling_up?(cluster_data[:state])
353
+ spinner.error
354
+ Uffizzi.ui.say_error_and_exit("Failed to scale up cluster #{cluster_name}.")
355
+ end
356
+
357
+ spinner.success
358
+ Uffizzi.ui.say("Cluster #{cluster_name} was successfully scaled up")
359
+ end
360
+
361
+ def handle_scale_down_cluster(cluster_name, cluster_api_connection_params)
362
+ response = scale_down_cluster(cluster_api_connection_params[:server], project_slug, cluster_name)
363
+ return ResponseHelper.handle_failed_response(response) unless ResponseHelper.ok?(response)
364
+
365
+ spinner = TTY::Spinner.new("[:spinner] Scaling down cluster #{cluster_name}...", format: :dots)
366
+ spinner.auto_spin
367
+ ClusterService.wait_cluster_scale_down(cluster_name, cluster_api_connection_params)
368
+
369
+ spinner.success
370
+ Uffizzi.ui.say("Cluster #{cluster_name} was successfully scaled down")
371
+ end
372
+
358
373
  def handle_missing_cluster_name_error
359
374
  Uffizzi.ui.say("No kubeconfig found at #{KubeconfigService.default_path}")
360
375
  Uffizzi.ui.say('Please update the current context or provide a cluster name.')
@@ -116,7 +116,7 @@ module Uffizzi
116
116
 
117
117
  def wait_cluster_creation(cluster_name)
118
118
  Uffizzi.ui.say('Checking the cluster status...')
119
- cluster_data = ClusterService.wait_cluster_deploy(project_slug, cluster_name, oidc_token)
119
+ cluster_data = ClusterService.wait_cluster_deploy(cluster_name, cluster_api_connection_params)
120
120
 
121
121
  if ClusterService.failed?(cluster_data[:state])
122
122
  Uffizzi.ui.say_error_and_exit("Cluster with name: #{cluster_name} failed to be created.")
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uffizzi'
4
+ require 'uffizzi/config_file'
5
+
6
+ module Uffizzi
7
+ class Cli::Status < Thor
8
+ include ApiClient
9
+
10
+ default_task :describe
11
+
12
+ desc 'describe', 'Show account status'
13
+ def describe
14
+ Uffizzi::AuthHelper.check_login
15
+
16
+ account_name = ConfigFile.read_option(:account)[:name]
17
+ response = fetch_account(ConfigFile.read_option(:server), account_name)
18
+
19
+ if ResponseHelper.ok?(response)
20
+ handle_describe_success_response(response)
21
+ elsif ResponseHelper.not_found?(response)
22
+ Uffizzi.ui.say("Account with name #{account_name} does not exist")
23
+ else
24
+ ResponseHelper.handle_failed_response(response)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def handle_describe_success_response(response)
31
+ account = response[:body][:account]
32
+ account_rendered_params = {
33
+ account: account[:name],
34
+ plan: "Uffizzi #{account[:product_name]}",
35
+ api: account[:api_url],
36
+ controller: account[:vclusters_controller_url],
37
+ }
38
+
39
+ Uffizzi.ui.output_format = Uffizzi::UI::Shell::PRETTY_LIST
40
+ Uffizzi.ui.say(account_rendered_params)
41
+ end
42
+ end
43
+ end
data/lib/uffizzi/cli.rb CHANGED
@@ -83,6 +83,10 @@ module Uffizzi
83
83
  require_relative 'cli/uninstall'
84
84
  subcommand 'uninstall', Cli::Uninstall
85
85
 
86
+ desc 'status', 'status'
87
+ require_relative 'cli/status'
88
+ subcommand 'status', Cli::Status
89
+
86
90
  map preview: :compose
87
91
 
88
92
  class << self
@@ -276,6 +276,13 @@ module ApiClient
276
276
  build_response(response)
277
277
  end
278
278
 
279
+ def sync_cluster(server, project_slug, cluster_name)
280
+ uri = sync_cluster_uri(server, project_slug, cluster_name)
281
+ response = http_client.make_put_request(uri)
282
+
283
+ build_response(response)
284
+ end
285
+
279
286
  def create_access_token(server, session_id)
280
287
  uri = access_tokens_url(server)
281
288
 
@@ -124,6 +124,10 @@ module ApiRoutes
124
124
  "#{server}/api/cli/v1/projects/#{project_slug}/clusters/#{cluster_name}/scale_down"
125
125
  end
126
126
 
127
+ def sync_cluster_uri(server, project_slug, cluster_name)
128
+ "#{server}/api/cli/v1/projects/#{project_slug}/clusters/#{cluster_name}/sync"
129
+ end
130
+
127
131
  def access_token_url(server, code)
128
132
  "#{server}/api/cli/v1/access_tokens/#{code}"
129
133
  end
@@ -8,6 +8,7 @@ class ClusterService
8
8
  CLUSTER_STATE_DEPLOYING = 'deploying'
9
9
  CLUSTER_STATE_DEPLOYED = 'deployed'
10
10
  CLUSTER_STATE_SCALING_DOWN = 'scaling_down'
11
+ CLUSTER_STATE_SCALED_DOWN = 'scaled_down'
11
12
  CLUSTER_STATE_SCALING_UP = 'scaling_up'
12
13
  CLUSTER_FAILED_SCALING_UP = 'failed_scaling_up'
13
14
  CLUSTER_STATE_FAILED_DEPLOY_NAMESPACE = 'failed_deploy_namespace'
@@ -38,53 +39,35 @@ class ClusterService
38
39
  cluster_state === CLUSTER_STATE_SCALING_DOWN
39
40
  end
40
41
 
42
+ def scaled_down?(cluster_state)
43
+ cluster_state === CLUSTER_STATE_SCALED_DOWN
44
+ end
45
+
41
46
  def failed_scaling_up?(cluster_state)
42
47
  cluster_state === CLUSTER_FAILED_SCALING_UP
43
48
  end
44
49
 
45
- def wait_cluster_deploy(project_slug, cluster_name, oidc_token)
50
+ def wait_cluster_deploy(cluster_name, cluster_api_connection_params)
46
51
  loop do
47
- params = {
48
- cluster_name: cluster_name,
49
- oidc_token: oidc_token,
50
- }
51
- response = get_cluster(Uffizzi::ConfigFile.read_option(:server), project_slug, params)
52
- return Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.ok?(response)
53
-
54
- cluster_data = response.dig(:body, :cluster)
55
-
52
+ cluster_data = fetch_cluster_data(cluster_name, **cluster_api_connection_params)
56
53
  return cluster_data unless deploying?(cluster_data[:state])
57
54
 
58
55
  sleep(5)
59
56
  end
60
57
  end
61
58
 
62
- def wait_cluster_scale_up(project_slug, cluster_name)
59
+ def wait_cluster_scale_up(cluster_name, cluster_api_connection_params)
63
60
  loop do
64
- params = {
65
- cluster_name: cluster_name,
66
- }
67
- response = get_cluster(Uffizzi::ConfigFile.read_option(:server), project_slug, params)
68
- return Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.ok?(response)
69
-
70
- cluster_data = response.dig(:body, :cluster)
71
-
61
+ cluster_data = fetch_cluster_data(cluster_name, **cluster_api_connection_params)
72
62
  return cluster_data unless scaling_up?(cluster_data[:state])
73
63
 
74
64
  sleep(5)
75
65
  end
76
66
  end
77
67
 
78
- def wait_cluster_scale_down(project_slug, cluster_name)
68
+ def wait_cluster_scale_down(cluster_name, cluster_api_connection_params)
79
69
  loop do
80
- params = {
81
- cluster_name: cluster_name,
82
- }
83
- response = get_cluster(Uffizzi::ConfigFile.read_option(:server), project_slug, params)
84
- return Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.ok?(response)
85
-
86
- cluster_data = response.dig(:body, :cluster)
87
-
70
+ cluster_data = fetch_cluster_data(cluster_name, **cluster_api_connection_params)
88
71
  return unless scaling_down?(cluster_data[:state])
89
72
 
90
73
  sleep(3)
@@ -120,6 +103,16 @@ class ClusterService
120
103
  end
121
104
  end
122
105
 
106
+ def sync_cluster_data(cluster_name, server:, project_slug:)
107
+ response = sync_cluster(server, project_slug, cluster_name)
108
+
109
+ if Uffizzi::ResponseHelper.ok?(response)
110
+ response.dig(:body, :cluster)
111
+ else
112
+ Uffizzi::ResponseHelper.handle_failed_response(response)
113
+ end
114
+ end
115
+
123
116
  def build_render_data(cluster_data)
124
117
  {
125
118
  name: cluster_data[:name],
@@ -128,5 +121,16 @@ class ClusterService
128
121
  host: cluster_data[:host],
129
122
  }
130
123
  end
124
+
125
+ def cluster_status_text_map
126
+ {
127
+ CLUSTER_STATE_SCALING_UP => 'The cluster is scaling up',
128
+ CLUSTER_STATE_SCALED_DOWN => 'The cluster is scaled down',
129
+ CLUSTER_STATE_SCALING_DOWN => 'The cluster is scaling down',
130
+ CLUSTER_FAILED_SCALING_UP => 'The cluster failed scaling up',
131
+ CLUSTER_STATE_FAILED_DEPLOY_NAMESPACE => 'The cluster failed',
132
+ CLUSTER_STATE_FAILED => 'The cluster failed',
133
+ }
134
+ end
131
135
  end
132
136
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uffizzi
4
- VERSION = '2.3.4'
4
+ VERSION = '2.4.0'
5
5
  end
@@ -1,3 +1,4 @@
1
+ $ uffizzi cluster update-kubeconfig -h
1
2
  uffizzi-cluster-update-kubeconfig - update a kubeconfig
2
3
  ================================================================
3
4
 
@@ -5,7 +6,8 @@ uffizzi-cluster-update-kubeconfig - update a kubeconfig
5
6
  uffizzi cluster update-kubeconfig [CLUSTER_NAME]
6
7
 
7
8
  ## DESCRIPTION
8
- Update your kubeconfig file.
9
+ Update your kubeconfig file such that you can use kubectl to connect
10
+ to a Uffizzi cluster.
9
11
 
10
12
  This command can fail for the following reasons:
11
13
  - Your kubeconfig file out of specification
@@ -13,6 +15,11 @@ uffizzi-cluster-update-kubeconfig - update a kubeconfig
13
15
  For more information on Uffizzi clusters, see:
14
16
  https://docs.uffizzi.com/references/cli/
15
17
 
18
+ ## POSITIONAL ARGUMENTS
19
+ CLUSTER_NAME
20
+ The name of the cluster for which to create a kubeconfig entry.
21
+ This cluster must exist in your account.
22
+
16
23
  ## FLAGS
17
24
  --kubeconfig="/path/to/your/kubeconfig"
18
25
  Path to kubeconfig file you want to update
@@ -24,6 +31,6 @@ uffizzi-cluster-update-kubeconfig - update a kubeconfig
24
31
  Quiet mode
25
32
 
26
33
  ## EXAMPLES
27
- To update kubeconfig file, run:
34
+ To update kubeconfig file for cluster 'my-cluster', run:
28
35
 
29
- $ uffizzi cluster update-kubeconfig --kubeconfig="/file/path/to/kubeconfig"
36
+ $ uffizzi cluster update-kubeconfig my-cluster --kubeconfig="/file/path/to/kubeconfig"
@@ -1,50 +1,52 @@
1
- $ uffizzi install help
2
- uffizzi-install - install the uffizzi platform
1
+ $ uffizzi -h
2
+ uffizzi - manage Uffizzi resources
3
3
  ================================================================
4
4
 
5
5
  ## SYNOPSIS
6
- uffizzi install [HOSTNAME]
6
+ uffizzi GROUP | COMMAND
7
7
 
8
8
  ## DESCRIPTION
9
- Install the Uffizzi platform on a host cluster. By default, this command uses your
10
- kubeconfig current context as the host.
9
+ The uffizzi CLI manages authentication, configuration, and
10
+ interaction with Uffizzi APIs.
11
11
 
12
- The output of this command is an IP address or hostname where your instance of
13
- the Uffizzi controller service is available. Uffizzi expects this service to be publicly
14
- available at the specified HOSTNAME. Before you can create Uffizzi environments
15
- on your installation, be sure to configure your DNS to point HOSTNAME to the IP
16
- or hostname output by this command.
12
+ For more information on the uffizzi CLI, see:
13
+ https://docs.uffizzi.com/references/cli/
17
14
 
18
- If you're looking for an air-gapped or local installation of Uffizzi, please contact
19
- sales@uffizzi.com or try the open-source version (docs.uffizzi.com/open-source).
15
+ ## GROUP
16
+ GROUP is one of the following:
17
+ cluster
18
+ Manage virtual clusters
20
19
 
21
- EMAIL is a business email, required for letsencrypt cert authority.
20
+ config
21
+ Configure the uffizzi CLI
22
22
 
23
- For more information on the Uffizzi installation process, see:
24
- https://docs.uffizzi.com/cli/commands/install
23
+ connect
24
+ Grant a Uffizzi user account access to external services
25
25
 
26
- ## FLAGS
26
+ compose
27
+ Manage Uffizzi compose environments (previews) and view logs
27
28
 
28
- --email
29
- A business email required for letsencrypt
29
+ dev
30
+ Creates a Uffizzi cluster preconfigured for development workflows
30
31
 
31
- --context
32
- The name of the kubeconfig context to use
32
+ install
33
+ Install the Uffizzi platform data plane on a host cluster.
33
34
 
34
- --namespace
35
- The namespace where Uffizzi platform will be installed
35
+ project
36
+ Manage Uffizzi project resources including compose files for
37
+ specifying compose environment (preview) configurations and secrets
36
38
 
37
- --help
38
- Display this help page and exit
39
+ ## COMMAND
40
+ COMMAND is one of the following:
39
41
 
40
- ## EXAMPLES
42
+ help
43
+ Show uffizzi documentation
41
44
 
42
- To install Uffizzi using the current context at hostname
43
- 'uffizzi.example.com', run:
45
+ login
46
+ Log in to a Uffizzi user account
44
47
 
45
- $ uffizzi install uffizzi.example.com --email="jdoe@example.com"
48
+ logout
49
+ Log out of a Uffizzi user account
46
50
 
47
- To install Uffizzi using context 'foo' and namespace 'bar', run:
48
-
49
- $ uffizzi install uffizzi.example.com --email="jdoe@example.com" \
50
- --context='foo' --namespace='bar'
51
+ version
52
+ Print version information for uffizzi CLI
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-11-28 00:00:00.000000000 Z
12
+ date: 2023-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -435,6 +435,7 @@ files:
435
435
  - lib/uffizzi/cli/project.rb
436
436
  - lib/uffizzi/cli/project/compose.rb
437
437
  - lib/uffizzi/cli/project/secret.rb
438
+ - lib/uffizzi/cli/status.rb
438
439
  - lib/uffizzi/cli/uninstall.rb
439
440
  - lib/uffizzi/clients/api/api_client.rb
440
441
  - lib/uffizzi/clients/api/api_routes.rb