added clusters show

This commit is contained in:
Chris Zhu
2024-10-31 14:44:28 -07:00
parent e86b572178
commit ac6bea2c8d
6 changed files with 52 additions and 7 deletions

View File

@@ -93,3 +93,5 @@ gem "tailwindcss-rails", "~> 2.7"
gem "httparty", "~> 0.22.0"
gem "redcarpet", "~> 3.6"
gem "rubyzip", "~> 2.3"

View File

@@ -553,6 +553,7 @@ DEPENDENCIES
responders!
rqrcode (~> 2.2)
rubocop-rails-omakase
rubyzip (~> 2.3)
selenium-webdriver
sidekiq (~> 6.2)
sitemap_generator (~> 6.1)

View File

@@ -43,7 +43,6 @@ bin/dev
- [ ] Docker compose should work
- [ ] Allow connecting to github separately from the app, not just on sign up
- [ ] Make a single user mode
- [ ] Fix landing page to show full screenshot
- [ ] I want a way to “stop” the processes, can maybe do this with a replicas=0 setting
- [ ] Rebulid metrics tabs so it works for both clusters & pods
https://overcast.blog/zero-downtime-deployments-with-kubernetes-a-full-guide-71019397b924?gi=95ab85c45634

View File

@@ -1,5 +1,8 @@
class ClustersController < ApplicationController
before_action :set_cluster, only: [ :show, :edit, :update, :destroy, :test_connection, :download_kubeconfig, :logs ]
before_action :set_cluster, only: [
:show, :edit, :update, :destroy,
:test_connection, :download_kubeconfig, :logs, :download_yaml,
]
skip_before_action :authenticate_user!, only: [:new]
# GET /clusters
@@ -39,6 +42,38 @@ class ClustersController < ApplicationController
end
end
def export(cluster, namespace, yaml_content, zip)
parsed = YAML.safe_load(yaml_content)
parsed['items'].each do |item|
name = item['metadata']['name']
zip.put_next_entry("#{cluster}/#{namespace}/#{name}.yaml")
zip.write(item.to_yaml)
end
end
def download_yaml
require 'zip'
stringio = Zip::OutputStream.write_buffer do |zio|
@cluster.projects.each do |project|
# Create a directory for each project
# Export services, deployments, ingress and cron jobs from a kubernetes namespace
%w[services deployments ingress cronjobs].each do |resource|
yaml_content = K8::Kubectl.new(@cluster.kubeconfig).call("get #{resource} -n #{project.name} -o yaml")
export(@cluster.name, project.name, yaml_content, zio)
end
end
end
stringio.rewind
# Send the zip file to the user
send_data(stringio.read,
filename: "#{@cluster.name}.zip",
type: "application/zip"
)
end
def download_kubeconfig
send_data @cluster.kubeconfig.to_yaml, filename: "#{@cluster.name}-kubeconfig.yml", type: "application/yaml"
end

View File

@@ -4,11 +4,18 @@
<%= cluster_layout(@cluster) do %>
<div id="<%= dom_id @cluster %>">
<%= link_to download_kubeconfig_cluster_path(@cluster), class: "btn btn-sm btn-outline" do %>
<div class="flex items-center gap-2">
Download Kubeconfig File
</div>
<% end %>
<div class="grid grid-cols-2 gap-4">
<%= link_to download_kubeconfig_cluster_path(@cluster), class: "btn btn-sm btn-outline" do %>
<div class="flex items-center gap-2">
Download Kubeconfig File
</div>
<% end %>
<%= link_to download_yaml_cluster_path(@cluster), class: "btn btn-sm btn-outline" do %>
<div class="flex items-center gap-2">
Download YAML File
</div>
<% end %>
</div>
<% if @cluster.projects.any? %>
<h4 class="mt-4 text-2xl font-bold">Projects</h4>

View File

@@ -50,6 +50,7 @@ Rails.application.routes.draw do
resources :clusters do
member do
get :download_kubeconfig
get :download_yaml
get :logs
end
resource :metrics, only: [ :show ], module: :clusters