mirror of
https://github.com/czhu12/canine.git
synced 2025-12-16 16:35:10 -06:00
fix lint errors
This commit is contained in:
@@ -6,3 +6,5 @@ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
|
||||
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
|
||||
# Layout/SpaceInsideArrayLiteralBrackets:
|
||||
# Enabled: false
|
||||
Style/StringLiterals:
|
||||
Enabled: false
|
||||
|
||||
@@ -35,4 +35,4 @@ class AddOns::InstallHelmChart
|
||||
end
|
||||
values
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,4 +11,4 @@ class AddOns::UninstallHelmChart
|
||||
end
|
||||
add_on.uninstalled!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,4 +17,4 @@ class Clusters::Install
|
||||
cluster.failed!
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,4 +14,4 @@ class Clusters::IsReady
|
||||
context.fail!("Cluster is not ready")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,4 +35,4 @@ class Projects::Local::CheckDockerExists
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class Projects::Local::CheckGithubConnectivity
|
||||
|
||||
executed do |context|
|
||||
path = context.project.repository_url
|
||||
|
||||
|
||||
# Check if directory exists
|
||||
context.checklist << "Checking project directory exists..."
|
||||
unless Dir.exist?(path)
|
||||
|
||||
@@ -7,4 +7,4 @@ class Projects::Save
|
||||
executed do |context|
|
||||
context.project.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,4 +7,4 @@ class Services::Create
|
||||
Services::Save,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,4 +8,4 @@ class Services::CreateAssociations
|
||||
CronSchedule.create(schedule: context.params[:service][:cron_schedule][:schedule], service: context.service)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class AddOnsController < ApplicationController
|
||||
include StorageHelper
|
||||
before_action :set_add_on, only: [:show, :edit, :update, :destroy]
|
||||
before_action :set_add_on, only: [ :show, :edit, :update, :destroy ]
|
||||
|
||||
# GET /add_ons
|
||||
def index
|
||||
|
||||
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
|
||||
include Pundit::Authorization
|
||||
include Pagy::Backend
|
||||
|
||||
#protect_from_forgery with: :exception
|
||||
# protect_from_forgery with: :exception
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||
|
||||
@@ -6,4 +6,4 @@ class Clusters::BaseController < ApplicationController
|
||||
def set_cluster
|
||||
@cluster = Cluster.find(params[:cluster_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -73,7 +73,7 @@ class ClustersController < ApplicationController
|
||||
stringio.rewind
|
||||
|
||||
# Send the zip file to the user
|
||||
send_data(stringio.read,
|
||||
send_data(stringio.read,
|
||||
filename: "#{@cluster.name}.zip",
|
||||
type: "application/zip"
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Local::PagesController < ApplicationController
|
||||
EXPECTED_SCOPES = ["repo", "write:packages"]
|
||||
EXPECTED_SCOPES = [ "repo", "write:packages" ]
|
||||
if Rails.application.config.local_mode
|
||||
skip_before_action :set_github_token_if_not_exists
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Users::RegistrationsController < Devise::RegistrationsController
|
||||
layout 'homepage', only: [:new, :create]
|
||||
layout 'homepage', only: [ :new, :create ]
|
||||
|
||||
protected
|
||||
def update_resource(resource, params)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Users::SessionsController < Devise::SessionsController
|
||||
layout 'homepage', only: [:new, :create]
|
||||
layout 'homepage', only: [ :new, :create ]
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module AnnouncementsHelper
|
||||
{
|
||||
"new" => "text-success",
|
||||
"update" => "text-warning",
|
||||
"fix" => "text-danger",
|
||||
"fix" => "text-danger"
|
||||
}.fetch(type, "text-success")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,4 +20,4 @@ module Loggable
|
||||
def create_log_output
|
||||
self.log_output = LogOutput.create!(loggable: self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ module MetricsHelper
|
||||
metrics.map do |m|
|
||||
{
|
||||
created_at: m.created_at,
|
||||
value: m.metadata[key].to_f,
|
||||
value: m.metadata[key].to_f
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module StorageHelper
|
||||
|
||||
value = match[1].to_f
|
||||
unit = match[2]&.upcase&.chr || ''
|
||||
|
||||
|
||||
(value * (SIZE_UNITS[unit] || 1)).to_i
|
||||
end
|
||||
|
||||
@@ -30,4 +30,4 @@ module StorageHelper
|
||||
def standardize_size(size)
|
||||
integer_to_size(size_to_integer(size)).to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,4 +2,4 @@ class AddOns::InstallJob < ApplicationJob
|
||||
def perform(add_on)
|
||||
AddOns::InstallHelmChart.execute(add_on:)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,4 +2,4 @@ class AddOns::UninstallJob < ApplicationJob
|
||||
def perform(add_on)
|
||||
AddOns::UninstallHelmChart.execute(add_on:)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Projects::DestroyJob < ApplicationJob
|
||||
|
||||
def perform(project)
|
||||
project.destroying!
|
||||
kubeconfig = project.cluster.kubeconfig
|
||||
@@ -10,13 +9,13 @@ class Projects::DestroyJob < ApplicationJob
|
||||
|
||||
unless Project.where(repository: project.repository).not(id: project.id).exists?
|
||||
client = Octokit::Client.new(access_token: project.account.github_access_token)
|
||||
|
||||
|
||||
# Get all webhooks for the repository
|
||||
hooks = client.hooks(project.repository_url)
|
||||
|
||||
|
||||
# Find the webhook with matching URL
|
||||
hook = hooks.find { |h| h.config.url.include?(Rails.application.routes.url_helpers.inbound_webhooks_github_index_path) }
|
||||
|
||||
|
||||
# Delete the hook if found
|
||||
client.remove_hook(project.repository_url, hook.id) if hook
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ class AddOn < ApplicationRecord
|
||||
include Loggable
|
||||
belongs_to :cluster
|
||||
has_one :account, through: :cluster
|
||||
enum :status, {installing: 0, installed: 1, uninstalling: 2, uninstalled: 3, failed: 4}
|
||||
enum :status, { installing: 0, installed: 1, uninstalling: 2, uninstalled: 3, failed: 4 }
|
||||
validates :chart_type, presence: true
|
||||
validate :chart_type_exists
|
||||
validates :name, presence: true, format: { with: /\A[a-z0-9_-]+\z/, message: "must be lowercase, numbers, hyphens, and underscores only" }
|
||||
|
||||
@@ -19,15 +19,15 @@ class Metric < ApplicationRecord
|
||||
enum :metric_type, {
|
||||
cpu: 0,
|
||||
memory: 1,
|
||||
storage: 2,
|
||||
storage: 2
|
||||
}
|
||||
|
||||
scope :node_only_tags, -> {
|
||||
scope :node_only_tags, -> {
|
||||
where("array_length(tags, 1) = 1")
|
||||
}
|
||||
|
||||
scope :for_project, ->(project) {
|
||||
where("tags @> ARRAY[?]::jsonb[]", %Q["namespace:#{project.name}"])
|
||||
where("tags @> ARRAY[?]::jsonb[]", %Q("namespace:#{project.name}"))
|
||||
}
|
||||
|
||||
def tag_value(tag)
|
||||
|
||||
@@ -31,4 +31,4 @@ class K8::Helm::Client
|
||||
return exit_status
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,4 +37,4 @@ class K8::Helm::Postgresql < K8::Helm::Service
|
||||
output = K8::Kubectl.new(add_on.cluster.kubeconfig, Cli::RunAndReturnOutput.new).call("get secret --namespace #{add_on.name} #{service_name} -o jsonpath='{.data.postgres-password}' | base64 -d")
|
||||
output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,4 +26,4 @@ class K8::Helm::Redis < K8::Helm::Service
|
||||
output = K8::Kubectl.new(add_on.cluster.kubeconfig, Cli::RunAndReturnOutput.new).call("get secret --namespace #{add_on.name} #{service_basename} -o jsonpath='{.data.redis-password}' | base64 -d")
|
||||
output.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,18 +11,18 @@ class K8::Helm::Service
|
||||
volumes = pods.flat_map do |pod|
|
||||
pod.spec.volumes.select { |volume| volume.respond_to?(:persistentVolumeClaim) && volume.persistentVolumeClaim.claimName }
|
||||
end
|
||||
|
||||
|
||||
pvc_names = volumes.map { |volume| volume.persistentVolumeClaim.claimName }
|
||||
pvcs = client.get_persistent_volume_claims(
|
||||
namespace: 'default',
|
||||
field_selector: "metadata.name=#{pvc_names.join(',')}"
|
||||
).flatten
|
||||
|
||||
|
||||
pvcs.map do |pvc|
|
||||
pod = pods.find { |p| p.spec.volumes.any? { |vol| vol.persistentVolumeClaim&.claimName == pvc.metadata.name } }
|
||||
mount_path = get_mount_path(pod, pvc.metadata.name) if pod
|
||||
usage = mount_path ? get_volume_usage(pod.metadata.name, mount_path) : nil
|
||||
|
||||
|
||||
{
|
||||
name: pvc.metadata.name,
|
||||
usage: usage
|
||||
@@ -40,16 +40,16 @@ class K8::Helm::Service
|
||||
def get_mount_path(pod, pvc_name)
|
||||
volume = pod.spec.volumes.find { |vol| vol.persistentVolumeClaim&.claimName == pvc_name }
|
||||
return nil unless volume
|
||||
|
||||
|
||||
container = pod.spec.containers.find { |c| c.volumeMounts.any? { |vm| vm.name == volume.name } }
|
||||
container&.volumeMounts&.find { |vm| vm.name == volume.name }&.mountPath
|
||||
end
|
||||
|
||||
|
||||
def get_volume_usage(pod_name, mount_path)
|
||||
output = K8::Kubectl.new(add_on.cluster.kubeconfig, Cli::RunAndReturnOutput.new).call("exec #{pod_name} -- df -h #{mount_path}")
|
||||
lines = output.strip.split("\n")
|
||||
return nil if lines.size < 2
|
||||
|
||||
|
||||
usage_line = lines[1].split
|
||||
{
|
||||
used: usage_line[2],
|
||||
@@ -67,5 +67,4 @@ class K8::Helm::Service
|
||||
output = K8::Kubectl.new(add_on.cluster.kubeconfig, Cli::RunAndReturnOutput.new).call("exec #{service_name} -- df -h /data")
|
||||
output.strip
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module K8
|
||||
module Kubeconfig
|
||||
def with_kube_config
|
||||
Tempfile.open(['kubeconfig', '.yaml']) do |kubeconfig_file|
|
||||
Tempfile.open([ 'kubeconfig', '.yaml' ]) do |kubeconfig_file|
|
||||
kubeconfig_hash = kubeconfig.is_a?(String) ? JSON.parse(kubeconfig) : kubeconfig
|
||||
kubeconfig_file.write(kubeconfig_hash.to_yaml)
|
||||
kubeconfig_file.flush
|
||||
|
||||
@@ -130,4 +130,4 @@ module K8::Metrics::Api
|
||||
@memory = memory
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,4 +5,4 @@ class K8::Shared::AcmeIssuer < K8::Base
|
||||
@email = email
|
||||
@namespace = namespace
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,4 +9,4 @@ class K8::Stateless::CronJob < K8::Base
|
||||
def restart
|
||||
K8::Kubectl.from_project(project).call("rollout restart cronjob/#{service.name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,10 +2,10 @@ class RandomNameGenerator
|
||||
ADJECTIVES = %w[quick lazy happy brave clever quiet mighty kind shiny eager]
|
||||
NOUNS = %w[fox bear wolf tiger lion eagle owl deer hare dolphin]
|
||||
|
||||
def self.generate_name(prefix=nil)
|
||||
def self.generate_name(prefix = nil)
|
||||
adjective = ADJECTIVES.sample
|
||||
noun = NOUNS.sample
|
||||
name = "#{adjective}-#{noun}"
|
||||
prefix ? "#{prefix}-#{name}" : name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Chartkick.options = {
|
||||
height: "400px",
|
||||
colors: ["#4f46e5", "#06b6d4", "#10b981", "#f59e0b", "#ef4444"],
|
||||
colors: [ "#4f46e5", "#06b6d4", "#10b981", "#f59e0b", "#ef4444" ],
|
||||
library: {
|
||||
font: {
|
||||
family: "'DM Sans', sans-serif"
|
||||
|
||||
@@ -32,6 +32,6 @@ class CreateNoticedTables < ActiveRecord::Migration[6.1]
|
||||
setting = config.options[config.orm][:primary_key_type]
|
||||
primary_key_type = setting || :primary_key
|
||||
foreign_key_type = setting || :bigint
|
||||
[primary_key_type, foreign_key_type]
|
||||
[ primary_key_type, foreign_key_type ]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,8 +14,8 @@ class CreateFriendlyIdSlugs < MIGRATION_CLASS
|
||||
t.string :scope
|
||||
t.datetime :created_at
|
||||
end
|
||||
add_index :friendly_id_slugs, [:sluggable_type, :sluggable_id]
|
||||
add_index :friendly_id_slugs, [:slug, :sluggable_type], length: {slug: 140, sluggable_type: 50}
|
||||
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], length: {slug: 70, sluggable_type: 50, scope: 70}, unique: true
|
||||
add_index :friendly_id_slugs, [ :sluggable_type, :sluggable_id ]
|
||||
add_index :friendly_id_slugs, [ :slug, :sluggable_type ], length: { slug: 140, sluggable_type: 50 }
|
||||
add_index :friendly_id_slugs, [ :slug, :sluggable_type, :scope ], length: { slug: 70, sluggable_type: 50, scope: 70 }, unique: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@ namespace :metrics do
|
||||
end
|
||||
task check_health: :environment do
|
||||
Service.web_service.where('healthcheck_url IS NOT NULL').each do |service|
|
||||
#url = File.join("http://#{service.name}-service.#{service.project.name}.svc.cluster.local", service.healthcheck_url)
|
||||
#K8::Client.from_project(service.project).run_command("curl -s -o /dev/null -w '%{http_code}' #{url}")
|
||||
# url = File.join("http://#{service.name}-service.#{service.project.name}.svc.cluster.local", service.healthcheck_url)
|
||||
# K8::Client.from_project(service.project).run_command("curl -s -o /dev/null -w '%{http_code}' #{url}")
|
||||
if service.domains.any?
|
||||
url = File.join("https://#{service.domains.first.domain_name}", service.healthcheck_url)
|
||||
Rails.logger.info("Checking health for #{service.name} at #{url}")
|
||||
|
||||
Reference in New Issue
Block a user