Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
moklidia committed Jul 24, 2023
2 parents 9e946c6 + 195ce62 commit 7b4aa47
Show file tree
Hide file tree
Showing 30 changed files with 158 additions and 108 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: core
specs:
uffizzi_core (2.2.4)
uffizzi_core (2.2.5)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -110,7 +110,7 @@ GEM
ast (2.4.2)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.786.0)
aws-partitions (1.791.0)
aws-sdk-core (3.178.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -267,7 +267,7 @@ GEM
public_suffix (5.0.3)
puma (4.3.11)
nio4r (~> 2.0)
pundit (2.3.0)
pundit (2.3.1)
activesupport (>= 3.0.0)
racc (1.6.0)
rack (2.2.3)
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ compose:
continuous_preview:
default_delete_preview_after: 72
deployment:
max_memory_limit: 8000
subdomain:
length_limit: 63
default_job_retry_count: 5
Expand Down
6 changes: 3 additions & 3 deletions core/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uffizzi_core (2.2.4)
uffizzi_core (2.2.5)
aasm
actionpack (~> 6.1.0)
active_model_serializers
Expand Down Expand Up @@ -109,7 +109,7 @@ GEM
activerecord (>= 5.2.6)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
aws-partitions (1.786.0)
aws-partitions (1.791.0)
aws-sdk-core (3.178.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -297,7 +297,7 @@ GEM
public_suffix (4.0.6)
puma (5.6.2)
nio4r (~> 2.0)
pundit (2.3.0)
pundit (2.3.1)
activesupport (>= 3.0.0)
racc (1.7.1)
rack (2.2.3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ def domain_module
module_class(:domain_module)
end

def deployment_memory_module
return unless module_exists?(:deployment_memory_module)

module_class(:deployment_memory_module)
end

def template_memory_module
return unless module_exists?(:template_memory_module)

module_class(:template_memory_module)
end

def controller_settings_service
return unless module_exists?(:controller_settings)

module_class(:controller_settings)
end

private

def module_exists?(module_name)
Expand Down
14 changes: 0 additions & 14 deletions core/app/forms/uffizzi_core/api/cli/v1/deployment/create_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class UffizziCore::Api::Cli::V1::Deployment::CreateForm < UffizziCore::Deploymen

validate :check_all_containers_have_unique_ports
validate :check_exists_ingress_container
validate :check_max_memory_limit
validate :check_max_memory_request
validate :check_secrets_exist_in_database

def assign_dependences!(project, user)
Expand Down Expand Up @@ -87,18 +85,6 @@ def check_exists_ingress_container
errors.add(:containers, :incorrect_ingress_container) unless UffizziCore::DeploymentService.ingress_container?(active_containers)
end

def check_max_memory_limit
return if UffizziCore::DeploymentService.valid_containers_memory_limit?(self)

errors.add(:containers, :max_memory_limit_error, max: project.account.container_memory_limit)
end

def check_max_memory_request
return if UffizziCore::DeploymentService.valid_containers_memory_request?(self)

errors.add(:containers, :max_memory_request_error, max: project.account.container_memory_limit)
end

def check_secrets_exist_in_database
return if compose_file.nil?

Expand Down
14 changes: 0 additions & 14 deletions core/app/forms/uffizzi_core/api/cli/v1/deployment/update_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class UffizziCore::Api::Cli::V1::Deployment::UpdateForm < UffizziCore::Deploymen

validate :check_all_containers_have_unique_ports
validate :check_exists_ingress_container
validate :check_max_memory_limit
validate :check_max_memory_request

def assign_dependences!(project, user)
self.project = project
Expand Down Expand Up @@ -84,16 +82,4 @@ def check_exists_ingress_container

errors.add(:containers, :incorrect_ingress_container) unless UffizziCore::DeploymentService.ingress_container?(active_containers)
end

def check_max_memory_limit
return if UffizziCore::DeploymentService.valid_containers_memory_limit?(self)

errors.add(:containers, :max_memory_limit_error, max: project.account.container_memory_limit)
end

def check_max_memory_request
return if UffizziCore::DeploymentService.valid_containers_memory_request?(self)

errors.add(:containers, :max_memory_request_error, max: project.account.container_memory_limit)
end
end
16 changes: 0 additions & 16 deletions core/app/forms/uffizzi_core/api/cli/v1/template/create_form.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# frozen_string_literal: true

class UffizziCore::Api::Cli::V1::Template::CreateForm < UffizziCore::Template
validate :check_max_memory_limit
validate :check_max_memory_request

private

def check_max_memory_limit
return if valid_containers_memory_limit?

errors.add(:payload, :max_memory_limit_error, max: project.account.container_memory_limit)
end

def check_max_memory_request
return if valid_containers_memory_request?

errors.add(:payload, :max_memory_request_error, max: project.account.container_memory_limit)
end
end
2 changes: 1 addition & 1 deletion core/app/lib/uffizzi_core/concerns/models/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module UffizziCore::Concerns::Models::Cluster
end

event :disable, after: :after_disable do
transitions from: [:failed_deploy_namespace, :deploying, :deployed, :failed], to: :disabled
transitions from: [:deploying_namespace, :failed_deploy_namespace, :deploying, :deployed, :failed], to: :disabled
end
end

Expand Down
16 changes: 0 additions & 16 deletions core/app/lib/uffizzi_core/concerns/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,5 @@ module UffizziCore::Concerns::Models::Template
enumerize :creation_source, in: [:manual, :compose_file, :system], predicates: true, scope: true

validates :name, presence: true

def valid_containers_memory_limit?
containers_attributes = payload['containers_attributes']
container_memory_limit = project.account.container_memory_limit
return true if container_memory_limit.nil?

containers_attributes.all? { |container| container['memory_limit'].to_i <= container_memory_limit }
end

def valid_containers_memory_request?
containers_attributes = payload['containers_attributes']
container_memory_limit = project.account.container_memory_limit
return true if container_memory_limit.nil?

containers_attributes.all? { |container| container['memory_request'].to_i <= container_memory_limit }
end
end
end
10 changes: 10 additions & 0 deletions core/app/models/uffizzi_core/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@

class UffizziCore::Deployment < UffizziCore::ApplicationRecord
include UffizziCore::Concerns::Models::Deployment
include UffizziCore::DependencyInjectionConcern

validate :check_max_memory_limit

def check_max_memory_limit
return if deployment_memory_module.valid_memory_limit?(self)

deployment_memory_module.memory_limit_error_message(self)
errors.add(:containers, message)
end
end
10 changes: 10 additions & 0 deletions core/app/models/uffizzi_core/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

class UffizziCore::Template < UffizziCore::ApplicationRecord
include UffizziCore::Concerns::Models::Template
include UffizziCore::DependencyInjectionConcern

validate :check_max_memory_limit

def check_max_memory_limit
return if template_memory_module.valid_memory_limit?(self)

message = template_memory_module.memory_limit_error_message(self)
errors.add(:payload, message)
end
end
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, :kubeconfig
attributes :name, :state, :kubeconfig, :created_at, :host
end
1 change: 1 addition & 0 deletions core/app/services/uffizzi_core/cluster_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def manage_deploying(cluster, try)
if deployed_cluster.status.ready && deployed_cluster.status.kube_config.present?
cluster.finish_deploy
cluster.kubeconfig = deployed_cluster.status.kube_config
cluster.host = deployed_cluster.status.host
cluster.save!

return
Expand Down
16 changes: 0 additions & 16 deletions core/app/services/uffizzi_core/container_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ def continuously_deploy_enabled?(container)
container.aasm(:continuously_deploy).current_state == UffizziCore::Container::STATE_CD_ENABLED
end

def valid_memory_limit?(container)
max_memory_limit = container.deployment.project.account.container_memory_limit
container_memory_limit = container.memory_limit
return true if max_memory_limit.nil? || container_memory_limit.nil?

container_memory_limit <= max_memory_limit
end

def valid_memory_request?(container)
max_memory_limit = container.deployment.project.account.container_memory_limit
container_memory_request = container.memory_request
return true if max_memory_limit.nil? || container_memory_request.nil?

container_memory_request <= max_memory_limit
end

def last_state(container)
pods = pods_by_container(container)
container_status = container_status(container, pods)
Expand Down
2 changes: 1 addition & 1 deletion core/app/services/uffizzi_core/controller_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def controller_client(deployable)
when UffizziCore::Deployment
Settings.controller
when UffizziCore::Cluster
Settings.vcluster_controller
controller_settings_service.vcluster(deployable)
else
raise StandardError, "Deployable #{deployable.class.name} undefined"
end
Expand Down
9 changes: 9 additions & 0 deletions core/app/services/uffizzi_core/controller_settings_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UffizziCore::ControllerSettingsService
class << self
def vcluster(_cluster)
Settings.vcluster_controller
end
end
end
11 changes: 11 additions & 0 deletions core/app/services/uffizzi_core/deployment/memory_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class UffizziCore::Deployment::MemoryService
class << self
def valid_memory_limit?(_deployment)
true
end

def memory_limit_error_message(_deployment); end
end
end
16 changes: 0 additions & 16 deletions core/app/services/uffizzi_core/deployment_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ def all_containers_have_unique_ports?(containers)
containers.empty? || ports.size == ports.uniq.size
end

def valid_containers_memory_limit?(deployment)
containers = deployment.containers
container_memory_limit = deployment.project.account.container_memory_limit
return true if container_memory_limit.nil?

containers.all? { |container| container.memory_limit <= container_memory_limit }
end

def valid_containers_memory_request?(deployment)
containers = deployment.containers
container_memory_limit = deployment.project.account.container_memory_limit
return true if container_memory_limit.nil?

containers.all? { |container| container.memory_request <= container_memory_limit }
end

def ingress_container?(containers)
containers.empty? || containers.map(&:receive_incoming_requests).count(true) == 1
end
Expand Down
11 changes: 11 additions & 0 deletions core/app/services/uffizzi_core/template/memory_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class UffizziCore::Template::MemoryService
class << self
def valid_memory_limit?(_template)
true
end

def memory_limit_error_message(_template); end
end
end
3 changes: 1 addition & 2 deletions core/config/locales/en.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ en:
uffizzi_core/deployment:
attributes:
containers:
max_memory_limit_error: "Memory limit of containers must be less than %{max}"
max_memory_request_error: "Memory request of containers must be less than %{max}"
max_memory_limit_error: "Total memory limit of containers must be less than %{max}"
uffizzi_core/user:
attributes:
email:
Expand Down
7 changes: 7 additions & 0 deletions core/db/migrate/20230711101901_add_host_to_clusters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddHostToClusters < ActiveRecord::Migration[6.1]
def change
add_column(:uffizzi_core_clusters, :host, :string)
end
end
3 changes: 3 additions & 0 deletions core/lib/uffizzi_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
module UffizziCore
mattr_accessor :dependencies, default: {
rbac: 'UffizziCore::Rbac::UserAccessService',
deployment_memory_module: 'UffizziCore::Deployment::MemoryService',
template_memory_module: 'UffizziCore::Template::MemoryService',
controller_settings: 'UffizziCore::ControllerSettingsService',
}
mattr_accessor :table_names, default: {
accounts: :uffizzi_core_accounts,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/uffizzi_core/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module UffizziCore
VERSION = '2.2.4'
VERSION = '2.2.5'
end
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon

expected_default_container_params = {
secret_variables: [],
memory_limit: nil,
memory_request: nil,
memory_limit: Settings.compose.default_memory,
memory_request: Settings.compose.default_memory,
entrypoint: nil,
command: nil,
port: nil,
Expand Down
1 change: 1 addition & 0 deletions core/test/dummy/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ compose:
continuous_preview:
default_delete_preview_after: 72
deployment:
max_memory_limit: 8000
subdomain:
length_limit: 63
vcluster:
Expand Down
3 changes: 2 additions & 1 deletion core/test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_06_13_101901) do
ActiveRecord::Schema.define(version: 2023_07_11_101901) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -82,6 +82,7 @@
t.text "kubeconfig"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "host"
t.index ["project_id"], name: "index_cluster_on_project_id"
end

Expand Down
Loading

0 comments on commit 7b4aa47

Please sign in to comment.