Skip to content

Commit

Permalink
[430] Refactor cluster creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zipofar committed Jun 22, 2023
1 parent a07b15e commit 6aa06d8
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
class UffizziCore::Api::Cli::V1::Projects::ClusterSerializer < UffizziCore::BaseSerializer
type :cluster

attributes :name, :state, :kube_config
attributes :name, :state, :kubeconfig
end
3 changes: 1 addition & 2 deletions core/app/services/uffizzi_core/cluster_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def deploy_cluster(cluster)
return cluster.fail!
end


UffizziCore::Cluster::ManageDeployingJob.perform_in(5.seconds, cluster.id)
end

Expand All @@ -33,7 +32,7 @@ def manage_deploying(cluster, try)

if deployed_cluster.status.ready
cluster.finish_deploy
cluster.kube_config = deployed_cluster.status.kube_config
cluster.kubeconfig = deployed_cluster.status.kube_config
cluster.save!

return
Expand Down
2 changes: 1 addition & 1 deletion core/db/migrate/20230613101901_create_clusters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def change
t.string 'state'
t.string 'name'
t.text 'manifest'
t.text 'kube_config'
t.text 'kubeconfig'

t.timestamps
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class UffizziCore::Api::Cli::V1::Projects::ClustersControllerTest < ActionContro
},
}

data = json_fixture('files/controller/cluster_not_ready.json')
stubbed_create_cluster_request = stub_create_cluster_request(data)
cluster_creation_data = json_fixture('files/controller/cluster_not_ready.json')
stubbed_create_namespace_request = stub_create_namespace_request
stubbed_create_cluster_request = stub_create_cluster_request(cluster_creation_data)
cluster_show_data = json_fixture('files/controller/cluster_ready.json')
stubbed_cluster_request = stub_get_cluster_request(cluster_show_data)

differences = {
-> { UffizziCore::Cluster.count } => 1,
Expand All @@ -50,6 +52,7 @@ class UffizziCore::Api::Cli::V1::Projects::ClustersControllerTest < ActionContro
assert_response(:success)
assert_requested(stubbed_create_cluster_request)
assert_requested(stubbed_create_namespace_request)
assert_requested(stubbed_cluster_request)
end

test '#create when enabled cluster with the same name exists' do
Expand Down Expand Up @@ -85,9 +88,11 @@ class UffizziCore::Api::Cli::V1::Projects::ClustersControllerTest < ActionContro
},
}

data = json_fixture('files/controller/cluster_not_ready.json')
stubbed_create_cluster_request = stub_create_cluster_request(data)
cluster_creation_data = json_fixture('files/controller/cluster_not_ready.json')
stubbed_create_namespace_request = stub_create_namespace_request
stubbed_create_cluster_request = stub_create_cluster_request(cluster_creation_data)
cluster_show_data = json_fixture('files/controller/cluster_ready.json')
stubbed_cluster_request = stub_get_cluster_request(cluster_show_data)

differences = {
-> { UffizziCore::Cluster.count } => 1,
Expand All @@ -100,12 +105,11 @@ class UffizziCore::Api::Cli::V1::Projects::ClustersControllerTest < ActionContro
assert_response(:success)
assert_requested(stubbed_create_cluster_request)
assert_requested(stubbed_create_namespace_request)
assert_requested(stubbed_cluster_request)
end

test '#show' do
cluster = create(:cluster, project: @project, deployed_by: @user, name: 'test')
data = json_fixture('files/controller/cluster_ready.json')
stubbed_cluster_request = stub_get_cluster_request(data)

params = {
project_slug: @project.slug,
Expand All @@ -115,7 +119,6 @@ class UffizziCore::Api::Cli::V1::Projects::ClustersControllerTest < ActionContro
get :show, params: params, format: :json

assert_response(:success)
assert_requested(stubbed_cluster_request)
end

test '#destroy' do
Expand Down
2 changes: 2 additions & 0 deletions core/test/dummy/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ continuous_preview:
deployment:
subdomain:
length_limit: 63
vcluster:
max_creation_retry_count: 5
2 changes: 1 addition & 1 deletion core/test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
t.string "state"
t.string "name"
t.text "manifest"
t.text "kube_config"
t.text "kubeconfig"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["project_id"], name: "index_cluster_on_project_id"
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20230613110517_create_clusters.uffizzi_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def change
t.string 'state'
t.string 'name'
t.text 'manifest'
t.text 'kube_config'
t.text 'kubeconfig'

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
t.string "state"
t.string "name"
t.text "manifest"
t.text "kube_config"
t.text "kubeconfig"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["project_id"], name: "index_cluster_on_project_id"
Expand Down

0 comments on commit 6aa06d8

Please sign in to comment.