mirror of
https://github.com/czhu12/canine.git
synced 2026-05-07 12:19:58 -05:00
updated add ons install
This commit is contained in:
@@ -12,7 +12,7 @@ class AddOns::UninstallHelmChart
|
||||
end
|
||||
|
||||
client = K8::Client.new(connection)
|
||||
if (namespace = client.get_namespaces.find { |n| n.metadata.name == add_on.name }).present?
|
||||
if add_on.managed_namespace? && (namespace = client.get_namespaces.find { |n| n.metadata.name == add_on.namespace }).present?
|
||||
client.delete_namespace(namespace.metadata.name)
|
||||
end
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ class AddOnsController < ApplicationController
|
||||
|
||||
# POST /add_ons or /add_ons.json
|
||||
def create
|
||||
params = AddOns::Create.parse_params(params)
|
||||
result = AddOns::Create.call(AddOn.new(params), user)
|
||||
add_on_params = AddOns::Create.parse_params(params)
|
||||
result = AddOns::Create.call(AddOn.new(add_on_params), current_user)
|
||||
@add_on = result.add_on
|
||||
# Uncomment to authorize with Pundit
|
||||
# authorize @add_on
|
||||
|
||||
@@ -16,7 +16,9 @@ class Projects::DeploymentJob < ApplicationJob
|
||||
end
|
||||
|
||||
# Create namespace
|
||||
apply_namespace(project, kubectl)
|
||||
if project.managed_namespace?
|
||||
apply_namespace(project, kubectl)
|
||||
end
|
||||
|
||||
# Upload container registry secrets
|
||||
upload_registry_secrets(kubectl, deployment)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
class Projects::DestroyJob < ApplicationJob
|
||||
def perform(project, user)
|
||||
project.destroying!
|
||||
delete_namespace(project, user)
|
||||
if project.managed_namespace
|
||||
delete_namespace(project, user)
|
||||
end
|
||||
|
||||
# Delete the github webhook for the project IF there are no more projects that refer to that repository
|
||||
# TODO: This might have overlapping repository urls across different providers.
|
||||
@@ -14,11 +16,9 @@ class Projects::DestroyJob < ApplicationJob
|
||||
end
|
||||
|
||||
def delete_namespace(project, user)
|
||||
if project.managed_namespace
|
||||
client = K8::Client.new(K8::Connection.new(project.cluster, user))
|
||||
if (namespace = client.get_namespaces.find { |n| n.metadata.name == project.namespace }).present?
|
||||
client.delete_namespace(namespace.metadata.name)
|
||||
end
|
||||
client = K8::Client.new(K8::Connection.new(project.cluster, user))
|
||||
if (namespace = client.get_namespaces.find { |n| n.metadata.name == project.namespace }).present?
|
||||
client.delete_namespace(namespace.metadata.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: <%= nameable.name %>
|
||||
name: <%= nameable.namespace %>
|
||||
labels:
|
||||
caninemanaged: 'true'
|
||||
|
||||
@@ -18,6 +18,23 @@ RSpec.describe AddOns::UninstallHelmChart do
|
||||
end
|
||||
|
||||
describe '#execute' do
|
||||
context 'with an unmanaged namespace' do
|
||||
let(:add_on) { create(:add_on, managed_namespace: false) }
|
||||
it 'does not delete the namespace' do
|
||||
expect(client).not_to receive(:delete_namespace)
|
||||
described_class.execute(connection:)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a managed namespace' do
|
||||
it 'deletes the namespace' do
|
||||
allow(client).to receive(:get_namespaces).and_return([ OpenStruct.new(metadata: OpenStruct.new(name: add_on.namespace)) ])
|
||||
expect(client).to receive(:delete_namespace)
|
||||
|
||||
described_class.execute(connection:)
|
||||
end
|
||||
end
|
||||
|
||||
it 'uninstalls the helm chart successfully' do
|
||||
expect(add_on).to receive(:uninstalled!)
|
||||
expect(add_on).to receive(:destroy!)
|
||||
|
||||
Reference in New Issue
Block a user