mirror of
https://github.com/czhu12/canine.git
synced 2026-05-03 10:00:31 -05:00
Merge pull request #504 from CanineHQ/chriszhu__cluster_fix
fix clusters creation + more specs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
APP_HOST=canine.example.com
|
||||
BOOT_MODE=cloud
|
||||
OMNIAUTH_GITHUB_WEBHOOK_SECRET=1234567890
|
||||
OMNIAUTH_GITHUB_PUBLIC_KEY=1234567890
|
||||
OMNIAUTH_GITHUB_PRIVATE_KEY=1234567890
|
||||
LOCAL_MODE=true
|
||||
OMNIAUTH_GITHUB_PRIVATE_KEY=1234567890
|
||||
@@ -171,7 +171,7 @@ class ClustersController < ApplicationController
|
||||
params[:cluster][:kubeconfig] = YAML.safe_load(params[:cluster][:kubeconfig])
|
||||
elsif params[:cluster][:cluster_type] == "k3s"
|
||||
ip_address = params[:cluster][:ip_address]
|
||||
kubeconfig_output = params[:cluster][:kubeconfig_output]
|
||||
kubeconfig_output = params[:cluster][:k3s_kubeconfig_output]
|
||||
if ip_address.blank? || kubeconfig_output.blank?
|
||||
message = "IP address and kubeconfig output are required for K3s clusters"
|
||||
flash[:error] = message
|
||||
@@ -188,7 +188,7 @@ class ClustersController < ApplicationController
|
||||
end
|
||||
params[:cluster][:kubeconfig] = data
|
||||
elsif params[:cluster][:cluster_type] == "local_k3s"
|
||||
kubeconfig_output = params[:cluster][:kubeconfig_output]
|
||||
kubeconfig_output = params[:cluster][:local_k3s_kubeconfig_output]
|
||||
if kubeconfig_output.blank?
|
||||
message = "Kubeconfig output is required for local K3s clusters"
|
||||
flash[:error] = message
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<div data-k3s-instructions-target="step" class="hidden">
|
||||
4. Copy the output and paste it here:
|
||||
<div class="form-group">
|
||||
<%= form.text_area :kubeconfig_output, class: "textarea textarea-bordered w-full max-w-lg h-48" %>
|
||||
<%= form.text_area :k3s_kubeconfig_output, class: "textarea textarea-bordered w-full max-w-lg h-48" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :kubeconfig_output, "Kubeconfig" %>
|
||||
<%= form.text_area :kubeconfig_output, class: "textarea textarea-bordered w-full max-w-lg h-48", placeholder: "Paste your kubeconfig here..." %>
|
||||
<%= form.label :local_k3s_kubeconfig_output, "Kubeconfig" %>
|
||||
<%= form.text_area :local_k3s_kubeconfig_output, class: "textarea textarea-bordered w-full max-w-lg h-48", placeholder: "Paste your kubeconfig here..." %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -6,8 +6,8 @@ module SystemHelpers
|
||||
user ||= account.owner
|
||||
|
||||
visit new_user_session_path
|
||||
fill_in "user_email", with: user.email
|
||||
fill_in "user_password", with: "password"
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: "password"
|
||||
click_button "Sign in"
|
||||
|
||||
{ user: user, account: account }
|
||||
|
||||
@@ -65,4 +65,86 @@ RSpec.describe "Clusters", type: :system do
|
||||
expect(page).to have_current_path(clusters_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "create cluster" do
|
||||
let(:valid_kubeconfig_output) do
|
||||
<<~YAML
|
||||
apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
certificate-authority-data: dGVzdC1jZXJ0LWRhdGE=
|
||||
server: https://127.0.0.1:6443
|
||||
name: default
|
||||
contexts:
|
||||
- context:
|
||||
cluster: default
|
||||
user: default
|
||||
name: default
|
||||
current-context: default
|
||||
kind: Config
|
||||
preferences: {}
|
||||
users:
|
||||
- name: default
|
||||
user:
|
||||
token: test-token-12345
|
||||
YAML
|
||||
end
|
||||
|
||||
before do
|
||||
allow(Clusters::InstallJob).to receive(:perform_later)
|
||||
end
|
||||
|
||||
it "creates a new external k3s cluster" do
|
||||
visit new_cluster_path
|
||||
fill_in "cluster_name", with: "my-k3s-cluster"
|
||||
find('[data-card-name="k3s"]').click
|
||||
|
||||
fill_in "cluster_ip_address", with: "192.168.1.100"
|
||||
|
||||
# Show and fill the kubeconfig field directly via JS (bypassing step validation)
|
||||
page.execute_script("document.querySelectorAll('[data-k3s-instructions-target=\"step\"]').forEach(s => s.classList.remove('hidden'))")
|
||||
page.execute_script("document.querySelector('[data-k3s-instructions-target=\"next\"]').type = 'submit'")
|
||||
page.execute_script("document.querySelector('[data-k3s-instructions-target=\"next\"]').innerHTML = 'Submit'")
|
||||
|
||||
fill_in "cluster_k3s_kubeconfig_output", with: valid_kubeconfig_output
|
||||
click_button "Submit"
|
||||
|
||||
expect(page).to have_content("Cluster was successfully created")
|
||||
expect(Cluster.last).to have_attributes(name: "my-k3s-cluster", cluster_type: "k3s")
|
||||
expect(Clusters::InstallJob).to have_received(:perform_later)
|
||||
end
|
||||
|
||||
it "creates a new local k3s cluster" do
|
||||
visit new_cluster_path
|
||||
fill_in "cluster_name", with: "my-local-cluster"
|
||||
find('[data-card-name="local_k3s"]').click
|
||||
|
||||
fill_in "cluster_local_k3s_kubeconfig_output", with: valid_kubeconfig_output
|
||||
click_button "Create Cluster"
|
||||
|
||||
expect(page).to have_content("Cluster was successfully created")
|
||||
expect(Cluster.last).to have_attributes(name: "my-local-cluster", cluster_type: "local_k3s")
|
||||
expect(Clusters::InstallJob).to have_received(:perform_later)
|
||||
end
|
||||
|
||||
it "creates a new managed k8s cluster" do
|
||||
kubeconfig_file = Tempfile.new([ 'kubeconfig', '.yaml' ])
|
||||
kubeconfig_file.write(valid_kubeconfig_output)
|
||||
kubeconfig_file.rewind
|
||||
|
||||
visit new_cluster_path
|
||||
fill_in "cluster_name", with: "my-k8s-cluster"
|
||||
find('[data-card-name="k8s"]').click
|
||||
|
||||
attach_file "cluster_kubeconfig_file", kubeconfig_file.path
|
||||
click_button "Submit"
|
||||
|
||||
expect(page).to have_content("Cluster was successfully created")
|
||||
expect(Cluster.last).to have_attributes(name: "my-k8s-cluster", cluster_type: "k8s")
|
||||
expect(Clusters::InstallJob).to have_received(:perform_later)
|
||||
ensure
|
||||
kubeconfig_file.close
|
||||
kubeconfig_file.unlink
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user