From a3ed0d253d757d99846c18f84efe110d14ba79ec Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Apr 2022 06:08:45 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- app/services/ci/generate_kubeconfig_service.rb | 11 ++++++----- doc/administration/audit_events.md | 2 +- lib/gitlab/ci/variables/builder.rb | 2 +- spec/lib/gitlab/ci/variables/builder_spec.rb | 2 +- spec/services/ci/generate_kubeconfig_service_spec.rb | 5 +++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/services/ci/generate_kubeconfig_service.rb b/app/services/ci/generate_kubeconfig_service.rb index 18f68c0ff09..894ab8e8505 100644 --- a/app/services/ci/generate_kubeconfig_service.rb +++ b/app/services/ci/generate_kubeconfig_service.rb @@ -2,8 +2,9 @@ module Ci class GenerateKubeconfigService - def initialize(build) - @build = build + def initialize(pipeline, token:) + @pipeline = pipeline + @token = token @template = Gitlab::Kubernetes::Kubeconfig::Template.new end @@ -33,10 +34,10 @@ module Ci private - attr_reader :build, :template + attr_reader :pipeline, :token, :template def agents - build.pipeline.authorized_cluster_agents + pipeline.authorized_cluster_agents end def cluster_name @@ -52,7 +53,7 @@ module Ci end def agent_token(agent) - ['ci', agent.id, build.token].join(delimiter) + ['ci', agent.id, token].join(delimiter) end def delimiter diff --git a/doc/administration/audit_events.md b/doc/administration/audit_events.md index 955f7a6a830..ad937146af3 100644 --- a/doc/administration/audit_events.md +++ b/doc/administration/audit_events.md @@ -33,7 +33,7 @@ permission level, who added a new user, or who removed a user. ## Retention policy There is no retention policy in place for audit events. -See the [Specify a retention period for audit events](https://gitlab.com/gitlab-org/gitlab/-/issues/8137) for more information. +See the [Specify a retention period for audit events](https://gitlab.com/groups/gitlab-org/-/epics/7917) for more information. ## List of events diff --git a/lib/gitlab/ci/variables/builder.rb b/lib/gitlab/ci/variables/builder.rb index bcb1fe83ea2..a452cb197ae 100644 --- a/lib/gitlab/ci/variables/builder.rb +++ b/lib/gitlab/ci/variables/builder.rb @@ -52,7 +52,7 @@ module Gitlab # https://gitlab.com/groups/gitlab-org/configure/-/epics/8 # Until then, we need to make both the old and the new KUBECONFIG contexts available collection.concat(deployment_variables(environment: environment, job: job)) - template = ::Ci::GenerateKubeconfigService.new(job).execute + template = ::Ci::GenerateKubeconfigService.new(pipeline, token: job.token).execute kubeconfig_yaml = collection['KUBECONFIG']&.value template.merge_yaml(kubeconfig_yaml) if kubeconfig_yaml.present? diff --git a/spec/lib/gitlab/ci/variables/builder_spec.rb b/spec/lib/gitlab/ci/variables/builder_spec.rb index b9aa5f7c431..e13a0993fa8 100644 --- a/spec/lib/gitlab/ci/variables/builder_spec.rb +++ b/spec/lib/gitlab/ci/variables/builder_spec.rb @@ -246,7 +246,7 @@ RSpec.describe Gitlab::Ci::Variables::Builder do subject { builder.kubernetes_variables(environment: nil, job: job) } before do - allow(Ci::GenerateKubeconfigService).to receive(:new).with(job).and_return(service) + allow(Ci::GenerateKubeconfigService).to receive(:new).with(job.pipeline, token: job.token).and_return(service) end it { is_expected.to include(key: 'KUBECONFIG', value: 'example-kubeconfig', public: false, file: true) } diff --git a/spec/services/ci/generate_kubeconfig_service_spec.rb b/spec/services/ci/generate_kubeconfig_service_spec.rb index b0673d16158..e3088ca6ea7 100644 --- a/spec/services/ci/generate_kubeconfig_service_spec.rb +++ b/spec/services/ci/generate_kubeconfig_service_spec.rb @@ -6,16 +6,17 @@ RSpec.describe Ci::GenerateKubeconfigService do describe '#execute' do let(:project) { create(:project) } let(:build) { create(:ci_build, project: project) } + let(:pipeline) { build.pipeline } let(:agent1) { create(:cluster_agent, project: project) } let(:agent2) { create(:cluster_agent) } let(:template) { instance_double(Gitlab::Kubernetes::Kubeconfig::Template) } - subject { described_class.new(build).execute } + subject { described_class.new(pipeline, token: build.token).execute } before do expect(Gitlab::Kubernetes::Kubeconfig::Template).to receive(:new).and_return(template) - expect(build.pipeline).to receive(:authorized_cluster_agents).and_return([agent1, agent2]) + expect(pipeline).to receive(:authorized_cluster_agents).and_return([agent1, agent2]) end it 'adds a cluster, and a user and context for each available agent' do