diff --git a/doc/api/graphql/reference/_index.md b/doc/api/graphql/reference/_index.md index 37432125fb119d580de225f9316dc79e0ece6299..01ae2cd402c855a76d5a96ef1ef5794b8cd7ea1c 100644 --- a/doc/api/graphql/reference/_index.md +++ b/doc/api/graphql/reference/_index.md @@ -22746,7 +22746,6 @@ GitLab CI/CD configuration template. | <a id="clusteragentisreceptive"></a>`isReceptive` | [`Boolean`](#boolean) | Whether the cluster agent is receptive or not. | | <a id="clusteragentname"></a>`name` | [`String`](#string) | Name of the cluster agent. | | <a id="clusteragentproject"></a>`project` | [`Project`](#project) | Project the cluster agent is associated with. | -| <a id="clusteragentremotedevelopmentagentconfig"></a>`remoteDevelopmentAgentConfig` {{< icon name="warning-solid" >}} | [`RemoteDevelopmentAgentConfig`](#remotedevelopmentagentconfig) | **Introduced** in GitLab 17.4. **Status**: Experiment. Remote development agent config for the cluster agent. | | <a id="clusteragenttokens"></a>`tokens` | [`ClusterAgentTokenConnection`](#clusteragenttokenconnection) | Tokens associated with the cluster agent. (see [Connections](#connections)) | | <a id="clusteragentupdatedat"></a>`updatedAt` | [`Time`](#time) | Timestamp the cluster agent was updated. | | <a id="clusteragenturlconfigurations"></a>`urlConfigurations` | [`ClusterAgentUrlConfigurationConnection`](#clusteragenturlconfigurationconnection) | URL configurations for the cluster agent in case it is a receptive agent. (see [Connections](#connections)) | @@ -36833,28 +36832,6 @@ Represents the source code attached to a release in a particular format. | <a id="releasesourceformat"></a>`format` | [`String`](#string) | Format of the source. | | <a id="releasesourceurl"></a>`url` | [`String`](#string) | Download URL of the source. | -### `RemoteDevelopmentAgentConfig` - -Represents a remote development agent configuration. - -#### Fields - -| Name | Type | Description | -| ---- | ---- | ----------- | -| <a id="remotedevelopmentagentconfigclusteragent"></a>`clusterAgent` | [`ClusterAgent!`](#clusteragent) | Cluster agent that the remote development agent config belongs to. | -| <a id="remotedevelopmentagentconfigcreatedat"></a>`createdAt` | [`Time!`](#time) | Timestamp of when the remote development agent config was created. | -| <a id="remotedevelopmentagentconfigdefaultmaxhoursbeforetermination"></a>`defaultMaxHoursBeforeTermination` | [`Int!`](#int) | Default max hours before worksapce termination of the remote development agent config. | -| <a id="remotedevelopmentagentconfigdnszone"></a>`dnsZone` | [`String!`](#string) | DNS zone where workspaces are available. | -| <a id="remotedevelopmentagentconfigenabled"></a>`enabled` | [`Boolean!`](#boolean) | Indicates whether remote development is enabled for the GitLab agent. | -| <a id="remotedevelopmentagentconfiggitlabworkspacesproxynamespace"></a>`gitlabWorkspacesProxyNamespace` | [`String!`](#string) | Namespace where gitlab-workspaces-proxy is installed. | -| <a id="remotedevelopmentagentconfigid"></a>`id` | [`RemoteDevelopmentRemoteDevelopmentAgentConfigID!`](#remotedevelopmentremotedevelopmentagentconfigid) | Global ID of the remote development agent config. | -| <a id="remotedevelopmentagentconfigmaxhoursbeforeterminationlimit"></a>`maxHoursBeforeTerminationLimit` | [`Int!`](#int) | Max hours before worksapce termination limit of the remote development agent config. | -| <a id="remotedevelopmentagentconfignetworkpolicyenabled"></a>`networkPolicyEnabled` | [`Boolean!`](#boolean) | Whether the network policy of the remote development agent config is enabled. | -| <a id="remotedevelopmentagentconfigprojectid"></a>`projectId` | [`ID`](#id) | ID of the project that the remote development agent config belongs to. | -| <a id="remotedevelopmentagentconfigupdatedat"></a>`updatedAt` | [`Time!`](#time) | Timestamp of the last update to any mutable remote development agent config property. | -| <a id="remotedevelopmentagentconfigworkspacesperuserquota"></a>`workspacesPerUserQuota` | [`Int!`](#int) | Maximum number of workspaces per user. | -| <a id="remotedevelopmentagentconfigworkspacesquota"></a>`workspacesQuota` | [`Int!`](#int) | Maximum number of workspaces for the GitLab agent. | - ### `Repository` #### Fields @@ -45607,12 +45584,6 @@ A `ReleasesLinkID` is a global ID. It is encoded as a string. An example `ReleasesLinkID` is: `"gid://gitlab/Releases::Link/1"`. -### `RemoteDevelopmentRemoteDevelopmentAgentConfigID` - -A `RemoteDevelopmentRemoteDevelopmentAgentConfigID` is a global ID. It is encoded as a string. - -An example `RemoteDevelopmentRemoteDevelopmentAgentConfigID` is: `"gid://gitlab/RemoteDevelopment::RemoteDevelopmentAgentConfig/1"`. - ### `RemoteDevelopmentWorkspaceID` A `RemoteDevelopmentWorkspaceID` is a global ID. It is encoded as a string. diff --git a/ee/app/finders/remote_development/remote_development_agent_configs_finder.rb b/ee/app/finders/remote_development/remote_development_agent_configs_finder.rb deleted file mode 100644 index 655ded085f0bea13964c3699248caa436a310103..0000000000000000000000000000000000000000 --- a/ee/app/finders/remote_development/remote_development_agent_configs_finder.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -module RemoteDevelopment - class RemoteDevelopmentAgentConfigsFinder - # Executes a query to find agent configurations based on the provided filter arguments. - # - # @param [User, QA::Resource::User] current_user The user making the request. Must have permission - # to access workspaces. - # @param [Array<Integer>] ids A list of specific RemoteDevelopmentAgentConfig IDs to filter by (optional). - # @param [Array<Integer>] cluster_agent_ids A list of ClusterAgent IDs to filter by (optional). - # @return [ActiveRecord::Relation<RemoteDevelopmentAgentConfig>] - # A collection of filtered RemoteDevelopmentAgentConfig records ordered by ID descending. - def self.execute(current_user:, ids: [], cluster_agent_ids: []) - return RemoteDevelopmentAgentConfig.none unless current_user.can?(:access_workspaces_feature) - - filter_arguments = { - ids: ids, - cluster_agent_ids: cluster_agent_ids - } - - filter_argument_types = { - ids: Integer, - cluster_agent_ids: Integer - } - - FilterArgumentValidator.validate_filter_argument_types!(filter_argument_types, filter_arguments) - FilterArgumentValidator.validate_at_least_one_filter_argument_provided!(**filter_arguments) - - collection_proxy = RemoteDevelopmentAgentConfig.all - collection_proxy = collection_proxy.id_in(ids) if ids.present? - collection_proxy = collection_proxy.by_cluster_agent_ids(cluster_agent_ids) if cluster_agent_ids.present? - - collection_proxy.order_id_desc - end - end -end diff --git a/ee/app/graphql/ee/types/clusters/agent_type.rb b/ee/app/graphql/ee/types/clusters/agent_type.rb index ea5a9f524e8c4e1a982b96e7a2f5b15adb439930..cd3d8d8056260eb8a0cbe4ac9b7ae39b46942682 100644 --- a/ee/app/graphql/ee/types/clusters/agent_type.rb +++ b/ee/app/graphql/ee/types/clusters/agent_type.rb @@ -29,14 +29,6 @@ module AgentType resolver: ::Resolvers::RemoteDevelopment::ClusterAgent::WorkspacesResolver, description: 'Workspaces associated with the agent.' - field :remote_development_agent_config, - ::Types::RemoteDevelopment::RemoteDevelopmentAgentConfigType, - extras: [:lookahead], - null: true, - description: 'Remote development agent config for the cluster agent.', - resolver: ::Resolvers::RemoteDevelopment::ClusterAgent::RemoteDevelopmentAgentConfigResolver, - experiment: { milestone: '17.4' } - field :workspaces_agent_config, ::Types::RemoteDevelopment::WorkspacesAgentConfigType, extras: [:lookahead], diff --git a/ee/app/graphql/resolvers/remote_development/cluster_agent/remote_development_agent_config_resolver.rb b/ee/app/graphql/resolvers/remote_development/cluster_agent/remote_development_agent_config_resolver.rb deleted file mode 100644 index 46a91d17d4ce33f7d3377b0b1f094f94219991dd..0000000000000000000000000000000000000000 --- a/ee/app/graphql/resolvers/remote_development/cluster_agent/remote_development_agent_config_resolver.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -module Resolvers - module RemoteDevelopment - module ClusterAgent - class RemoteDevelopmentAgentConfigResolver < ::Resolvers::BaseResolver - include Gitlab::Graphql::Authorize::AuthorizeResource - include LooksAhead - - type Types::RemoteDevelopment::RemoteDevelopmentAgentConfigType, null: true - - alias_method :agent, :object - - # @param [Hash] _args Not used - # @return [RemoteDevelopmentAgentConfig] - def resolve_with_lookahead(**_args) - unless License.feature_available?(:remote_development) - raise_resource_not_available_error! "'remote_development' licensed feature is not available" - end - - raise Gitlab::Access::AccessDeniedError unless can_read_remote_development_agent_config? - - BatchLoader::GraphQL.for(agent.id).batch do |agent_ids, loader| - agent_configs = ::RemoteDevelopment::RemoteDevelopmentAgentConfigsFinder.execute( - current_user: current_user, - cluster_agent_ids: agent_ids - ) - apply_lookahead(agent_configs).each do |agent_config| - # noinspection RubyResolve -- https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-32301 - loader.call(agent_config.cluster_agent_id, agent_config) - end - end - end - - private - - # @return [TrueClass, FalseClass] - def can_read_remote_development_agent_config? - # noinspection RubyNilAnalysis - This is because the superclass #current_user uses #[], which can return nil - current_user.can?(:read_cluster_agent, agent) - end - end - end - end -end diff --git a/ee/app/graphql/types/remote_development/remote_development_agent_config_type.rb b/ee/app/graphql/types/remote_development/remote_development_agent_config_type.rb deleted file mode 100644 index 2d7196d2143e267e35edbe51b7265db44cf4ca64..0000000000000000000000000000000000000000 --- a/ee/app/graphql/types/remote_development/remote_development_agent_config_type.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -module Types - module RemoteDevelopment - class RemoteDevelopmentAgentConfigType < ::Types::BaseObject - graphql_name 'RemoteDevelopmentAgentConfig' - description 'Represents a remote development agent configuration' - - authorize :read_workspaces_agent_config - - field :id, ::Types::GlobalIDType[::RemoteDevelopment::RemoteDevelopmentAgentConfig], - null: false, description: 'Global ID of the remote development agent config.' - - field :cluster_agent, ::Types::Clusters::AgentType, - null: false, description: 'Cluster agent that the remote development agent config belongs to.' - - field :project_id, GraphQL::Types::ID, - null: true, description: 'ID of the project that the remote development agent config belongs to.' - - field :enabled, GraphQL::Types::Boolean, - null: false, description: 'Indicates whether remote development is enabled for the GitLab agent.' - - field :dns_zone, GraphQL::Types::String, - null: false, description: 'DNS zone where workspaces are available.' - - field :network_policy_enabled, GraphQL::Types::Boolean, - null: false, description: 'Whether the network policy of the remote development agent config is enabled.' - - field :gitlab_workspaces_proxy_namespace, GraphQL::Types::String, - null: false, description: 'Namespace where gitlab-workspaces-proxy is installed.' - - field :workspaces_quota, GraphQL::Types::Int, - null: false, description: 'Maximum number of workspaces for the GitLab agent.' - - field :workspaces_per_user_quota, GraphQL::Types::Int, # rubocop:disable GraphQL/ExtractType -- We don't want to extract this to a type, it's just an integer field - null: false, description: 'Maximum number of workspaces per user.' - - field :default_max_hours_before_termination, GraphQL::Types::Int, null: false, - description: 'Default max hours before worksapce termination of the remote development agent config.' - - field :max_hours_before_termination_limit, GraphQL::Types::Int, null: false, - description: 'Max hours before worksapce termination limit of the remote development agent config.' - - field :created_at, Types::TimeType, - null: false, description: 'Timestamp of when the remote development agent config was created.' - - field :updated_at, Types::TimeType, null: false, - description: 'Timestamp of the last update to any mutable remote development agent config property.' - - def max_hours_before_termination_limit - 120 - end - - def default_max_hours_before_termination - 24 - end - end - end -end diff --git a/ee/app/models/ee/clusters/agent.rb b/ee/app/models/ee/clusters/agent.rb index 3cf72dfeed2324b5676c45ffad9687e3d619fa7b..04201c7f216aa2219aeed455228880bc4d650525 100644 --- a/ee/app/models/ee/clusters/agent.rb +++ b/ee/app/models/ee/clusters/agent.rb @@ -15,12 +15,6 @@ module Agent foreign_key: 'cluster_agent_id', inverse_of: :agent - # TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 - has_one :remote_development_agent_config, - class_name: 'RemoteDevelopment::RemoteDevelopmentAgentConfig', - inverse_of: :agent, - foreign_key: :cluster_agent_id - # WARNING: Do not use this `unversioned_latest_workspaces_agent_config` # association unless you are positive that is what you want to do! # diff --git a/ee/app/models/remote_development/remote_development_agent_config.rb b/ee/app/models/remote_development/remote_development_agent_config.rb deleted file mode 100644 index 84ac6300e406732e2f3e65c5d17959103fbacb92..0000000000000000000000000000000000000000 --- a/ee/app/models/remote_development/remote_development_agent_config.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -module RemoteDevelopment - class RemoteDevelopmentAgentConfig < ApplicationRecord - self.table_name = "workspaces_agent_configs" - - # NOTE: See the following comment for the reasoning behind the `RemoteDevelopment` prefix of this table/model: - # https://gitlab.com/gitlab-org/gitlab/-/issues/410045#note_1385602915 - - include Sortable - - ignore_column :max_hours_before_termination_limit, remove_with: '17.11', remove_after: '2025-03-20' - ignore_column :default_max_hours_before_termination, remove_with: '17.11', remove_after: '2025-03-20' - - UNLIMITED_QUOTA = -1 - - belongs_to :agent, - class_name: 'Clusters::Agent', foreign_key: 'cluster_agent_id', inverse_of: :remote_development_agent_config - - # noinspection RailsParamDefResolve - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-31542 - has_many :workspaces, through: :agent, source: :workspaces - - validates :agent, presence: true - validates :dns_zone, hostname: true - validates :enabled, inclusion: { in: [true, false] } - - validates :network_policy_egress, - json_schema: { filename: 'workspaces_agent_configs_network_policy_egress' } - validates :network_policy_egress, 'remote_development/network_policy_egress': true - validates :default_resources_per_workspace_container, - json_schema: { filename: 'workspaces_agent_configs_workspace_container_resources' } - validates :default_resources_per_workspace_container, 'remote_development/workspace_container_resources': true - validates :max_resources_per_workspace, - json_schema: { filename: 'workspaces_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: UNLIMITED_QUOTA } - validates :workspaces_per_user_quota, - numericality: { only_integer: true, greater_than_or_equal_to: UNLIMITED_QUOTA } - validates :allow_privilege_escalation, inclusion: { in: [true, false] } - validates :use_kubernetes_user_namespaces, inclusion: { in: [true, false] } - validates :default_runtime_class, 'remote_development/default_runtime_class': true - validates :annotations, 'remote_development/annotations': true - validates :labels, 'remote_development/labels': true - - scope :by_cluster_agent_ids, ->(ids) { where(cluster_agent_id: ids) } - end -end diff --git a/ee/app/models/remote_development/workspace.rb b/ee/app/models/remote_development/workspace.rb index 98142c71660e34db74ac4ab574845ffdbbb21f3f..da678fba15a605a2b7ab3ffa61585f2a9899fcbd 100644 --- a/ee/app/models/remote_development/workspace.rb +++ b/ee/app/models/remote_development/workspace.rb @@ -20,9 +20,6 @@ class Workspace < ApplicationRecord attribute :desired_config_generator_version, default: ::RemoteDevelopment::WorkspaceOperations::DesiredConfigGeneratorVersion::LATEST_VERSION - # TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 - # noinspection RailsParamDefResolve - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-31542 - has_one :remote_development_agent_config, through: :agent, source: :remote_development_agent_config has_many :workspace_variables, class_name: 'RemoteDevelopment::WorkspaceVariable', inverse_of: :workspace # Currently we only support :environment type for user provided variables has_many :user_provided_workspace_variables, -> { diff --git a/ee/app/policies/remote_development/remote_development_agent_config_policy.rb b/ee/app/policies/remote_development/remote_development_agent_config_policy.rb deleted file mode 100644 index 82d3bc30f641f04ea2bc4a807fc56895b6dc574d..0000000000000000000000000000000000000000 --- a/ee/app/policies/remote_development/remote_development_agent_config_policy.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module RemoteDevelopment - # TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 - class RemoteDevelopmentAgentConfigPolicy < BasePolicy - condition(:can_read_cluster_agent) { can?(:read_cluster_agent, agent) } - - # noinspection RubyResolve -- https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-32336 - rule { can_read_cluster_agent }.enable :read_workspaces_agent_config - - private - - def agent - @subject.agent - end - end -end diff --git a/ee/spec/finders/remote_development/remote_development_agent_configs_finder_spec.rb b/ee/spec/finders/remote_development/remote_development_agent_configs_finder_spec.rb deleted file mode 100644 index 047bccbf7ecd55523c9a9a28c7216ea7674a4093..0000000000000000000000000000000000000000 --- a/ee/spec/finders/remote_development/remote_development_agent_configs_finder_spec.rb +++ /dev/null @@ -1,140 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -# noinspection RubyArgCount -- Rubymine detecting wrong types, it thinks some #create are from Minitest, not FactoryBot -RSpec.describe RemoteDevelopment::RemoteDevelopmentAgentConfigsFinder, feature_category: :workspaces do - let_it_be(:current_user) { create(:user) } - - let_it_be(:cluster_admin_user) { create(:user) } - let_it_be(:agent_a) do - create(:ee_cluster_agent, :with_existing_workspaces_agent_config, created_by_user: cluster_admin_user) - end - - let_it_be(:agent_b) do - create(:ee_cluster_agent, :with_existing_workspaces_agent_config, created_by_user: cluster_admin_user) - end - - let_it_be(:agent_config_a) { agent_a.remote_development_agent_config } - let_it_be(:agent_config_b) { agent_b.remote_development_agent_config } - - subject(:collection_proxy) do - described_class.execute(current_user: current_user, **filter_arguments) - end - - before do - stub_licensed_features(remote_development: true) - allow(::RemoteDevelopment::FilterArgumentValidator).to receive_messages(validate_filter_argument_types!: true, - validate_at_least_one_filter_argument_provided!: true) - end - - context "with ids argument" do - let(:filter_arguments) { { ids: [agent_config_a.id] } } - - it "returns only agent configs matching the specified IDs" do - expect(collection_proxy).to contain_exactly(agent_config_a) - end - end - - context "with cluster_agent_ids argument" do - let(:filter_arguments) { { cluster_agent_ids: [agent_a.id] } } - - it "returns only agent configs matching the specified agent IDs" do - expect(collection_proxy).to contain_exactly(agent_config_a) - end - end - - context "with multiple arguments" do - let(:filter_arguments) do - { - ids: [agent_config_a.id], - cluster_agent_ids: [agent_a.id, agent_b.id] - } - end - - it "handles multiple arguments and still returns all agent configs which match all filter arguments" do - expect(collection_proxy).to contain_exactly(agent_config_a) - end - end - - context "with extra empty filter arguments" do - let(:filter_arguments) do - { - ids: [agent_config_a.id], - cluster_agent_ids: [] - } - end - - it "still uses existing filter arguments" do - expect(collection_proxy).to contain_exactly(agent_config_a) - end - end - - describe "validations" do - context "when no filter arguments are provided" do - before do - allow(::RemoteDevelopment::FilterArgumentValidator).to receive( - :validate_at_least_one_filter_argument_provided! - ).and_raise(ArgumentError.new("At least one filter argument must be provided")) - end - - let(:filter_arguments) { {} } - - it "raises an ArgumentError" do - expect { collection_proxy }.to raise_error(ArgumentError, "At least one filter argument must be provided") - end - end - - context "when an invalid filter argument type is provided" do - let(:expected_exception_message) do - "'ids' must be an Array of 'Integer', " \ - "'cluster_agent_ids' must be an Array of 'Integer'" - end - - before do - allow(::RemoteDevelopment::FilterArgumentValidator).to receive( - :validate_filter_argument_types! - ).and_raise(RuntimeError.new(expected_exception_message)) - end - - context "when argument is not an array" do - let(:filter_arguments) do - { - ids: 1, - cluster_agent_ids: 1 - } - end - - it "raises an RuntimeError", :unlimited_max_formatted_output_length do - expect { collection_proxy.to_a }.to raise_error(RuntimeError, expected_exception_message) - end - end - - context "when array content is wrong type" do - let(:filter_arguments) do - { - ids: %w[a b], - cluster_agent_ids: %w[a b] - } - end - - it "raises an RuntimeError", :unlimited_max_formatted_output_length do - expect { collection_proxy.to_a }.to raise_error(RuntimeError, expected_exception_message) - end - end - end - end - - describe "no workspaces feature" do - before do - stub_licensed_features(remote_development: false) - end - - let(:filter_arguments) { { ids: [agent_config_a.id] } } - - it "returns no agent config" do - expect(collection_proxy).to eq([]) - end - end -end diff --git a/ee/spec/graphql/ee/types/clusters/agent_type_spec.rb b/ee/spec/graphql/ee/types/clusters/agent_type_spec.rb index def2692476080e531318f52a4669234de1eb534c..619c28408c085fe225568ab110d433d00ac7a114 100644 --- a/ee/spec/graphql/ee/types/clusters/agent_type_spec.rb +++ b/ee/spec/graphql/ee/types/clusters/agent_type_spec.rb @@ -7,8 +7,6 @@ expect(described_class).to have_graphql_fields( :vulnerability_images, :workspaces, - # TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 - :remote_development_agent_config, :workspaces_agent_config, :is_receptive, :url_configurations @@ -87,9 +85,6 @@ namespace(fullPath: "#{group.full_path}") { remoteDevelopmentClusterAgents(filter: AVAILABLE) { nodes { - remoteDevelopmentAgentConfig { - workspacesPerUserQuota - } workspacesAgentConfig { workspacesPerUserQuota } @@ -108,27 +103,6 @@ stub_licensed_features(remote_development: true) end - # TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 - describe "for remote_development_agent_config" do - subject(:remote_development_agent_config_result) do - result = GitlabSchema.execute(query, context: { current_user: current_user }).as_json - result.dig('data', 'namespace', 'remoteDevelopmentClusterAgents', 'nodes', 0, 'remoteDevelopmentAgentConfig') - end - - context 'when user is logged in' do - let(:current_user) { user } - let(:expected_workspaces_per_user_quota) do - workspaces_agent_config.workspaces_per_user_quota - end - - it 'returns associated workspaces agent config' do - expect(remote_development_agent_config_result).to eq( - 'workspacesPerUserQuota' => expected_workspaces_per_user_quota - ) - end - end - end - subject(:workspaces_agent_config_result) do result = GitlabSchema.execute(query, context: { current_user: current_user }).as_json result.dig('data', 'namespace', 'remoteDevelopmentClusterAgents', 'nodes', 0, 'workspacesAgentConfig') diff --git a/ee/spec/graphql/resolvers/clusters/agents_resolver_spec.rb b/ee/spec/graphql/resolvers/clusters/agents_resolver_spec.rb index 3964fdddb8e2fcde09cc8d551d535a28e5c0d13c..7a21cbe88047db8090cf33c8301077314c287108 100644 --- a/ee/spec/graphql/resolvers/clusters/agents_resolver_spec.rb +++ b/ee/spec/graphql/resolvers/clusters/agents_resolver_spec.rb @@ -75,29 +75,6 @@ create(:ee_cluster_agent, project: project) end - # TODO: clusterAgent.hasRemoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 - context 'when has_remote_development_agent_config argument is provided' do - let(:params) do - { has_remote_development_agent_config: has_remote_development_agent_config } - end - - context 'when has_remote_development_agent_config is set to true' do - let(:has_remote_development_agent_config) { true } - - it 'returns only agents with remote_development_agent_config' do - expect(subject).to contain_exactly(agent_with_workspaces_agent_config) - end - end - - context 'when has_remote_development_agent_config is set to false' do - let(:has_remote_development_agent_config) { false } - - it 'returns only agents without remote_development_agent_config' do - expect(subject).to contain_exactly(agent_without_workspaces_agent_config) - end - end - end - context 'when has_workspaces_agent_config argument is provided' do let(:params) do { has_workspaces_agent_config: has_workspaces_agent_config } diff --git a/ee/spec/graphql/types/remote_development/remote_development_agent_config_type_spec.rb b/ee/spec/graphql/types/remote_development/remote_development_agent_config_type_spec.rb deleted file mode 100644 index 786ada3d2d2937828ea4ca4cc3b1a395016d4a31..0000000000000000000000000000000000000000 --- a/ee/spec/graphql/types/remote_development/remote_development_agent_config_type_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -# noinspection RubyArgCount -- Rubymine detecting wrong types, it thinks some #create are from Minitest, not FactoryBot -RSpec.describe GitlabSchema.types['RemoteDevelopmentAgentConfig'], feature_category: :workspaces do - let(:fields) do - %i[ - id cluster_agent project_id enabled dns_zone network_policy_enabled gitlab_workspaces_proxy_namespace - workspaces_quota workspaces_per_user_quota default_max_hours_before_termination max_hours_before_termination_limit - created_at updated_at - ] - end - - specify { expect(described_class.graphql_name).to eq('RemoteDevelopmentAgentConfig') } - - specify { expect(described_class).to have_graphql_fields(fields) } - - specify { expect(described_class).to require_graphql_authorizations(:read_workspaces_agent_config) } - - describe 'remote_development_agent_config' do - let_it_be(:group) { create(:group) } - - let_it_be(:query) do - %( - query { - namespace(fullPath: "#{group.full_path}") { - remoteDevelopmentClusterAgents(filter: AVAILABLE) { - nodes { - remoteDevelopmentAgentConfig { - defaultMaxHoursBeforeTermination - } - } - } - } - } - ) - end - - subject(:remote_development_agent_config_result) do - result = GitlabSchema.execute(query, context: { current_user: current_user }).as_json - result.dig('data', 'namespace', 'remoteDevelopmentClusterAgents', 'nodes', 0, 'remoteDevelopmentAgentConfig') - end - - context 'when user is not logged in' do - let(:current_user) { nil } - - it { is_expected.to be_nil } - end - end -end diff --git a/ee/spec/models/remote_development/remote_development_agent_config_spec.rb b/ee/spec/models/remote_development/remote_development_agent_config_spec.rb deleted file mode 100644 index 6cb740bc64bae1d65e27b6e2c0f0bb1931a5034b..0000000000000000000000000000000000000000 --- a/ee/spec/models/remote_development/remote_development_agent_config_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -# TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated - remove in 17.10 - https://gitlab.com/gitlab-org/gitlab/-/issues/480769 -RSpec.describe RemoteDevelopment::RemoteDevelopmentAgentConfig, feature_category: :workspaces do - let_it_be_with_reload(:agent) do - create(:ee_cluster_agent, :with_existing_workspaces_agent_config) - end - - let(:default_default_resources_per_workspace_container) { {} } - let(:default_max_resources_per_workspace) { {} } - let(:default_network_policy_egress) do - [ - { - "allow" => "0.0.0.0/0", - "except" => [ - -"10.0.0.0/8", - -"172.16.0.0/12", - -"192.168.0.0/16" - ] - } - ] - end - - subject(:config) { agent.unversioned_latest_workspaces_agent_config } - - describe 'associations' do - it { is_expected.to belong_to(:agent) } - it { is_expected.to have_many(:workspaces) } - - context 'with associated workspaces' do - let(:workspace_1) { create(:workspace, agent: agent) } - let(:workspace_2) { create(:workspace, agent: agent) } - - it 'has correct associations from factory' do - expect(config.reload.workspaces).to contain_exactly(workspace_1, workspace_2) - expect(workspace_1.remote_development_agent_config).to eq(agent.remote_development_agent_config) - end - end - end - - describe 'validations' do - context 'when config has an invalid dns_zone' do - subject(:config) { build(:workspaces_agent_config, dns_zone: "invalid dns zone") } - - it 'prevents config from being created' do - expect { config.save! }.to raise_error( - ActiveRecord::RecordInvalid, - "Validation failed: Dns zone contains invalid characters (valid characters: [a-z0-9\\-])" - ) - end - end - - it 'when network_policy_egress is not specified explicitly' do - expect(config).to be_valid - expect(config.network_policy_egress).to eq(default_network_policy_egress) - end - - it 'when network_policy_egress is nil' do - # noinspection RubyResolve - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-31542 - config.network_policy_egress = nil - expect(config).not_to be_valid - expect(config.errors[:network_policy_egress]).to include( - 'must be a valid json schema', - 'must be an array' - ) - end - - it 'when default_resources_per_workspace_container is not specified explicitly' do - expect(config).to be_valid - expect(config.default_resources_per_workspace_container).to eq(default_default_resources_per_workspace_container) - end - - it 'when default_resources_per_workspace_container is nil' do - # noinspection RubyResolve - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-31542 - config.default_resources_per_workspace_container = nil - expect(config).not_to be_valid - expect(config.errors[:default_resources_per_workspace_container]).to include( - 'must be a valid json schema', - 'must be a hash' - ) - end - - it 'when max_resources_per_workspace is not specified explicitly' do - expect(config).to be_valid - expect(config.max_resources_per_workspace).to eq(default_max_resources_per_workspace) - end - - it 'when default_resources_per_workspace_container is nil' do - # noinspection RubyResolve - https://handbook.gitlab.com/handbook/tools-and-tips/editors-and-ides/jetbrains-ides/tracked-jetbrains-issues/#ruby-31542 - config.max_resources_per_workspace = nil - expect(config).not_to be_valid - expect(config.errors[:max_resources_per_workspace]).to include( - 'must be a valid json schema', - '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 - is_expected.to validate_numericality_of(:workspaces_per_user_quota).only_integer.is_greater_than_or_equal_to(-1) - end - end -end diff --git a/ee/spec/policies/remote_development/remote_development_agent_config_policy_spec.rb b/ee/spec/policies/remote_development/remote_development_agent_config_policy_spec.rb deleted file mode 100644 index df3cee08aef9dd833a72f670d2c23c2975e8bff2..0000000000000000000000000000000000000000 --- a/ee/spec/policies/remote_development/remote_development_agent_config_policy_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe RemoteDevelopment::RemoteDevelopmentAgentConfigPolicy, feature_category: :workspaces do - include AdminModeHelper - using RSpec::Parameterized::TableSyntax - - let_it_be(:agent_project_creator, refind: true) { create(:user) } - let_it_be(:agent_project, refind: true) { create(:project, creator: agent_project_creator) } - let_it_be(:agent, refind: true) do - create(:ee_cluster_agent, :with_existing_workspaces_agent_config, project: agent_project) - end - - let_it_be(:agent_config) { agent.unversioned_latest_workspaces_agent_config } - - let_it_be(:admin_user, refind: true) { create(:admin) } - let_it_be(:non_admin_user, refind: true) { create(:user) } - # NOTE: The following need to be `let`, not `let_it_be`, because it uses a `let` declaration from the matrix - let(:user) { admin_mode ? admin_user : non_admin_user } - - let(:policy_class) { described_class } - - subject(:policy_instance) { described_class.new(user, agent_config) } - - before do - enable_admin_mode!(user) if admin_mode - agent_project.add_role(user, role_on_agent_project) unless role_on_agent_project == :none - agent_project.reload - - debug = false # Set to true to enable debugging of policies, but change back to false before committing - debug_policies(user, agent_config, policy_class, ability) if debug - end - - shared_examples 'fixture sanity checks' do - it "has fixture sanity checks" do - expect(agent_project.creator_id).not_to eq(user.id) - end - end - - # rubocop:disable Layout/LineLength -- TableSyntax should not be split across lines - where(:admin, :admin_mode, :role_on_agent_project, :allowed) do - # @formatter:off - Turn off RubyMine autoformatting - - # admin | # admin_mode | role_on_agent_project | allowed # check - true | true | :none | true # admin with admin_mode enabled: allowed - true | false | :none | false # admin but admin_mode not enabled: not allowed - false | false | :guest | false # non-admin guest on cluster agent project: not allowed - false | false | :planner | false # non-admin planner on cluster agent project: not allowed - false | false | :reporter | false # non-admin planner on cluster agent project: not allowed - false | false | :developer | true # non-admin developer on cluster agent project: allowed - false | false | :maintainer | true # non-admin maintainer on cluster agent project : allowed - - # @formatter:on - end - # rubocop:enable Layout/LineLength - - with_them do - describe "read_workspaces_agent_config ability" do - let(:ability) { :read_workspaces_agent_config } - - it_behaves_like 'fixture sanity checks' - - it { is_expected.to(allowed ? be_allowed(ability) : be_disallowed(ability)) } - end - end - - # NOTE: Leaving this method here for future use. You can also set GITLAB_DEBUG_POLICIES=1. For more details, see: - # https://docs.gitlab.com/ee/development/permissions/custom_roles.html#refactoring-abilities - # This may be generalized in the future for use across all policy specs - # Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/463453 - def debug_policies(user, agent_config, policy_class, ability) - puts "\n\nPolicy debug for #{policy_class} policy:\n" - puts "user: #{user.username} (id: #{user.id}, admin: #{user.admin?}, " \ - "admin_mode: #{user && Gitlab::Auth::CurrentUserMode.new(user).admin_mode?}" \ - ")\n" - - policy = policy_class.new(user, agent_config) - puts "debugging :#{ability} ability:\n\n" - pp policy.debug(ability) - puts "\n\n" - end -end diff --git a/ee/spec/requests/api/graphql/remote_development/README.md b/ee/spec/requests/api/graphql/remote_development/README.md index b09cfcb0a0207dcf313eb7a443e7886e8176eca3..095ee2d966a8f507af9fde289c71c2fe9b3c1687 100644 --- a/ee/spec/requests/api/graphql/remote_development/README.md +++ b/ee/spec/requests/api/graphql/remote_development/README.md @@ -17,12 +17,6 @@ Here are the related spec folders for the fields (in alphabetical order by resol - Resolver source file for `tests.yml` and `verify-tff-mapping`: `ee/app/graphql/resolvers/remote_development/workspaces_admin_resolver.rb` - Notes: Only admins may use this field. -- GraphQL Field: `Query.project.clusterAgent.remoteDevelopmentAgentConfig` - - Spec folder: `ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config` - - API docs: https://docs.gitlab.com/ee/api/graphql/reference/#clusteragentremotedevelopmentagentconfig - - Resolver source file for `tests.yml` and `verify-tff-mapping`: `ee/app/graphql/resolvers/remote_development/cluster_agent/remote_development_agent_config_resolver.rb` - - Note: THIS FIELD IS DEPRECATED, AND WILL BE REMOVED IN A FUTURE RELEASE. - - Field: `Query.project.clusterAgent.workspaces` - Spec folder: `ee/spec/requests/api/graphql/remote_development/cluster_agent/workspaces` - API docs: https://docs.gitlab.com/ee/api/graphql/reference/#clusteragentworkspaces diff --git a/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/TODO_DEPRECATED.md b/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/TODO_DEPRECATED.md deleted file mode 100644 index 2fed024ee29ee6f0eeff6daccd6436d69b37016a..0000000000000000000000000000000000000000 --- a/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/TODO_DEPRECATED.md +++ /dev/null @@ -1,6 +0,0 @@ -TODO: clusterAgent.remoteDevelopmentAgentConfig GraphQL is deprecated. - -Remove this entire folder `ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config` -and its contents in 18.0 - -https://gitlab.com/gitlab-org/gitlab/-/issues/509049 diff --git a/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/shared.rb b/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/shared.rb deleted file mode 100644 index abd965c0dc7b7d33690d03eef368f12b2aedd807..0000000000000000000000000000000000000000 --- a/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/shared.rb +++ /dev/null @@ -1,87 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../shared' - -RSpec.shared_context 'for a Query.project.clusterAgent.remoteDevelopmentAgentConfig query' do - include GraphqlHelpers - - let_it_be(:project) { create(:project, :in_group) } - let_it_be(:agent) { create(:cluster_agent, project: project) } - let_it_be(:remote_development_agent_config) { create(:workspaces_agent_config, agent: agent) } - - let_it_be(:authorized_user) do - # create the minimum privileged user that should have the project and namespace - # permissions to access the remote_development_agent_config. - create(:user, developer_of: project.namespace) - end - - let_it_be(:unauthorized_user) do - # create the maximum privileged user that should NOT have the project and namespace - # permissions to access the agent. - create(:user, reporter_of: project.namespace) - end - - let_it_be(:unauthorized_remote_development_agent_config) { create(:workspaces_agent_config) } - - let(:args) { { full_path: project.full_path } } - let(:attributes) { { name: agent.name } } - let(:fields) do - query_graphql_field( - :cluster_agent, - attributes, - [ - query_graphql_field( - :remote_development_agent_config, - all_graphql_fields_for("remote_development_agent_configs".classify, max_depth: 1) - ) - ] - ) - end - - let(:query) { graphql_query_for(:project, args, fields) } - - subject(:actual_remote_development_agent_config) do - graphql_dig_at(graphql_data, :project, :clusterAgent, :remoteDevelopmentAgentConfig) - end -end - -RSpec.shared_examples 'single remoteDevelopmentAgentConfig query' do - include_context 'in licensed environment' - - context 'when user is authorized' do - include_context 'with authorized user as current user' - - it_behaves_like 'query is a working graphql query' - it_behaves_like 'query returns single remote_development_agent_config' - - context 'when the user requests a remote_development_agent_config that they are not authorized for' do - let(:agent) { unauthorized_remote_development_agent_config.agent } - let(:project) { agent.project } - - it_behaves_like 'query is a working graphql query' - it_behaves_like 'query returns blank' - end - end - - context 'when user is not authorized' do - include_context 'with unauthorized user as current user' - - it_behaves_like 'query is a working graphql query' - it_behaves_like 'query returns blank' - end - - it_behaves_like 'query in unlicensed environment' -end - -RSpec.shared_examples 'query returns single remote_development_agent_config' do - include GraphqlHelpers - - before do - post_graphql(query, current_user: current_user) - end - - it "returns correct object" do - expect(actual_remote_development_agent_config.fetch('id')) - .to eq("gid://gitlab/RemoteDevelopment::RemoteDevelopmentAgentConfig/#{remote_development_agent_config.id}") - end -end diff --git a/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/with_no_args_spec.rb b/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/with_no_args_spec.rb deleted file mode 100644 index bdcab3be29559540fdf52bf0052979acf688eddb..0000000000000000000000000000000000000000 --- a/ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/with_no_args_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require_relative './shared' - -# NOTE: Even though this `single remoteDevelopmentAgentConfig` spec only has no fields to test, we still use similar -# shared examples patterns and structure as the other multi-model query specs, for consistency. - -RSpec.describe 'Query.project.clusterAgent.remoteDevelopmentAgentConfig', feature_category: :workspaces do - include_context 'for a Query.project.clusterAgent.remoteDevelopmentAgentConfig query' - - it_behaves_like 'single remoteDevelopmentAgentConfig query' -end diff --git a/scripts/verify-tff-mapping b/scripts/verify-tff-mapping index e2c11409cb1c3fe7e505d5253d2e2872dffda6dc..7c99936e7023f4d9ffc5d6156720a9ee7652e0a8 100755 --- a/scripts/verify-tff-mapping +++ b/scripts/verify-tff-mapping @@ -466,15 +466,6 @@ tests = [ ## END Remote development GraphQL mutations ## BEGIN Remote development GraphQL resolvers (in alphabetical order by resolver source file path) - { - explanation: - 'Map Remote Development GraphQL cluster_agent/remote_development_agent_config_resolver.rb to request specs', - changed_file: - 'ee/app/graphql/resolvers/remote_development/cluster_agent/remote_development_agent_config_resolver.rb', - expected: %w[ - ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/with_no_args_spec.rb - ] - }, { explanation: 'Map Remote Development GraphQL cluster_agent/workspaces_resolver.rb to request specs', diff --git a/tests.yml b/tests.yml index 3d482386923959994dd3e53f98df49f78c2bddbb..8d100fa8345e173f7a522d4f465c9332941327eb 100644 --- a/tests.yml +++ b/tests.yml @@ -127,10 +127,6 @@ mapping: - 'ee/spec/requests/api/graphql/remote_development/workspaces/*_spec.rb' - 'ee/spec/requests/api/graphql/remote_development/workspace_variables/*_spec.rb' - - source: 'ee/app/graphql/resolvers/remote_development/cluster_agent/remote_development_agent_config_resolver\.rb' - test: - - 'ee/spec/requests/api/graphql/remote_development/cluster_agent/remote_development_agent_config/*_spec.rb' - - source: 'ee/app/graphql/resolvers/remote_development/cluster_agent/workspaces_agent_config_resolver\.rb' test: - 'ee/spec/requests/api/graphql/remote_development/cluster_agent/workspaces_agent_config/*_spec.rb'