Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
zipofar committed Dec 29, 2023
2 parents 8deeb0c + 6cfd83d commit e64d371
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uffizzi-cli (2.4.3)
uffizzi-cli (2.4.4)
activesupport
awesome_print
faker
Expand Down
17 changes: 16 additions & 1 deletion lib/uffizzi/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'uffizzi'
require 'uffizzi/config_file'
require 'uffizzi/services/kubeconfig_service'
require 'uffizzi/services/account_service'

module Uffizzi
class Cli::Install < Thor
Expand Down Expand Up @@ -40,7 +41,12 @@ def controller(hostname)
Uffizzi.ui.say('Helm release is deployed')

controller_setting_params = build_controller_setting_params(uri, installation_options)
create_controller_settings(controller_setting_params) if existing_controller_setting.blank?

if existing_controller_setting.blank?
create_controller_settings(controller_setting_params)
set_account_installation
end

Uffizzi.ui.say('Controller settings are saved')
say_success(uri)
end
Expand Down Expand Up @@ -189,6 +195,15 @@ def fetch_controller_settings
response.dig(:body, :controller_settings)
end

def set_account_installation
params = {
installation_type: AccountService::SELF_HOSTED_CONTROLLER_INSTALLATION_TYPE,
}

response = update_account(server, account_name, params)
Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.ok?(response)
end

def update_controller_settings(controller_setting_id, params)
response = update_account_controller_settings(server, account_id, controller_setting_id, params)
Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.ok?(response)
Expand Down
10 changes: 10 additions & 0 deletions lib/uffizzi/cli/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def controller

ask_confirmation
delete_controller_settings
unset_account_installation
InstallService.helm_uninstall!(namespace)

helm_unset_repo
Expand Down Expand Up @@ -75,6 +76,15 @@ def delete_controller_settings
end
end

def unset_account_installation
params = {
installation_type: nil,
}

response = update_account(server, account_name, params)
Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.ok?(response)
end

def namespace
options[:namespace] || InstallService::DEFAULT_NAMESPACE
end
Expand Down
7 changes: 7 additions & 0 deletions lib/uffizzi/clients/api/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def fetch_account(server, account_name)
build_response(response)
end

def update_account(server, account_name, params)
uri = account_uri(server, account_name)
response = http_client.make_put_request(uri, params)

build_response(response)
end

def create_project(server, account_id, params)
uri = create_projects_uri(server, account_id)
response = http_client.make_post_request(uri, params)
Expand Down
5 changes: 5 additions & 0 deletions lib/uffizzi/services/account_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class AccountService
SELF_HOSTED_CONTROLLER_INSTALLATION_TYPE = 'self_hosted_controller'
end
2 changes: 1 addition & 1 deletion lib/uffizzi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Uffizzi
VERSION = '2.4.3'
VERSION = '2.4.4'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"account":
{
"id": 1,
"name": "test",
"projects": [
{
"id": 1,
"slug": "uffizzi-test-slug-1"
}
],
"api_url": "http://app.uffizzi.com",
"vclusters_controller_url": "http://controller.uffizzi.com",
"product_name": "Starter Plan",
"has_installation": "self_hosted_controller"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"api_url": "http://app.uffizzi.com",
"vclusters_controller_url": "http://controller.uffizzi.com",
"product_name": "Starter Plan"
"product_name": "Starter Plan",
"has_installation": null
}
}
6 changes: 6 additions & 0 deletions test/support/uffizzi_stub_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def stub_uffizzi_account_success(body, account_name)
stub_request(:get, url).to_return(status: 200, body: body.to_json)
end

def stub_update_account_success(body, account_name)
url = account_uri(Uffizzi.configuration.server, account_name)

stub_request(:put, url).to_return(status: 200, body: body.to_json)
end

def stub_uffizzi_account_projects_success(body, account_id)
url = account_projects_uri(Uffizzi.configuration.server, account_id)

Expand Down
15 changes: 10 additions & 5 deletions test/uffizzi/cli/install_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def setup
def test_install
host = 'my-host.com'
account_id = 1
account_name = 'some_account'
Uffizzi::ConfigFile.write_option(:account, { 'id' => account_id, 'name' => account_name })

@mock_shell.promise_execute(/kubectl version/, stdout: '1.23.00')
@mock_shell.promise_execute(/helm version/, stdout: '3.00')
Expand Down Expand Up @@ -55,9 +57,11 @@ def test_install
@mock_shell.promise_execute(/kubectl get certificaterequests/, stdout: cert_request_answer.to_json)
@mock_prompt.promise_question_answer('Okay to proceed?', 'y')

empty_body = json_fixture('files/uffizzi/uffizzi_account_controller_settings_empty.json')
stub_get_account_controller_settings_request(empty_body, account_id)
empty_controller_settings_body = json_fixture('files/uffizzi/uffizzi_account_controller_settings_empty.json')
account_body = json_fixture('files/uffizzi/uffizzi_account_success_with_installation.json')
stub_get_account_controller_settings_request(empty_controller_settings_body, account_id)
stub_create_account_controller_settings_request({}, account_id)
stub_update_account_success(account_body, account_name)

@install.options = command_options(email: 'admin@my-domain.com')
@install.controller(host)
Expand Down Expand Up @@ -108,9 +112,10 @@ def test_install_if_settgins_exists
@mock_prompt.promise_question_answer('Okay to proceed?', 'y')
@mock_prompt.promise_question_answer('Do you want update the controller settings?', 'y')

body = json_fixture('files/uffizzi/uffizzi_account_controller_settings.json')
stub_get_account_controller_settings_request(body, account_id)
stub_update_account_controller_settings_request(body, account_id, body[:controller_settings][0][:id])
account_controller_settings_body = json_fixture('files/uffizzi/uffizzi_account_controller_settings.json')
stub_get_account_controller_settings_request(account_controller_settings_body, account_id)
stub_update_account_controller_settings_request(account_controller_settings_body, account_id,
account_controller_settings_body[:controller_settings][0][:id])

@install.options = command_options(email: 'admin@my-domain.com')
@install.controller(host)
Expand Down
10 changes: 7 additions & 3 deletions test/uffizzi/cli/uninstall_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def setup

def test_uninstall
account_id = 1
account_name = 'some_account'
Uffizzi::ConfigFile.write_option(:account, { 'id' => account_id, 'name' => account_name })

@mock_shell.promise_execute(/kubectl version/, stdout: '1.23.00')
@mock_shell.promise_execute(/helm version/, stdout: '3.00')
Expand All @@ -25,9 +27,11 @@ def test_uninstall
@mock_shell.promise_execute(/helm uninstall/, stdout: 'Helm release is uninstalled')
@mock_prompt.promise_question_answer('Okay to proceed?', 'y')

body = json_fixture('files/uffizzi/uffizzi_account_controller_settings.json')
stub_get_account_controller_settings_request(body, account_id)
stub_delete_account_controller_settings_request(account_id, body[:controller_settings][0][:id])
account_controller_settings = json_fixture('files/uffizzi/uffizzi_account_controller_settings.json')
account_body = json_fixture('files/uffizzi/uffizzi_account_success_with_one_project.json')
stub_get_account_controller_settings_request(account_controller_settings, account_id)
stub_delete_account_controller_settings_request(account_id, account_controller_settings[:controller_settings][0][:id])
stub_update_account_success(account_body, account_name)

@uninstall.controller

Expand Down

0 comments on commit e64d371

Please sign in to comment.