Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6a104ee4
Commit
6a104ee4
authored
Jan 05, 2016
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move SwaggerSchema to DiscoveryClient
parent
144b5acd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
51 deletions
+47
-51
client.go
pkg/client/unversioned/client.go
+0
-48
client_test.go
pkg/client/unversioned/client_test.go
+2
-2
discovery_client.go
pkg/client/unversioned/discovery_client.go
+44
-0
factory.go
pkg/kubectl/cmd/util/factory.go
+1
-1
No files found.
pkg/client/unversioned/client.go
View file @
6a104ee4
...
...
@@ -17,16 +17,9 @@ limitations under the License.
package
unversioned
import
(
"encoding/json"
"fmt"
"net"
"net/url"
"strings"
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
)
// Interface holds the methods for clients of Kubernetes,
...
...
@@ -47,7 +40,6 @@ type Interface interface {
PersistentVolumesInterface
PersistentVolumeClaimsNamespacer
ComponentStatusesInterface
SwaggerSchemaInterface
Extensions
()
ExtensionsInterface
Discovery
()
DiscoveryInterface
}
...
...
@@ -118,46 +110,6 @@ type Client struct {
*
DiscoveryClient
}
// SwaggerSchemaInterface has a method to retrieve the swagger schema. Used in
// client.Interface
type
SwaggerSchemaInterface
interface
{
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
}
// SwaggerSchema retrieves and parses the swagger API schema the server supports.
func
(
c
*
Client
)
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
if
version
.
IsEmpty
()
{
return
nil
,
fmt
.
Errorf
(
"groupVersion cannot be empty"
)
}
groupList
,
err
:=
c
.
Discovery
()
.
ServerGroups
()
if
err
!=
nil
{
return
nil
,
err
}
groupVersions
:=
ExtractGroupVersions
(
groupList
)
// This check also takes care the case that kubectl is newer than the running endpoint
if
stringDoesntExistIn
(
version
.
String
(),
groupVersions
)
{
return
nil
,
fmt
.
Errorf
(
"API version: %v is not supported by the server. Use one of: %v"
,
version
,
groupVersions
)
}
var
path
string
if
version
==
v1
.
SchemeGroupVersion
{
path
=
"/swaggerapi/api/"
+
version
.
Version
}
else
{
path
=
"/swaggerapi/apis/"
+
version
.
Group
+
"/"
+
version
.
Version
}
body
,
err
:=
c
.
Get
()
.
AbsPath
(
path
)
.
Do
()
.
Raw
()
if
err
!=
nil
{
return
nil
,
err
}
var
schema
swagger
.
ApiDeclaration
err
=
json
.
Unmarshal
(
body
,
&
schema
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"got '%s': %v"
,
string
(
body
),
err
)
}
return
&
schema
,
nil
}
func
stringDoesntExistIn
(
str
string
,
slice
[]
string
)
bool
{
for
_
,
s
:=
range
slice
{
if
s
==
str
{
...
...
pkg/client/unversioned/client_test.go
View file @
6a104ee4
...
...
@@ -273,7 +273,7 @@ func TestGetSwaggerSchema(t *testing.T) {
defer
server
.
Close
()
client
:=
NewOrDie
(
&
Config
{
Host
:
server
.
URL
})
got
,
err
:=
client
.
SwaggerSchema
(
v1
.
SchemeGroupVersion
)
got
,
err
:=
client
.
Discovery
()
.
SwaggerSchema
(
v1
.
SchemeGroupVersion
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected encoding error: %v"
,
err
)
}
...
...
@@ -292,7 +292,7 @@ func TestGetSwaggerSchemaFail(t *testing.T) {
defer
server
.
Close
()
client
:=
NewOrDie
(
&
Config
{
Host
:
server
.
URL
})
got
,
err
:=
client
.
SwaggerSchema
(
unversioned
.
GroupVersion
{
Group
:
"api.group"
,
Version
:
"v4"
})
got
,
err
:=
client
.
Discovery
()
.
SwaggerSchema
(
unversioned
.
GroupVersion
{
Group
:
"api.group"
,
Version
:
"v4"
})
if
got
!=
nil
{
t
.
Fatalf
(
"unexpected response: %v"
,
got
)
}
...
...
pkg/client/unversioned/discovery_client.go
View file @
6a104ee4
...
...
@@ -21,9 +21,12 @@ import (
"fmt"
"net/url"
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/version"
)
...
...
@@ -33,6 +36,7 @@ type DiscoveryInterface interface {
ServerGroupsInterface
ServerResourcesInterface
ServerVersionInterface
SwaggerSchemaInterface
}
// ServerGroupsInterface has methods for obtaining supported groups on the API server
...
...
@@ -56,6 +60,12 @@ type ServerVersionInterface interface {
ServerVersion
()
(
*
version
.
Info
,
error
)
}
// SwaggerSchemaInterface has a method to retrieve the swagger schema.
type
SwaggerSchemaInterface
interface
{
// SwaggerSchema retrieves and parses the swagger API schema the server supports.
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
}
// DiscoveryClient implements the functions that dicovery server-supported API groups,
// versions and resources.
type
DiscoveryClient
struct
{
...
...
@@ -162,6 +172,40 @@ func (d *DiscoveryClient) ServerVersion() (*version.Info, error) {
return
&
info
,
nil
}
// SwaggerSchema retrieves and parses the swagger API schema the server supports.
func
(
d
*
DiscoveryClient
)
SwaggerSchema
(
version
unversioned
.
GroupVersion
)
(
*
swagger
.
ApiDeclaration
,
error
)
{
if
version
.
IsEmpty
()
{
return
nil
,
fmt
.
Errorf
(
"groupVersion cannot be empty"
)
}
groupList
,
err
:=
d
.
ServerGroups
()
if
err
!=
nil
{
return
nil
,
err
}
groupVersions
:=
ExtractGroupVersions
(
groupList
)
// This check also takes care the case that kubectl is newer than the running endpoint
if
stringDoesntExistIn
(
version
.
String
(),
groupVersions
)
{
return
nil
,
fmt
.
Errorf
(
"API version: %v is not supported by the server. Use one of: %v"
,
version
,
groupVersions
)
}
var
path
string
if
version
==
v1
.
SchemeGroupVersion
{
path
=
"/swaggerapi/api/"
+
version
.
Version
}
else
{
path
=
"/swaggerapi/apis/"
+
version
.
Group
+
"/"
+
version
.
Version
}
body
,
err
:=
d
.
Get
()
.
AbsPath
(
path
)
.
Do
()
.
Raw
()
if
err
!=
nil
{
return
nil
,
err
}
var
schema
swagger
.
ApiDeclaration
err
=
json
.
Unmarshal
(
body
,
&
schema
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"got '%s': %v"
,
string
(
body
),
err
)
}
return
&
schema
,
nil
}
func
setDiscoveryDefaults
(
config
*
Config
)
error
{
config
.
Prefix
=
""
config
.
GroupVersion
=
nil
...
...
pkg/kubectl/cmd/util/factory.go
View file @
6a104ee4
...
...
@@ -320,7 +320,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
if
err
!=
nil
{
return
nil
,
err
}
return
client
.
SwaggerSchema
(
version
)
return
client
.
Discovery
()
.
SwaggerSchema
(
version
)
},
DefaultNamespace
:
func
()
(
string
,
bool
,
error
)
{
return
clientConfig
.
Namespace
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment