Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
028656fd
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
028656fd
编写于
6月 05, 2018
作者:
A
alex.fan
提交者:
GitHub
6月 05, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2 from kubesphere/master
fork code
上级
d71f7770
6b1ff0e0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
224 addition
and
19 deletion
+224
-19
pkg/apis/v1alpha/components/components_handler.go
pkg/apis/v1alpha/components/components_handler.go
+5
-2
pkg/apis/v1alpha/registries/registries_handler.go
pkg/apis/v1alpha/registries/registries_handler.go
+58
-5
pkg/models/components.go
pkg/models/components.go
+9
-7
pkg/models/registries.go
pkg/models/registries.go
+152
-5
未找到文件。
pkg/apis/v1alpha/components/components_handler.go
浏览文件 @
028656fd
...
...
@@ -40,8 +40,11 @@ func handleGetComponents(request *restful.Request, response *restful.Response) {
if
err
!=
nil
{
response
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
}
response
.
WriteAsJson
(
result
)
}
else
{
response
.
WriteAsJson
(
result
)
}
}
pkg/apis/v1alpha/registries/registries_handler.go
浏览文件 @
028656fd
...
...
@@ -17,11 +17,13 @@ limitations under the License.
package
registries
import
(
"github.com/emicklei/go-restful"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/filter/route"
"net/http"
"github.com/emicklei/go-restful"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/filter/route"
"kubesphere.io/kubesphere/pkg/models"
)
func
Register
(
ws
*
restful
.
WebService
,
subPath
string
)
{
...
...
@@ -30,6 +32,14 @@ func Register(ws *restful.WebService, subPath string) {
Consumes
(
restful
.
MIME_JSON
)
.
Produces
(
restful
.
MIME_JSON
)
ws
.
Route
(
ws
.
POST
(
subPath
)
.
To
(
handleCreateRegistries
)
.
Filter
(
route
.
RouteLogging
))
.
Consumes
(
restful
.
MIME_JSON
)
.
Produces
(
restful
.
MIME_JSON
)
ws
.
Route
(
ws
.
GET
(
subPath
+
"/{project}"
)
.
To
(
handleQueryRegistries
)
.
Filter
(
route
.
RouteLogging
))
.
Consumes
(
restful
.
MIME_JSON
)
.
Produces
(
restful
.
MIME_JSON
)
}
func
handlerRegistryValidation
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
...
...
@@ -38,16 +48,59 @@ func handlerRegistryValidation(request *restful.Request, response *restful.Respo
err
:=
request
.
ReadEntity
(
&
authinfo
)
if
err
!=
nil
{
response
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
}
else
{
result
:=
models
.
RegistryLoginAuth
(
authinfo
)
response
.
WriteAsJson
(
result
)
}
}
func
handleCreateRegistries
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
registries
:=
models
.
Registries
{}
err
:=
request
.
ReadEntity
(
&
registries
)
if
err
!=
nil
{
response
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
}
result
:=
models
.
RegistryLoginAuth
(
authinfo
)
result
,
err
:=
models
.
CreateRegistries
(
registries
)
if
err
!=
nil
{
response
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
}
else
{
response
.
WriteAsJson
(
result
)
response
.
WriteAsJson
(
result
)
}
}
func
handleQueryRegistries
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
project
:=
request
.
PathParameter
(
"project"
)
result
,
err
:=
models
.
QueryRegistries
(
project
)
if
err
!=
nil
{
response
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
constants
.
MessageResponse
{
Message
:
err
.
Error
()})
}
else
{
response
.
WriteAsJson
(
result
)
}
}
\ No newline at end of file
pkg/models/components.go
浏览文件 @
028656fd
...
...
@@ -17,11 +17,13 @@ limitations under the License.
package
models
import
(
"kubesphere.io/kubesphere/pkg/client"
meta_v1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
"time"
"github.com/golang/glog"
"strings"
meta_v1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"kubesphere.io/kubesphere/pkg/client"
)
const
KUBESYSTEM
=
"kube-system"
...
...
@@ -66,7 +68,7 @@ func GetComponents() (result []Components, err error) {
var
components
Components
templates
:=
[]
string
{
"kube-apiserver"
,
"etcd"
,
"kube-scheduler"
,
"kube-controller-manager"
,
"cloud-controller-manager"
}
templates
:=
[]
string
{
"kube-apiserver"
,
"etcd"
,
"kube-scheduler"
,
"kube-controller-manager"
,
"cloud-controller-manager"
}
if
len
(
podlists
.
Items
)
>
0
{
...
...
@@ -191,7 +193,7 @@ func GetComponents() (result []Components, err error) {
components
.
Name
=
ds
.
Name
components
.
Kind
=
"Daemonset"
components
.
SelfLink
=
ds
.
SelfLink
components
.
Label
=
ds
.
Labels
components
.
Label
=
ds
.
Spec
.
Selector
.
Match
Labels
components
.
Namespace
=
ds
.
Namespace
version
:=
strings
.
Split
(
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
,
":"
)
...
...
@@ -252,7 +254,7 @@ func GetComponents() (result []Components, err error) {
components
.
Name
=
dm
.
Name
components
.
Kind
=
"Deployment"
components
.
SelfLink
=
dm
.
SelfLink
components
.
Label
=
dm
.
Labels
components
.
Label
=
dm
.
Spec
.
Selector
.
Match
Labels
components
.
Namespace
=
dm
.
Namespace
components
.
Replicas
=
int
(
dm
.
Status
.
Replicas
)
version
:=
strings
.
Split
(
dm
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
,
":"
)
...
...
@@ -292,4 +294,4 @@ func GetComponents() (result []Components, err error) {
return
result
,
nil
}
}
\ No newline at end of file
pkg/models/registries.go
浏览文件 @
028656fd
...
...
@@ -17,14 +17,27 @@ limitations under the License.
package
models
import
(
"encoding/base64"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/golang/glog"
"k8s.io/api/core/v1"
meta_v1
"k8s.io/apimachinery/pkg/apis/meta/v1"
kubeclient
"kubesphere.io/kubesphere/pkg/client"
"kubesphere.io/kubesphere/pkg/constants"
)
const
TYPE
=
"kubernetes.io/dockerconfigjson"
const
SECRET
=
"Secret"
const
APIVERSION
=
"v1"
type
AuthInfo
struct
{
Username
string
`json:"username"`
...
...
@@ -32,13 +45,42 @@ type AuthInfo struct {
ServerHost
string
`json:"serverhost"`
}
type
ValidationMsg
struct
{
func
NewAuthInfo
(
para
Registries
)
*
AuthInfo
{
return
&
AuthInfo
{
Username
:
para
.
RegUsername
,
Password
:
para
.
RegPassword
,
ServerHost
:
para
.
RegServerHost
,
}
}
func
convert2DockerJson
(
authinfo
AuthInfo
)
[]
byte
{
datastr
:=
[]
byte
(
authinfo
.
Username
+
":"
+
authinfo
.
Password
)
auth
:=
base64
.
StdEncoding
.
EncodeToString
(
datastr
)
dockercfg
:=
fmt
.
Sprintf
(
"{
\"
auths
\"
:{
\"
%s
\"
:{
\"
username
\"
:
\"
%s
\"
,
\"
password
\"
:
\"
%s
\"
,
\"
auth
\"
:
\"
%s
\"
}}}"
,
authinfo
.
ServerHost
,
authinfo
.
Username
,
authinfo
.
Password
,
auth
)
return
[]
byte
(
dockercfg
)
Message
string
`json:"message"`
Reason
string
`json:"reason"`
}
type
Registries
struct
{
DisplayName
string
`json:"display_name,omitempty"`
Description
string
`json:"description,omitempty"`
AuthProject
string
`json:"auth_project,omitempty"`
RegServerHost
string
`json:"reg_server_host,omitempty"`
RegUsername
string
`json:"reg_username,omitempty"`
RegPassword
string
`json:"reg_password,omitempty"`
CreateUser
string
`json:"create_user,omitempty"`
}
type
ValidationMsg
struct
{
Message
string
`json:"message"`
Reason
string
`json:"reason"`
}
const
DOCKERCLIENTERROR
=
"Docker client error"
...
...
@@ -90,4 +132,109 @@ func RegistryLoginAuth(authinfo AuthInfo) ValidationMsg {
}
//create registries
func
CreateRegistries
(
registries
Registries
)
(
msg
constants
.
MessageResponse
,
err
error
)
{
projects
:=
strings
.
Split
(
registries
.
AuthProject
,
","
)
var
secret
v1
.
Secret
secret
.
Kind
=
SECRET
secret
.
APIVersion
=
APIVERSION
secret
.
Type
=
TYPE
secret
.
Name
=
registries
.
DisplayName
+
".key"
authinfo
:=
NewAuthInfo
(
registries
)
data
:=
make
(
map
[
string
][]
byte
)
data
[
".dockerconfigjson"
]
=
convert2DockerJson
(
*
authinfo
)
secret
.
Data
=
data
k8sclient
:=
kubeclient
.
NewK8sClient
()
labels
:=
make
(
map
[
string
]
string
)
annotations
:=
make
(
map
[
string
]
string
)
labels
[
"app"
]
=
"dockerhubkey"
secret
.
Labels
=
labels
annotations
[
"description"
]
=
registries
.
Description
annotations
[
"createuser"
]
=
registries
.
CreateUser
secret
.
Annotations
=
annotations
for
_
,
pro
:=
range
projects
{
glog
.
Infof
(
"create secret %s in %s "
,
registries
.
DisplayName
,
pro
)
_
,
err
:=
k8sclient
.
CoreV1
()
.
Secrets
(
pro
)
.
Create
(
&
secret
)
if
err
!=
nil
{
glog
.
Error
(
err
)
return
msg
,
err
}
}
//end for
msg
.
Message
=
"success"
return
msg
,
nil
}
//query registries host
func
QueryRegistries
(
project
string
)
(
regList
[]
Registries
,
err
error
)
{
k8sclient
:=
kubeclient
.
NewK8sClient
()
var
options
meta_v1
.
ListOptions
options
.
LabelSelector
=
"app=dockerhubkey"
var
reg
Registries
secrets
,
err
:=
k8sclient
.
CoreV1
()
.
Secrets
(
project
)
.
List
(
options
)
if
err
!=
nil
{
glog
.
Errorln
(
err
)
return
regList
,
err
}
if
len
(
secrets
.
Items
)
>
0
{
for
_
,
secret
:=
range
secrets
.
Items
{
reg
.
DisplayName
=
secret
.
Name
reg
.
AuthProject
=
project
if
err
!=
nil
{
glog
.
Errorln
(
err
)
return
regList
,
err
}
var
data
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
(
secret
.
Data
[
".dockerconfigjson"
],
&
data
)
if
err
!=
nil
{
glog
.
Errorln
(
err
)
return
regList
,
err
}
hostMap
:=
data
[
"auths"
]
.
(
map
[
string
]
interface
{})
for
key
,
_
:=
range
hostMap
{
reg
.
RegServerHost
=
key
}
regList
=
append
(
regList
,
reg
)
}
}
return
regList
,
nil
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录