本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest.InterfacesFor函数的典型用法代码示例。如果您正苦于以下问题:Golang InterfacesFor函数的具体用法?Golang InterfacesFor怎么用?Golang InterfacesFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InterfacesFor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetKubernetesDefaults
// SetKubernetesDefaults sets default values on the provided client config for accessing the
// Kubernetes API or returns an error if any of the defaults are impossible or invalid.
func SetKubernetesDefaults(config *Config) error {
if config.Prefix == "" {
config.Prefix = "/api"
}
if len(config.UserAgent) == 0 {
config.UserAgent = DefaultKubernetesUserAgent()
}
if len(config.Version) == 0 {
config.Version = defaultVersionFor(config)
}
version := config.Version
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", "))
}
if config.Codec == nil {
config.Codec = versionInterfaces.Codec
}
if config.QPS == 0.0 {
config.QPS = 5.0
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}
开发者ID:alexmavr,项目名称:dashboard,代码行数:28,代码来源:helper.go
示例2: findCodec
func findCodec(version string) (runtime.Codec, error) {
versions, err := latest.InterfacesFor(version)
if err != nil {
return nil, err
}
return versions.Codec, nil
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:7,代码来源:server.go
示例3: Converter
// Converter returns the api.Scheme for the API version to test against, as set by the
// KUBE_API_VERSION env var.
func Converter() runtime.ObjectConvertor {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
}
return interfaces.ObjectConvertor
}
开发者ID:mikedanese,项目名称:heapster,代码行数:9,代码来源:testapi.go
示例4: MetadataAccessor
// MetadataAccessor returns the MetadataAccessor for the API version to test against,
// as set by the KUBE_API_VERSION env var.
func MetadataAccessor() meta.MetadataAccessor {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
}
return interfaces.MetadataAccessor
}
开发者ID:mikedanese,项目名称:heapster,代码行数:9,代码来源:testapi.go
示例5: Codec
// Codec returns the codec for the API version to test against, as set by the
// KUBE_API_VERSION env var.
func Codec() runtime.Codec {
interfaces, err := latest.InterfacesFor(Version())
if err != nil {
panic(err)
}
return interfaces.Codec
}
开发者ID:mikedanese,项目名称:heapster,代码行数:9,代码来源:testapi.go
示例6: forbidden
// forbidden renders a simple forbidden error
func forbidden(reason, apiVersion string, w http.ResponseWriter, req *http.Request) {
// the api version can be empty for two basic reasons:
// 1. malformed API request
// 2. not an API request at all
// In these cases, just assume the latest version that will work better than nothing
if len(apiVersion) == 0 {
apiVersion = klatest.Version
}
// Reason is an opaque string that describes why access is allowed or forbidden (forbidden by the time we reach here).
// We don't have direct access to kind or name (not that those apply either in the general case)
// We create a NewForbidden to stay close the API, but then we override the message to get a serialization
// that makes sense when a human reads it.
forbiddenError, _ := kapierror.NewForbidden("", "", errors.New("")).(*kapierror.StatusError)
forbiddenError.ErrStatus.Message = reason
// Not all API versions in valid API requests will have a matching codec in kubernetes. If we can't find one,
// just default to the latest kube codec.
codec := klatest.Codec
if requestedCodec, err := klatest.InterfacesFor(apiVersion); err == nil {
codec = requestedCodec
}
formatted := &bytes.Buffer{}
output, err := codec.Encode(&forbiddenError.ErrStatus)
if err != nil {
fmt.Fprintf(formatted, "%s", forbiddenError.Error())
} else {
_ = json.Indent(formatted, output, "", " ")
}
w.Header().Set("Content-Type", restful.MIME_JSON)
w.WriteHeader(http.StatusForbidden)
w.Write(formatted.Bytes())
}
开发者ID:jigkoxsee,项目名称:origin,代码行数:36,代码来源:master.go
示例7: RESTClientFor
// RESTClientFor returns a RESTClient that satisfies the requested attributes on a client Config
// object.
func RESTClientFor(config *Config) (*RESTClient, error) {
version := defaultVersionFor(config)
// Set version
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return nil, fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", "))
}
baseURL, err := defaultServerUrlFor(config)
if err != nil {
return nil, err
}
client := NewRESTClient(baseURL, versionInterfaces.Codec)
transport, err := TransportFor(config)
if err != nil {
return nil, err
}
if transport != http.DefaultTransport {
client.Client = &http.Client{Transport: transport}
}
return client, nil
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:28,代码来源:helper.go
示例8: NewEtcdStorage
// NewEtcdStorage returns a StorageInterface for the provided arguments or an error if the version
// is incorrect.
func NewEtcdStorage(client tools.EtcdClient, version string, prefix string) (etcdStorage tools.StorageInterface, err error) {
if version == "" {
version = latest.Version
}
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return etcdStorage, err
}
return tools.NewEtcdStorage(client, versionInterfaces.Codec, prefix), nil
}
开发者ID:TesterRandolph,项目名称:kubernetes,代码行数:12,代码来源:master.go
示例9: NewEtcdHelper
// NewEtcdHelper returns an EtcdHelper for the provided arguments or an error if the version
// is incorrect.
func NewEtcdHelper(client tools.EtcdGetSet, version string, prefix string) (helper tools.EtcdHelper, err error) {
if version == "" {
version = latest.Version
}
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return helper, err
}
return tools.NewEtcdHelper(client, versionInterfaces.Codec, prefix), nil
}
开发者ID:paulcichonski,项目名称:kubernetes,代码行数:12,代码来源:master.go
示例10: NewEtcdHelper
// NewEtcdHelper returns an EtcdHelper for the provided arguments or an error if the version
// is incorrect.
func NewEtcdHelper(client tools.EtcdGetSet, version string) (helper tools.EtcdHelper, err error) {
if version == "" {
version = latest.Version
}
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return helper, err
}
return tools.EtcdHelper{client, versionInterfaces.Codec, tools.RuntimeVersionAdapter{versionInterfaces.MetadataAccessor}}, nil
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:12,代码来源:master.go
示例11: PrintObj
// PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer.
func (j *JSONPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
vi, err := latest.InterfacesFor(j.version)
if err != nil {
return err
}
data, err := vi.Codec.Encode(obj)
if err != nil {
return err
}
dst := bytes.Buffer{}
err = json.Indent(&dst, data, "", " ")
dst.WriteByte('\n')
_, err = w.Write(dst.Bytes())
return err
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:17,代码来源:resource_printer.go
示例12: toVersionedMap
func toVersionedMap(version string, obj runtime.Object) (map[string]interface{}, error) {
vi, err := latest.InterfacesFor(version)
if err != nil {
return nil, err
}
data, err := vi.Codec.Encode(obj)
if err != nil {
return nil, err
}
outObj := map[string]interface{}{}
err = json.Unmarshal(data, &outObj)
if err != nil {
return nil, err
}
return outObj, nil
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:17,代码来源:resource_printer.go
示例13: SetKubernetesDefaults
// SetKubernetesDefaults sets default values on the provided client config for accessing the
// Kubernetes API or returns an error if any of the defaults are impossible or invalid.
func SetKubernetesDefaults(config *Config) error {
if config.Prefix == "" {
config.Prefix = "/api"
}
if len(config.Version) == 0 {
config.Version = defaultVersionFor(config)
}
version := config.Version
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", "))
}
if config.Codec == nil {
config.Codec = versionInterfaces.Codec
}
config.LegacyBehavior = (version == "v1beta1" || version == "v1beta2")
return nil
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:20,代码来源:helper.go
示例14: Merge
func Merge(dst runtime.Object, fragment, kind string) (runtime.Object, error) {
// Ok, this is a little hairy, we'd rather not force the user to specify a kind for their JSON
// So we pull it into a map, add the Kind field, and then reserialize.
// We also pull the apiVersion for proper parsing
var intermediate interface{}
if err := json.Unmarshal([]byte(fragment), &intermediate); err != nil {
return nil, err
}
dataMap, ok := intermediate.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Expected a map, found something else: %s", fragment)
}
version, found := dataMap["apiVersion"]
if !found {
return nil, fmt.Errorf("Inline JSON requires an apiVersion field")
}
versionString, ok := version.(string)
if !ok {
return nil, fmt.Errorf("apiVersion must be a string")
}
i, err := latest.InterfacesFor(versionString)
if err != nil {
return nil, err
}
// encode dst into versioned json and apply fragment directly too it
target, err := i.Codec.Encode(dst)
if err != nil {
return nil, err
}
patched, err := jsonpatch.MergePatch(target, []byte(fragment))
if err != nil {
return nil, err
}
out, err := i.Codec.Decode(patched)
if err != nil {
return nil, err
}
return out, nil
}
开发者ID:gabrielweyer,项目名称:kubernetes,代码行数:40,代码来源:helpers.go
示例15: TestProjectIsNamespace
// TestProjectIsNamespace verifies that a project is a namespace, and a namespace is a project
func TestProjectIsNamespace(t *testing.T) {
testutil.DeleteAllEtcdKeys()
etcdClient := testutil.NewEtcdClient()
etcdHelper, err := master.NewEtcdStorage(etcdClient, latest.InterfacesFor, "v1", etcdtest.PathPrefix())
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// create a kube and its client
kubeInterfaces, _ := klatest.InterfacesFor(klatest.Version)
namespaceStorage, _, _ := namespaceetcd.NewStorage(etcdHelper)
kubeStorage := map[string]rest.Storage{
"namespaces": namespaceStorage,
}
osMux := http.NewServeMux()
server := httptest.NewServer(osMux)
defer server.Close()
handlerContainer := master.NewHandlerContainer(osMux)
version := &apiserver.APIGroupVersion{
Root: "/api",
Version: "v1beta3",
Storage: kubeStorage,
Codec: kv1beta3.Codec,
Mapper: klatest.RESTMapper,
Creater: kapi.Scheme,
Typer: kapi.Scheme,
Convertor: kapi.Scheme,
Linker: kubeInterfaces.MetadataAccessor,
Admit: admit.NewAlwaysAdmit(),
Context: kapi.NewRequestContextMapper(),
}
if err := version.InstallREST(handlerContainer); err != nil {
t.Fatalf("unable to install REST: %v", err)
}
kubeClient, err := kclient.New(&kclient.Config{Host: server.URL, Version: "v1beta3"})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
// create an origin
originInterfaces, _ := latest.InterfacesFor(latest.Version)
originStorage := map[string]rest.Storage{
"projects": projectregistry.NewREST(kubeClient.Namespaces(), nil),
}
osVersion := &apiserver.APIGroupVersion{
Root: "/oapi",
Version: "v1",
Storage: originStorage,
Codec: latest.Codec,
Mapper: latest.RESTMapper,
Creater: kapi.Scheme,
Typer: kapi.Scheme,
Convertor: kapi.Scheme,
Linker: originInterfaces.MetadataAccessor,
Admit: admit.NewAlwaysAdmit(),
Context: kapi.NewRequestContextMapper(),
}
if err := osVersion.InstallREST(handlerContainer); err != nil {
t.Fatalf("unable to install REST: %v", err)
}
originClient, err := client.New(&kclient.Config{Host: server.URL})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// create a namespace
namespace := &kapi.Namespace{
ObjectMeta: kapi.ObjectMeta{Name: "integration-test"},
}
namespaceResult, err := kubeClient.Namespaces().Create(namespace)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// now try to get the project with the same name and ensure it is our namespace
project, err := originClient.Projects().Get(namespaceResult.Name)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if project.Name != namespace.Name {
t.Fatalf("Project name did not match namespace name, project %v, namespace %v", project.Name, namespace.Name)
}
// now create a project
project = &projectapi.Project{
ObjectMeta: kapi.ObjectMeta{
Name: "new-project",
//.........这里部分代码省略.........
开发者ID:dustintownsend,项目名称:origin,代码行数:101,代码来源:project_test.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest.InterfacesFor函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论