Skip to content

Commit

Permalink
Merge pull request kubernetes#13955 from caesarxuchao/API-discovery
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Sep 21, 2015
2 parents 653e695 + 1278771 commit 6c30a0e
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 49 deletions.
4 changes: 4 additions & 0 deletions api/swagger-spec/resourceListing.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"path": "/api",
"description": "get available API versions"
},
{
"path": "/apis",
"description": "get available API versions"
},
{
"path": "/version",
"description": "git code version from which this is built"
Expand Down
19 changes: 19 additions & 0 deletions api/swagger-spec/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10950,6 +10950,25 @@
]
}
]
},
{
"path": "/api/v1",
"description": "API at /api/v1 version v1",
"operations": [
{
"type": "void",
"method": "GET",
"summary": "get available resources",
"nickname": "getAPIResources",
"parameters": [],
"produces": [
"application/json"
],
"consumes": [
"application/json"
]
}
]
}
],
"models": {
Expand Down
4 changes: 4 additions & 0 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
// We will fix this by supporting multiple group versions in Config
cl.ExperimentalClient = client.NewExperimentalOrDie(&client.Config{Host: apiServer.URL, Version: testapi.Experimental.Version()})

storageVersions := make(map[string]string)
etcdStorage, err := master.NewEtcdStorage(etcdClient, latest.GroupOrDie("").InterfacesFor, testapi.Default.Version(), etcdtest.PathPrefix())
storageVersions[""] = testapi.Default.Version()
if err != nil {
glog.Fatalf("Unable to get etcd storage: %v", err)
}
expEtcdStorage, err := master.NewEtcdStorage(etcdClient, latest.GroupOrDie("experimental").InterfacesFor, testapi.Experimental.Version(), etcdtest.PathPrefix())
storageVersions["experimental"] = testapi.Experimental.Version()
if err != nil {
glog.Fatalf("Unable to get etcd storage for experimental: %v", err)
}
Expand Down Expand Up @@ -171,6 +174,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
ReadWritePort: portNumber,
PublicAddress: publicAddress,
CacheTimeout: 2 * time.Second,
StorageVersions: storageVersions,
})
handler.delegate = m.Handler

Expand Down
31 changes: 23 additions & 8 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package app

import (
"crypto/tls"
"fmt"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -245,7 +246,10 @@ func (s *APIServer) verifyClusterIPFlags() {
}
}

func newEtcd(etcdConfigFile string, etcdServerList []string, interfacesFunc meta.VersionInterfacesFunc, defaultVersion, storageVersion, pathPrefix string) (etcdStorage storage.Interface, err error) {
func newEtcd(etcdConfigFile string, etcdServerList []string, interfacesFunc meta.VersionInterfacesFunc, storageVersion, pathPrefix string) (etcdStorage storage.Interface, err error) {
if storageVersion == "" {
return etcdStorage, fmt.Errorf("storageVersion is required to create a etcd storage")
}
var client tools.EtcdClient
if etcdConfigFile != "" {
client, err = etcd.NewClientFromFile(etcdConfigFile)
Expand All @@ -264,11 +268,8 @@ func newEtcd(etcdConfigFile string, etcdServerList []string, interfacesFunc meta
etcdClient.SetTransport(transport)
client = etcdClient
}

if storageVersion == "" {
storageVersion = defaultVersion
}
return master.NewEtcdStorage(client, interfacesFunc, storageVersion, pathPrefix)
etcdStorage, err = master.NewEtcdStorage(client, interfacesFunc, storageVersion, pathPrefix)
return etcdStorage, err
}

// Run runs the specified APIServer. This should never exit.
Expand Down Expand Up @@ -341,7 +342,16 @@ func (s *APIServer) Run(_ []string) error {
glog.Fatalf("Invalid server address: %v", err)
}

etcdStorage, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, latest.GroupOrDie("").InterfacesFor, latest.GroupOrDie("").Version, s.StorageVersion, s.EtcdPathPrefix)
g, err := latest.Group("")
if err != nil {
return err
}
storageVersions := make(map[string]string)
if s.StorageVersion == "" {
s.StorageVersion = g.Version
}
etcdStorage, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, g.InterfacesFor, s.StorageVersion, s.EtcdPathPrefix)
storageVersions[""] = s.StorageVersion
if err != nil {
glog.Fatalf("Invalid storage version or misconfigured etcd: %v", err)
}
Expand All @@ -352,10 +362,14 @@ func (s *APIServer) Run(_ []string) error {
if err != nil {
glog.Fatalf("experimental API is enabled in runtime config, but not enabled in the environment variable KUBE_API_VERSIONS. Error: %v", err)
}
expEtcdStorage, err = newEtcd(s.EtcdConfigFile, s.EtcdServerList, g.InterfacesFor, g.Version, s.ExpStorageVersion, s.EtcdPathPrefix)
if s.ExpStorageVersion == "" {
s.ExpStorageVersion = g.Version
}
expEtcdStorage, err = newEtcd(s.EtcdConfigFile, s.EtcdServerList, g.InterfacesFor, s.ExpStorageVersion, s.EtcdPathPrefix)
if err != nil {
glog.Fatalf("Invalid experimental storage version or misconfigured etcd: %v", err)
}
storageVersions["experimental"] = s.StorageVersion
}

n := s.ServiceClusterIPRange
Expand Down Expand Up @@ -427,6 +441,7 @@ func (s *APIServer) Run(_ []string) error {
config := &master.Config{
DatabaseStorage: etcdStorage,
ExpDatabaseStorage: expEtcdStorage,
StorageVersions: storageVersions,

EventTTL: s.EventTTL,
KubeletClient: kubeletClient,
Expand Down
56 changes: 52 additions & 4 deletions pkg/api/unversioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,64 @@ import (

// This file contains API types that are unversioned.

// APIVersions lists the api versions that are available, to allow
// version negotiation. APIVersions isn't just an unnamed array of
// strings in order to allow for future evolution, though unversioned
// APIVersions lists the versions that are available, to allow clients to
// discover the API at /api, which is the root path of the legacy v1 API.
type APIVersions struct {
// versions are the api versions that are available.
Versions []string `json:"versions"`
}

// APIGroupList is a list of APIGroup, to allow clients to discover the API at
// /apis.
type APIGroupList struct {
// groups is a list of APIGroup.
Groups []APIGroup `json:"groups"`
}

// APIGroup contains the name, the supported versions, and the preferred version
// of a group.
type APIGroup struct {
// name is the name of the group.
Name string `json:"name"`
// versions are the versions supported in this group.
Versions []GroupVersion `json:"versions"`
// preferredVersion is the version preferred by the API server, which
// probably is the storage version.
PreferredVersion GroupVersion `json:"preferredVersion,omitempty"`
}

// GroupVersion contains the "group/version" and "version" string of a version.
// It is made a struct to keep extensiblity.
type GroupVersion struct {
// groupVersion specifies the API group and version in the form "group/version"
GroupVersion string `json:"groupVersion"`
// version specifies the version in the form of "version". This is to save
// the clients the trouble of splitting the GroupVersion.
Version string `json:"version"`
}

// APIResource specifies the name of a resource and whether it is namespaced.
type APIResource struct {
// name is the name of the resource.
Name string `json:"name"`
// namespaced indicates if a resource is namespaced or not.
Namespaced bool `json:"namespaced"`
}

// APIResourceList is a list of APIResource, it is used to expose the name of the
// resources supported in a specific group and version, and if the resource
// is namespaced.
type APIResourceList struct {
// groupVersion is the group and version this APIResourceList is for.
GroupVersion string `json:"groupVersion"`
// resources contains the name of the resources and if they are namespaced.
APIResources []APIResource `json:"resources"`
}

// RootPaths lists the paths available at root.
// For example: "/healthz", "/api".
// For example: "/healthz", "/apis".
type RootPaths struct {
// paths are the paths available at root.
Paths []string `json:"paths"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/experimental/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type ThirdPartyResourceList struct {
}

// An APIVersion represents a single concrete version of an object model.
// TODO: we should consider merge this struct with GroupVersion in unversioned.go
type APIVersion struct {
// Name of this version (e.g. 'v1').
Name string `json:"name,omitempty"`
Expand Down
Loading

0 comments on commit 6c30a0e

Please sign in to comment.