Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
2f490470
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,发现更多精彩内容 >>
未验证
提交
2f490470
编写于
2月 01, 2021
作者:
K
KubeSphere CI Bot
提交者:
GitHub
2月 01, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3317 from shaowenchen/fix_query_image
add parameter to allow ignore cert
上级
626c30b9
774cefcb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
42 addition
and
26 deletion
+42
-26
pkg/kapis/resources/v1alpha2/handler.go
pkg/kapis/resources/v1alpha2/handler.go
+6
-4
pkg/kapis/resources/v1alpha2/register.go
pkg/kapis/resources/v1alpha2/register.go
+6
-2
pkg/models/registries/manifest_test.go
pkg/models/registries/manifest_test.go
+1
-1
pkg/models/registries/registries.go
pkg/models/registries/registries.go
+7
-6
pkg/models/registries/registry_client.go
pkg/models/registries/registry_client.go
+19
-10
pkg/models/registries/registry_client_test.go
pkg/models/registries/registry_client_test.go
+2
-2
pkg/models/registries/token_test.go
pkg/models/registries/token_test.go
+1
-1
未找到文件。
pkg/kapis/resources/v1alpha2/handler.go
浏览文件 @
2f490470
...
...
@@ -18,6 +18,10 @@ package v1alpha2
import
(
"fmt"
"net/http"
"strconv"
"strings"
"github.com/emicklei/go-restful"
v1
"k8s.io/api/core/v1"
k8serr
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -37,9 +41,6 @@ import (
"kubesphere.io/kubesphere/pkg/models/routers"
"kubesphere.io/kubesphere/pkg/server/errors"
"kubesphere.io/kubesphere/pkg/server/params"
"net/http"
"strconv"
"strings"
)
type
resourceHandler
struct
{
...
...
@@ -325,8 +326,9 @@ func (r *resourceHandler) handleGetRegistryEntry(request *restful.Request, respo
imageName
:=
request
.
QueryParameter
(
"image"
)
namespace
:=
request
.
QueryParameter
(
"namespace"
)
secretName
:=
request
.
QueryParameter
(
"secret"
)
insecure
:=
request
.
QueryParameter
(
"insecure"
)
==
"true"
detail
,
err
:=
r
.
registryGetter
.
GetEntry
(
namespace
,
secretName
,
imageName
)
detail
,
err
:=
r
.
registryGetter
.
GetEntry
(
namespace
,
secretName
,
imageName
,
insecure
)
if
err
!=
nil
{
api
.
HandleBadRequest
(
response
,
nil
,
err
)
return
...
...
pkg/kapis/resources/v1alpha2/register.go
浏览文件 @
2f490470
...
...
@@ -17,8 +17,10 @@ limitations under the License.
package
v1alpha2
import
(
"net/http"
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-openapi"
restfulspec
"github.com/emicklei/go-restful-openapi"
appsv1
"k8s.io/api/apps/v1"
corev1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
...
...
@@ -33,7 +35,6 @@ import (
registriesmodel
"kubesphere.io/kubesphere/pkg/models/registries"
"kubesphere.io/kubesphere/pkg/server/errors"
"kubesphere.io/kubesphere/pkg/server/params"
"net/http"
)
const
(
...
...
@@ -145,6 +146,9 @@ func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, factor
Param
(
webservice
.
QueryParameter
(
"secret"
,
"secret name"
)
.
Required
(
false
)
.
DataFormat
(
"secret=%s"
))
.
Param
(
webservice
.
QueryParameter
(
"insecure"
,
"whether verify cert if using https repo"
)
.
Required
(
false
)
.
DataFormat
(
"insecure=%s"
))
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
RegistryTag
})
.
Doc
(
"Retrieve the blob from the registry identified"
)
.
Writes
(
registriesmodel
.
ImageDetails
{})
.
...
...
pkg/models/registries/manifest_test.go
浏览文件 @
2f490470
...
...
@@ -23,7 +23,7 @@ import (
func
TestDigestFromDockerHub
(
t
*
testing
.
T
)
{
testImage
:=
Image
{
Domain
:
"docker.io"
,
Path
:
"library/alpine"
,
Tag
:
"latest"
}
r
,
err
:=
CreateRegistryClient
(
""
,
""
,
"docker.io"
,
true
)
r
,
err
:=
CreateRegistryClient
(
""
,
""
,
"docker.io"
,
true
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not get client: %s"
,
err
)
}
...
...
pkg/models/registries/registries.go
浏览文件 @
2f490470
...
...
@@ -21,6 +21,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/emicklei/go-restful"
...
...
@@ -28,7 +30,6 @@ import (
"k8s.io/client-go/informers"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/api"
"strings"
)
const
(
...
...
@@ -55,7 +56,7 @@ type DockerConfigEntry struct {
type
RegistryGetter
interface
{
VerifyRegistryCredential
(
credential
api
.
RegistryCredential
)
error
GetEntry
(
namespace
,
secretName
,
imageName
string
)
(
ImageDetails
,
error
)
GetEntry
(
namespace
,
secretName
,
imageName
string
,
insecure
bool
)
(
ImageDetails
,
error
)
}
type
registryGetter
struct
{
...
...
@@ -96,8 +97,8 @@ func (c *registryGetter) VerifyRegistryCredential(credential api.RegistryCredent
}
}
func
(
c
*
registryGetter
)
GetEntry
(
namespace
,
secretName
,
imageName
string
)
(
ImageDetails
,
error
)
{
imageDetails
,
err
:=
c
.
getEntryBySecret
(
namespace
,
secretName
,
imageName
)
func
(
c
*
registryGetter
)
GetEntry
(
namespace
,
secretName
,
imageName
string
,
insecure
bool
)
(
ImageDetails
,
error
)
{
imageDetails
,
err
:=
c
.
getEntryBySecret
(
namespace
,
secretName
,
imageName
,
insecure
)
if
imageDetails
.
Status
==
StatusFailed
{
imageDetails
.
Message
=
err
.
Error
()
}
...
...
@@ -105,7 +106,7 @@ func (c *registryGetter) GetEntry(namespace, secretName, imageName string) (Imag
return
imageDetails
,
err
}
func
(
c
*
registryGetter
)
getEntryBySecret
(
namespace
,
secretName
,
imageName
string
)
(
ImageDetails
,
error
)
{
func
(
c
*
registryGetter
)
getEntryBySecret
(
namespace
,
secretName
,
imageName
string
,
insecure
bool
)
(
ImageDetails
,
error
)
{
failedImageDetails
:=
ImageDetails
{
Status
:
StatusFailed
,
Message
:
""
,
...
...
@@ -152,7 +153,7 @@ func (c *registryGetter) getEntryBySecret(namespace, secretName, imageName strin
useSSL
:=
checkSSl
(
config
.
ServerAddress
)
// Create the registry client.
r
,
err
:=
CreateRegistryClient
(
config
.
Username
,
config
.
Password
,
image
.
Domain
,
useSSL
)
r
,
err
:=
CreateRegistryClient
(
config
.
Username
,
config
.
Password
,
image
.
Domain
,
useSSL
,
insecure
)
if
err
!=
nil
{
return
failedImageDetails
,
err
}
...
...
pkg/models/registries/registry_client.go
浏览文件 @
2f490470
...
...
@@ -18,17 +18,19 @@ package registries
import
(
"compress/gzip"
"crypto/tls"
"errors"
"fmt"
"github.com/docker/docker/api/types"
"io"
"io/ioutil"
log
"k8s.io/klog"
"net/http"
"net/url"
"regexp"
"strings"
"time"
"github.com/docker/docker/api/types"
log
"k8s.io/klog"
)
const
(
...
...
@@ -63,10 +65,11 @@ type Registry struct {
// Opt holds the options for a new registry.
type
RegistryOpt
struct
{
Domain
string
Timeout
time
.
Duration
Headers
map
[
string
]
string
UseSSL
bool
Domain
string
Timeout
time
.
Duration
Headers
map
[
string
]
string
UseSSL
bool
Insecure
bool
}
type
authToken
struct
{
...
...
@@ -80,7 +83,7 @@ type authService struct {
Scope
[]
string
}
func
CreateRegistryClient
(
username
,
password
,
domain
string
,
useSSL
bool
)
(
*
Registry
,
error
)
{
func
CreateRegistryClient
(
username
,
password
,
domain
string
,
useSSL
bool
,
insecure
bool
)
(
*
Registry
,
error
)
{
authDomain
:=
domain
auth
,
err
:=
GetAuthConfig
(
username
,
password
,
authDomain
)
if
err
!=
nil
{
...
...
@@ -90,8 +93,9 @@ func CreateRegistryClient(username, password, domain string, useSSL bool) (*Regi
// Create the registry client.
return
New
(
auth
,
RegistryOpt
{
Domain
:
domain
,
UseSSL
:
useSSL
,
Domain
:
domain
,
UseSSL
:
useSSL
,
Insecure
:
insecure
,
})
}
...
...
@@ -135,11 +139,16 @@ func newFromTransport(auth types.AuthConfig, opt RegistryOpt) (*Registry, error)
}
registryURL
,
_
:=
url
.
Parse
(
registryUrl
)
tr
:=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
opt
.
Insecure
},
}
registry
:=
&
Registry
{
URL
:
registryURL
.
String
(),
Domain
:
registryURL
.
Host
,
Client
:
&
http
.
Client
{
Timeout
:
DefaultTimeout
,
Timeout
:
DefaultTimeout
,
Transport
:
tr
,
},
Username
:
auth
.
Username
,
Password
:
auth
.
Password
,
...
...
pkg/models/registries/registry_client_test.go
浏览文件 @
2f490470
...
...
@@ -41,7 +41,7 @@ func TestCreateRegistryClient(t *testing.T) {
}
for
_
,
testImage
:=
range
testImages
{
reg
,
err
:=
CreateRegistryClient
(
testImage
.
Username
,
testImage
.
Password
,
testImage
.
Domain
,
testImage
.
UseSSL
)
reg
,
err
:=
CreateRegistryClient
(
testImage
.
Username
,
testImage
.
Password
,
testImage
.
Domain
,
testImage
.
UseSSL
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Get err %s"
,
err
)
}
...
...
@@ -57,7 +57,7 @@ func TestCreateRegistryClient(t *testing.T) {
}
testImage
:=
Image
{
Domain
:
DockerHub
,
Path
:
"library/alpine"
,
Tag
:
"latest"
}
r
,
err
:=
CreateRegistryClient
(
""
,
""
,
DockerHub
,
true
)
r
,
err
:=
CreateRegistryClient
(
""
,
""
,
DockerHub
,
true
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not get client: %s"
,
err
)
}
...
...
pkg/models/registries/token_test.go
浏览文件 @
2f490470
...
...
@@ -48,7 +48,7 @@ func (asm authServiceMock) equalTo(v *authService) bool {
func
TestToken
(
t
*
testing
.
T
)
{
testImage
:=
Image
{
Domain
:
"docker.io"
,
Path
:
"library/alpine"
,
Tag
:
"latest"
}
r
,
err
:=
CreateRegistryClient
(
""
,
""
,
"docker.io"
,
true
)
r
,
err
:=
CreateRegistryClient
(
""
,
""
,
"docker.io"
,
true
,
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not get registry client: %s"
,
err
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录