Skip to content
代码片段 群组 项目
未验证 提交 09d6aa63 编辑于 作者: Alper Akgun's avatar Alper Akgun 提交者: GitLab
浏览文件

Updates to workspaces_quota config updates database fields

上级 10a7ef78
No related branches found
No related tags found
无相关合并请求
......@@ -28,6 +28,8 @@ class RemoteDevelopmentAgentConfig < ApplicationRecord
validates :max_resources_per_workspace,
json_schema: { filename: 'remote_development_agent_configs_workspace_container_resources' }
validates :max_resources_per_workspace, 'remote_development/workspace_container_resources': true
validates :workspaces_quota, numericality: { only_integer: true, greater_than_or_equal_to: -1 }
validates :workspaces_per_user_quota, numericality: { only_integer: true, greater_than_or_equal_to: -1 }
# noinspection RubyResolve - likely due to https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-31540
before_validation :prevent_dns_zone_update, if: ->(record) { record.persisted? && record.dns_zone_changed? }
......
......@@ -5,6 +5,7 @@ module RemoteDevelopment
module AgentConfig
class Updater
include Messages
UNLIMITED_QUOTA = -1
NETWORK_POLICY_EGRESS_DEFAULT = [
{
allow: "0.0.0.0/0",
......@@ -32,6 +33,9 @@ def self.update(value)
model_instance = RemoteDevelopmentAgentConfig.find_or_initialize_by(agent: agent) # rubocop:todo CodeReuse/ActiveRecord -- Use a finder class here
model_instance.enabled = config_from_agent_config_file.fetch(:enabled, false)
model_instance.workspaces_quota = config_from_agent_config_file.fetch(:workspaces_quota, UNLIMITED_QUOTA)
model_instance.workspaces_per_user_quota = config_from_agent_config_file.fetch(:workspaces_per_user_quota,
UNLIMITED_QUOTA)
model_instance.dns_zone = config_from_agent_config_file[:dns_zone]
model_instance.network_policy_enabled =
config_from_agent_config_file.fetch(:network_policy, {}).fetch(:enabled, true)
......
......@@ -7,6 +7,8 @@
let(:enabled) { true }
let(:dns_zone) { 'my-awesome-domain.me' }
let(:saved_quota) { 5 }
let(:quota) { 5 }
let(:network_policy_present) { false }
let(:default_network_policy_egress) { RemoteDevelopment::AgentConfig::Updater::NETWORK_POLICY_EGRESS_DEFAULT }
let(:network_policy_egress) { default_network_policy_egress }
......@@ -53,6 +55,12 @@
remote_development_config[:gitlab_workspaces_proxy] = gitlab_workspaces_proxy if gitlab_workspaces_proxy_present
remote_development_config[:default_resources_per_workspace_container] = default_resources_per_workspace_container
remote_development_config[:max_resources_per_workspace] = max_resources_per_workspace
if quota
remote_development_config[:workspaces_quota] = quota
remote_development_config[:workspaces_per_user_quota] = quota
end
{
remote_development: remote_development_config
}
......@@ -90,6 +98,8 @@
.to eq(default_resources_per_workspace_container)
expect(config_instance.max_resources_per_workspace.deep_symbolize_keys)
.to eq(max_resources_per_workspace)
expect(config_instance.workspaces_quota).to eq(saved_quota)
expect(config_instance.workspaces_per_user_quota).to eq(saved_quota)
expect(result)
.to be_ok_result(RemoteDevelopment::Messages::AgentConfigUpdateSuccessful.new(
......@@ -193,6 +203,13 @@
it_behaves_like 'successful update'
end
end
context 'when workspace quotas are not explicitly specified in the config passed' do
let(:quota) { nil }
let(:saved_quota) { -1 }
it_behaves_like 'successful update'
end
end
context 'when config file is invalid' do
......
......@@ -104,5 +104,13 @@
'must be a hash'
)
end
it 'allows numerical values for workspaces_quota greater or equal to -1' do
is_expected.to validate_numericality_of(:workspaces_quota).only_integer.is_greater_than_or_equal_to(-1)
end
it 'allows numerical values for workspaces_per_user_quota greater or equal to -1' do
validate_numericality_of(:workspaces_per_user_quota).only_integer.is_greater_than_or_equal_to(-1)
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册