Commit 4ebcacfb authored by Mike Greiling's avatar Mike Greiling Committed by Paul Slaughter

Remove gitlab-managed-app namespace after helm is uninstalled

After uninstalling Helm we can also clear out everything
under the `gitlab-managed-apps` namespace as well as the
tiller-admin clusterrolebinding.

This contributes to https://gitlab.com/gitlab-org/gitlab/issues/26815
parent f281e8c8
...@@ -5,8 +5,14 @@ import trackUninstallButtonClickMixin from 'ee_else_ce/clusters/mixins/track_uni ...@@ -5,8 +5,14 @@ import trackUninstallButtonClickMixin from 'ee_else_ce/clusters/mixins/track_uni
import { HELM, INGRESS, CERT_MANAGER, PROMETHEUS, RUNNER, KNATIVE, JUPYTER } from '../constants'; import { HELM, INGRESS, CERT_MANAGER, PROMETHEUS, RUNNER, KNATIVE, JUPYTER } from '../constants';
const CUSTOM_APP_WARNING_TEXT = { const CUSTOM_APP_WARNING_TEXT = {
[HELM]: s__( [HELM]: sprintf(
'ClusterIntegration|The associated Tiller pod will be deleted and cannot be restored.', s__(
'ClusterIntegration|The associated Tiller pod, the %{gitlabManagedAppsNamespace} namespace, and all of its resources will be deleted and cannot be restored.',
),
{
gitlabManagedAppsNamespace: '<code>gitlab-managed-apps</code>',
},
false,
), ),
[INGRESS]: s__( [INGRESS]: s__(
'ClusterIntegration|The associated load balancer and IP will be deleted and cannot be restored.', 'ClusterIntegration|The associated load balancer and IP will be deleted and cannot be restored.',
...@@ -76,6 +82,7 @@ export default { ...@@ -76,6 +82,7 @@ export default {
:modal-id="modalId" :modal-id="modalId"
:title="title" :title="title"
@ok="confirmUninstall()" @ok="confirmUninstall()"
>{{ warningText }} {{ customAppWarningText }}</gl-modal
> >
{{ warningText }} <span v-html="customAppWarningText"></span>
</gl-modal>
</template> </template>
...@@ -68,6 +68,13 @@ module Clusters ...@@ -68,6 +68,13 @@ module Clusters
ca_key.present? && ca_cert.present? ca_key.present? && ca_cert.present?
end end
def post_uninstall
cluster.kubeclient.delete_namespace(Gitlab::Kubernetes::Helm::NAMESPACE)
rescue Kubeclient::ResourceNotFoundError
# we actually don't care if the namespace is not present
# since we want to delete it anyway.
end
private private
def files def files
......
...@@ -18,7 +18,8 @@ module Gitlab ...@@ -18,7 +18,8 @@ module Gitlab
def generate_script def generate_script
super + [ super + [
reset_helm_command, reset_helm_command,
delete_tiller_replicaset delete_tiller_replicaset,
delete_tiller_clusterrolebinding
].join("\n") ].join("\n")
end end
...@@ -43,6 +44,12 @@ module Gitlab ...@@ -43,6 +44,12 @@ module Gitlab
Gitlab::Kubernetes::KubectlCmd.delete(*delete_args) Gitlab::Kubernetes::KubectlCmd.delete(*delete_args)
end end
def delete_tiller_clusterrolebinding
delete_args = %w[clusterrolebinding tiller-admin]
Gitlab::Kubernetes::KubectlCmd.delete(*delete_args)
end
def reset_helm_command def reset_helm_command
command = %w[helm reset] + optional_tls_flags command = %w[helm reset] + optional_tls_flags
......
...@@ -39,6 +39,7 @@ module Gitlab ...@@ -39,6 +39,7 @@ module Gitlab
:get_secret, :get_secret,
:get_service, :get_service,
:get_service_account, :get_service_account,
:delete_namespace,
:delete_pod, :delete_pod,
:create_config_map, :create_config_map,
:create_namespace, :create_namespace,
......
...@@ -3703,7 +3703,7 @@ msgstr "" ...@@ -3703,7 +3703,7 @@ msgstr ""
msgid "ClusterIntegration|The associated IP and all deployed services will be deleted and cannot be restored. Uninstalling Knative will also remove Istio from your cluster. This will not effect any other applications." msgid "ClusterIntegration|The associated IP and all deployed services will be deleted and cannot be restored. Uninstalling Knative will also remove Istio from your cluster. This will not effect any other applications."
msgstr "" msgstr ""
msgid "ClusterIntegration|The associated Tiller pod will be deleted and cannot be restored." msgid "ClusterIntegration|The associated Tiller pod, the %{gitlabManagedAppsNamespace} namespace, and all of its resources will be deleted and cannot be restored."
msgstr "" msgstr ""
msgid "ClusterIntegration|The associated load balancer and IP will be deleted and cannot be restored." msgid "ClusterIntegration|The associated load balancer and IP will be deleted and cannot be restored."
......
...@@ -15,6 +15,7 @@ describe Gitlab::Kubernetes::Helm::ResetCommand do ...@@ -15,6 +15,7 @@ describe Gitlab::Kubernetes::Helm::ResetCommand do
<<~EOS <<~EOS
helm reset helm reset
kubectl delete replicaset -n gitlab-managed-apps -l name\\=tiller kubectl delete replicaset -n gitlab-managed-apps -l name\\=tiller
kubectl delete clusterrolebinding tiller-admin
EOS EOS
end end
end end
...@@ -32,6 +33,7 @@ describe Gitlab::Kubernetes::Helm::ResetCommand do ...@@ -32,6 +33,7 @@ describe Gitlab::Kubernetes::Helm::ResetCommand do
--tls-key /data/helm/helm/config/key.pem --tls-key /data/helm/helm/config/key.pem
EOS1 EOS1
kubectl delete replicaset -n gitlab-managed-apps -l name\\=tiller kubectl delete replicaset -n gitlab-managed-apps -l name\\=tiller
kubectl delete clusterrolebinding tiller-admin
EOS2 EOS2
end end
end end
......
...@@ -162,6 +162,7 @@ describe Gitlab::Kubernetes::KubeClient do ...@@ -162,6 +162,7 @@ describe Gitlab::Kubernetes::KubeClient do
:get_secret, :get_secret,
:get_service, :get_service,
:get_service_account, :get_service_account,
:delete_namespace,
:delete_pod, :delete_pod,
:create_config_map, :create_config_map,
:create_namespace, :create_namespace,
......
...@@ -134,4 +134,14 @@ describe Clusters::Applications::Helm do ...@@ -134,4 +134,14 @@ describe Clusters::Applications::Helm do
end end
end end
end end
describe '#post_uninstall' do
let(:helm) { create(:clusters_applications_helm, :installed) }
it do
expect(helm.cluster.kubeclient).to receive(:delete_namespace).with('gitlab-managed-apps')
helm.post_uninstall
end
end
end end
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