2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2018-11-21 04:33:34 -05:00
|
|
|
|
|
|
|
describe Clusters::Applications::CertManager do
|
2019-07-30 09:12:16 -04:00
|
|
|
let(:cert_manager) { create(:clusters_applications_cert_manager) }
|
2018-11-21 04:33:34 -05:00
|
|
|
|
2019-07-30 09:12:16 -04:00
|
|
|
include_examples 'cluster application core specs', :clusters_applications_cert_manager
|
|
|
|
include_examples 'cluster application status specs', :clusters_applications_cert_manager
|
|
|
|
include_examples 'cluster application version specs', :clusters_applications_cert_manager
|
2019-02-06 06:05:21 -05:00
|
|
|
include_examples 'cluster application initial status specs'
|
2018-11-21 04:33:34 -05:00
|
|
|
|
2019-04-12 01:42:48 -04:00
|
|
|
describe '#can_uninstall?' do
|
|
|
|
subject { cert_manager.can_uninstall? }
|
|
|
|
|
2019-07-25 02:23:50 -04:00
|
|
|
it { is_expected.to be_truthy }
|
2019-04-12 01:42:48 -04:00
|
|
|
end
|
|
|
|
|
2018-11-21 04:33:34 -05:00
|
|
|
describe '#install_command' do
|
2019-03-31 18:55:08 -04:00
|
|
|
let(:cert_email) { 'admin@example.com' }
|
|
|
|
|
|
|
|
let(:cluster_issuer_file) do
|
|
|
|
file_contents = <<~EOF
|
|
|
|
---
|
|
|
|
apiVersion: certmanager.k8s.io/v1alpha1
|
|
|
|
kind: ClusterIssuer
|
|
|
|
metadata:
|
|
|
|
name: letsencrypt-prod
|
|
|
|
spec:
|
|
|
|
acme:
|
|
|
|
server: https://acme-v02.api.letsencrypt.org/directory
|
|
|
|
email: #{cert_email}
|
|
|
|
privateKeySecretRef:
|
|
|
|
name: letsencrypt-prod
|
|
|
|
http01: {}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
{ "cluster_issuer.yaml": file_contents }
|
|
|
|
end
|
|
|
|
|
2018-11-21 04:33:34 -05:00
|
|
|
subject { cert_manager.install_command }
|
|
|
|
|
|
|
|
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'is initialized with cert_manager arguments' do
|
2018-11-21 04:33:34 -05:00
|
|
|
expect(subject.name).to eq('certmanager')
|
2019-08-30 07:47:13 -04:00
|
|
|
expect(subject.chart).to eq('certmanager/cert-manager')
|
|
|
|
expect(subject.repository).to eq('https://charts.jetstack.io')
|
|
|
|
expect(subject.version).to eq('v0.9.1')
|
2019-01-03 08:41:53 -05:00
|
|
|
expect(subject).to be_rbac
|
2018-11-21 04:33:34 -05:00
|
|
|
expect(subject.files).to eq(cert_manager.files.merge(cluster_issuer_file))
|
2019-08-30 07:47:13 -04:00
|
|
|
expect(subject.preinstall).to eq([
|
|
|
|
'kubectl apply -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.9/deploy/manifests/00-crds.yaml',
|
|
|
|
'kubectl label --overwrite namespace gitlab-managed-apps certmanager.k8s.io/disable-validation=true'
|
|
|
|
])
|
|
|
|
expect(subject.postinstall).to eq([
|
2019-11-03 22:06:27 -05:00
|
|
|
"for i in $(seq 1 90); do kubectl apply -f /data/helm/certmanager/config/cluster_issuer.yaml && s=0 && break || s=$?; sleep 1s; echo \"Retrying ($i)...\"; done; (exit $s)"
|
2019-08-30 07:47:13 -04:00
|
|
|
])
|
2018-11-21 04:33:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a specific user' do
|
2019-03-31 18:55:08 -04:00
|
|
|
let(:cert_email) { 'abc@xyz.com' }
|
|
|
|
|
2018-11-21 04:33:34 -05:00
|
|
|
before do
|
2019-03-31 18:55:08 -04:00
|
|
|
cert_manager.email = cert_email
|
2018-11-21 04:33:34 -05:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'uses his/her email to register issuer with certificate provider' do
|
2018-11-21 04:33:34 -05:00
|
|
|
expect(subject.files).to eq(cert_manager.files.merge(cluster_issuer_file))
|
2018-11-21 06:39:29 -05:00
|
|
|
end
|
2018-11-21 04:33:34 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 08:41:53 -05:00
|
|
|
context 'on a non rbac enabled cluster' do
|
2018-11-21 04:33:34 -05:00
|
|
|
before do
|
2019-01-03 08:41:53 -05:00
|
|
|
cert_manager.cluster.platform_kubernetes.abac!
|
2018-11-21 04:33:34 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 08:41:53 -05:00
|
|
|
it { is_expected.not_to be_rbac }
|
2018-11-21 04:33:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'application failed to install previously' do
|
2019-07-30 09:12:16 -04:00
|
|
|
let(:cert_manager) { create(:clusters_applications_cert_manager, :errored, version: '0.0.1') }
|
2018-11-21 04:33:34 -05:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'is initialized with the locked version' do
|
2019-08-30 07:47:13 -04:00
|
|
|
expect(subject.version).to eq('v0.9.1')
|
2018-11-21 04:33:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-25 02:23:50 -04:00
|
|
|
describe '#uninstall_command' do
|
|
|
|
subject { cert_manager.uninstall_command }
|
|
|
|
|
|
|
|
it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::DeleteCommand) }
|
|
|
|
|
|
|
|
it 'is initialized with cert_manager arguments' do
|
|
|
|
expect(subject.name).to eq('certmanager')
|
|
|
|
expect(subject).to be_rbac
|
|
|
|
expect(subject.files).to eq(cert_manager.files)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'specifies a post delete command to remove custom resource definitions' do
|
|
|
|
expect(subject.postdelete).to eq([
|
2019-08-30 07:47:13 -04:00
|
|
|
'kubectl delete secret -n gitlab-managed-apps letsencrypt-prod --ignore-not-found',
|
2019-07-25 02:23:50 -04:00
|
|
|
'kubectl delete crd certificates.certmanager.k8s.io --ignore-not-found',
|
2019-08-30 07:47:13 -04:00
|
|
|
'kubectl delete crd certificaterequests.certmanager.k8s.io --ignore-not-found',
|
|
|
|
'kubectl delete crd challenges.certmanager.k8s.io --ignore-not-found',
|
2019-07-25 02:23:50 -04:00
|
|
|
'kubectl delete crd clusterissuers.certmanager.k8s.io --ignore-not-found',
|
2019-08-30 07:47:13 -04:00
|
|
|
'kubectl delete crd issuers.certmanager.k8s.io --ignore-not-found',
|
|
|
|
'kubectl delete crd orders.certmanager.k8s.io --ignore-not-found'
|
2019-07-25 02:23:50 -04:00
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'secret key name is not found' do
|
|
|
|
before do
|
|
|
|
allow(File).to receive(:read).and_call_original
|
|
|
|
expect(File).to receive(:read)
|
|
|
|
.with(Rails.root.join('vendor', 'cert_manager', 'cluster_issuer.yaml'))
|
|
|
|
.and_return('key: value')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not try and delete the secret' do
|
|
|
|
expect(subject.postdelete).to eq([
|
|
|
|
'kubectl delete crd certificates.certmanager.k8s.io --ignore-not-found',
|
2019-08-30 07:47:13 -04:00
|
|
|
'kubectl delete crd certificaterequests.certmanager.k8s.io --ignore-not-found',
|
|
|
|
'kubectl delete crd challenges.certmanager.k8s.io --ignore-not-found',
|
2019-07-25 02:23:50 -04:00
|
|
|
'kubectl delete crd clusterissuers.certmanager.k8s.io --ignore-not-found',
|
2019-08-30 07:47:13 -04:00
|
|
|
'kubectl delete crd issuers.certmanager.k8s.io --ignore-not-found',
|
|
|
|
'kubectl delete crd orders.certmanager.k8s.io --ignore-not-found'
|
2019-07-25 02:23:50 -04:00
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 04:33:34 -05:00
|
|
|
describe '#files' do
|
|
|
|
let(:application) { cert_manager }
|
|
|
|
let(:values) { subject[:'values.yaml'] }
|
|
|
|
|
|
|
|
subject { application.files }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'includes cert_manager specific keys in the values.yaml file' do
|
2018-11-21 04:33:34 -05:00
|
|
|
expect(values).to include('ingressShim')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:email) }
|
|
|
|
end
|
|
|
|
end
|