Commit da5c00d1 authored by Tiger's avatar Tiger

Remove Kubernetes service from deployment platform

This will no longer be used for deployments, as all
service templates have been migrated to clusters.
parent 148516ba
......@@ -14,9 +14,7 @@ module DeploymentPlatform
def find_deployment_platform(environment)
find_cluster_platform_kubernetes(environment: environment) ||
find_group_cluster_platform_kubernetes_with_feature_guard(environment: environment) ||
find_instance_cluster_platform_kubernetes_with_feature_guard(environment: environment) ||
find_kubernetes_service_integration ||
build_cluster_and_deployment_platform
find_instance_cluster_platform_kubernetes_with_feature_guard(environment: environment)
end
# EE would override this and utilize environment argument
......@@ -48,39 +46,4 @@ module DeploymentPlatform
Clusters::Instance.new.clusters.enabled.default_environment
.first&.platform_kubernetes
end
def find_kubernetes_service_integration
services.deployment.reorder(nil).find_by(active: true)
end
def build_cluster_and_deployment_platform
return unless kubernetes_service_template
cluster = ::Clusters::Cluster.create(cluster_attributes_from_service_template)
cluster.platform_kubernetes if cluster.persisted?
end
def kubernetes_service_template
@kubernetes_service_template ||= KubernetesService.active.find_by_template
end
def cluster_attributes_from_service_template
{
name: 'kubernetes-template',
projects: [self],
cluster_type: :project_type,
provider_type: :user,
platform_type: :kubernetes,
platform_kubernetes_attributes: platform_kubernetes_attributes_from_service_template
}
end
def platform_kubernetes_attributes_from_service_template
{
api_url: kubernetes_service_template.api_url,
ca_pem: kubernetes_service_template.ca_pem,
token: kubernetes_service_template.token,
namespace: kubernetes_service_template.namespace
}
end
end
---
title: Remove Kubernetes service template from available deployment platforms
merge_request: 29786
author:
type: removed
......@@ -8,40 +8,7 @@ describe DeploymentPlatform do
describe '#deployment_platform' do
subject { project.deployment_platform }
context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service and a Kubernetes template configured' do
let!(:kubernetes_service) { create(:kubernetes_service, template: true) }
it 'returns a platform kubernetes' do
expect(subject).to be_a_kind_of(Clusters::Platforms::Kubernetes)
end
it 'creates a cluster and a platform kubernetes' do
expect { subject }
.to change { Clusters::Cluster.count }.by(1)
.and change { Clusters::Platforms::Kubernetes.count }.by(1)
end
it 'includes appropriate attributes for Cluster' do
cluster = subject.cluster
expect(cluster.name).to eq('kubernetes-template')
expect(cluster.project).to eq(project)
expect(cluster.provider_type).to eq('user')
expect(cluster.platform_type).to eq('kubernetes')
end
it 'creates a platform kubernetes' do
expect { subject }.to change { Clusters::Platforms::Kubernetes.count }.by(1)
end
it 'copies attributes from Clusters::Platform::Kubernetes template into the new Cluster::Platforms::Kubernetes' do
expect(subject.api_url).to eq(kubernetes_service.api_url)
expect(subject.ca_pem).to eq(kubernetes_service.ca_pem)
expect(subject.token).to eq(kubernetes_service.token)
expect(subject.namespace).to eq(kubernetes_service.namespace)
end
end
context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service and no Kubernetes template configured' do
context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service' do
it { is_expected.to be_nil }
end
......@@ -126,23 +93,5 @@ describe DeploymentPlatform do
end
end
end
context 'when user configured kubernetes integration from project services' do
let!(:kubernetes_service) { create(:kubernetes_service, project: project) }
it 'returns the Kubernetes service' do
expect(subject).to eq(kubernetes_service)
end
end
context 'when the cluster creation fails' do
let!(:kubernetes_service) { create(:kubernetes_service, template: true) }
before do
allow_any_instance_of(Clusters::Cluster).to receive(:persisted?).and_return(false)
end
it { is_expected.to be_nil }
end
end
end
......@@ -7,7 +7,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
let(:project) { create(:kubernetes_project) }
let(:service) { project.deployment_platform }
let(:service) { create(:kubernetes_service, project: project) }
describe 'Associations' do
it { is_expected.to belong_to :project }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment