Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f8326af5
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f8326af5
编写于
4月 10, 2019
作者:
T
Thong Kuah
提交者:
Dylan Griffith
4月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement commands to uninstall cluster applications
This is the backend part which just allows uninstalling Prometheus for now.
上级
026c92d5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
161 addition
and
0 deletion
+161
-0
app/models/clusters/concerns/application_data.rb
app/models/clusters/concerns/application_data.rb
+8
-0
lib/gitlab/kubernetes/helm/delete_command.rb
lib/gitlab/kubernetes/helm/delete_command.rb
+55
-0
spec/lib/gitlab/kubernetes/helm/delete_command_spec.rb
spec/lib/gitlab/kubernetes/helm/delete_command_spec.rb
+72
-0
spec/support/shared_examples/models/cluster_application_helm_cert_examples.rb
...examples/models/cluster_application_helm_cert_examples.rb
+26
-0
未找到文件。
app/models/clusters/concerns/application_data.rb
浏览文件 @
f8326af5
...
...
@@ -6,6 +6,14 @@ module Clusters
extend
ActiveSupport
::
Concern
included
do
def
uninstall_command
Gitlab
::
Kubernetes
::
Helm
::
DeleteCommand
.
new
(
name:
name
,
rbac:
cluster
.
platform_kubernetes_rbac?
,
files:
files
)
end
def
repository
nil
end
...
...
lib/gitlab/kubernetes/helm/delete_command.rb
0 → 100644
浏览文件 @
f8326af5
# frozen_string_literal: true
module
Gitlab
module
Kubernetes
module
Helm
class
DeleteCommand
include
BaseCommand
include
ClientCommand
attr_accessor
:name
,
:files
def
initialize
(
name
:,
rbac
:,
files
:)
@name
=
name
@files
=
files
@rbac
=
rbac
end
def
generate_script
super
+
[
init_command
,
wait_for_tiller_command
,
delete_command
].
compact
.
join
(
"
\n
"
)
end
def
pod_name
"uninstall-
#{
name
}
"
end
def
rbac?
@rbac
end
private
def
delete_command
command
=
[
'helm'
,
'delete'
,
'--purge'
,
name
]
+
optional_tls_flags
command
.
shelljoin
end
def
optional_tls_flags
return
[]
unless
files
.
key?
(
:'ca.pem'
)
[
'--tls'
,
'--tls-ca-cert'
,
"
#{
files_dir
}
/ca.pem"
,
'--tls-cert'
,
"
#{
files_dir
}
/cert.pem"
,
'--tls-key'
,
"
#{
files_dir
}
/key.pem"
]
end
end
end
end
end
spec/lib/gitlab/kubernetes/helm/delete_command_spec.rb
0 → 100644
浏览文件 @
f8326af5
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Kubernetes
::
Helm
::
DeleteCommand
do
let
(
:app_name
)
{
'app-name'
}
let
(
:rbac
)
{
true
}
let
(
:files
)
{
{}
}
let
(
:delete_command
)
{
described_class
.
new
(
name:
app_name
,
rbac:
rbac
,
files:
files
)
}
subject
{
delete_command
}
it_behaves_like
'helm commands'
do
let
(
:commands
)
do
<<~
EOS
helm init --upgrade
for i in $(seq 1 30); do helm version && break; sleep 1s; echo "Retrying ($i)..."; done
helm delete --purge app-name
EOS
end
end
context
'when there is a ca.pem file'
do
let
(
:files
)
{
{
'ca.pem'
:
'some file content'
}
}
it_behaves_like
'helm commands'
do
let
(
:commands
)
do
<<~
EOS
helm init --upgrade
for i in $(seq 1 30); do helm version && break; sleep 1s; echo "Retrying ($i)..."; done
#{
helm_delete_command
}
EOS
end
let
(
:helm_delete_command
)
do
<<~
EOS
.
squish
helm delete --purge app-name
--tls
--tls-ca-cert /data/helm/app-name/config/ca.pem
--tls-cert /data/helm/app-name/config/cert.pem
--tls-key /data/helm/app-name/config/key.pem
EOS
end
end
end
describe
'#pod_resource'
do
subject
{
delete_command
.
pod_resource
}
context
'rbac is enabled'
do
let
(
:rbac
)
{
true
}
it
'generates a pod that uses the tiller serviceAccountName'
do
expect
(
subject
.
spec
.
serviceAccountName
).
to
eq
(
'tiller'
)
end
end
context
'rbac is not enabled'
do
let
(
:rbac
)
{
false
}
it
'generates a pod that uses the default serviceAccountName'
do
expect
(
subject
.
spec
.
serviceAcccountName
).
to
be_nil
end
end
end
describe
'#pod_name'
do
subject
{
delete_command
.
pod_name
}
it
{
is_expected
.
to
eq
(
'uninstall-app-name'
)
}
end
end
spec/support/shared_examples/models/cluster_application_helm_cert_examples.rb
浏览文件 @
f8326af5
shared_examples
'cluster application helm specs'
do
|
application_name
|
let
(
:application
)
{
create
(
application_name
)
}
describe
'#uninstall_command'
do
subject
{
application
.
uninstall_command
}
it
{
is_expected
.
to
be_an_instance_of
(
Gitlab
::
Kubernetes
::
Helm
::
DeleteCommand
)
}
it
'has the application name'
do
expect
(
subject
.
name
).
to
eq
(
application
.
name
)
end
it
'has files'
do
expect
(
subject
.
files
).
to
eq
(
application
.
files
)
end
it
'is rbac'
do
expect
(
subject
).
to
be_rbac
end
context
'on a non rbac enabled cluster'
do
before
do
application
.
cluster
.
platform_kubernetes
.
abac!
end
it
{
is_expected
.
not_to
be_rbac
}
end
end
describe
'#files'
do
subject
{
application
.
files
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录