k3s/pkg/client/unversioned/extensions.go

138 lines
4.1 KiB
Go
Raw Normal View History

2015-08-05 01:35:07 +00:00
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2015-08-12 17:35:07 +00:00
package unversioned
2015-08-05 01:35:07 +00:00
import (
"fmt"
"k8s.io/kubernetes/pkg/apimachinery/registered"
2015-12-08 14:21:04 +00:00
"k8s.io/kubernetes/pkg/apis/extensions"
2015-08-05 01:35:07 +00:00
)
// Interface holds the experimental methods for clients of Kubernetes
// to allow mock testing.
2015-10-12 17:50:20 +00:00
// Features of Extensions group are not supported and may be changed or removed in
2015-08-05 01:35:07 +00:00
// incompatible ways at any time.
2015-10-12 17:50:20 +00:00
type ExtensionsInterface interface {
HorizontalPodAutoscalersNamespacer
ScaleNamespacer
DaemonSetsNamespacer
DeploymentsNamespacer
2015-08-21 14:23:12 +00:00
JobsNamespacer
2015-09-28 23:41:09 +00:00
IngressNamespacer
ThirdPartyResourceNamespacer
ConfigMapsNamespacer
2015-08-05 01:35:07 +00:00
}
2015-10-12 17:50:20 +00:00
// ExtensionsClient is used to interact with experimental Kubernetes features.
// Features of Extensions group are not supported and may be changed or removed in
2015-08-05 01:35:07 +00:00
// incompatible ways at any time.
2015-10-12 17:50:20 +00:00
type ExtensionsClient struct {
2015-08-05 01:35:07 +00:00
*RESTClient
}
2015-10-12 17:50:20 +00:00
func (c *ExtensionsClient) HorizontalPodAutoscalers(namespace string) HorizontalPodAutoscalerInterface {
return newHorizontalPodAutoscalers(c, namespace)
}
2015-10-12 17:50:20 +00:00
func (c *ExtensionsClient) Scales(namespace string) ScaleInterface {
return newScales(c, namespace)
}
2015-10-12 17:50:20 +00:00
func (c *ExtensionsClient) DaemonSets(namespace string) DaemonSetInterface {
return newDaemonSets(c, namespace)
}
2015-10-12 17:50:20 +00:00
func (c *ExtensionsClient) Deployments(namespace string) DeploymentInterface {
return newDeployments(c, namespace)
}
2015-10-12 17:50:20 +00:00
func (c *ExtensionsClient) Jobs(namespace string) JobInterface {
2015-08-21 14:23:12 +00:00
return newJobs(c, namespace)
}
2015-10-12 17:50:20 +00:00
func (c *ExtensionsClient) Ingress(namespace string) IngressInterface {
2015-09-28 23:41:09 +00:00
return newIngress(c, namespace)
}
func (c *ExtensionsClient) ConfigMaps(namespace string) ConfigMapsInterface {
return newConfigMaps(c, namespace)
}
func (c *ExtensionsClient) ThirdPartyResources(namespace string) ThirdPartyResourceInterface {
return newThirdPartyResources(c, namespace)
}
2015-10-12 17:50:20 +00:00
// NewExtensions creates a new ExtensionsClient for the given config. This client
2015-08-05 01:35:07 +00:00
// provides access to experimental Kubernetes features.
2015-10-12 17:50:20 +00:00
// Features of Extensions group are not supported and may be changed or removed in
2015-08-05 01:35:07 +00:00
// incompatible ways at any time.
2015-10-12 17:50:20 +00:00
func NewExtensions(c *Config) (*ExtensionsClient, error) {
2015-08-05 01:35:07 +00:00
config := *c
2015-10-12 17:50:20 +00:00
if err := setExtensionsDefaults(&config); err != nil {
2015-08-05 01:35:07 +00:00
return nil, err
}
client, err := RESTClientFor(&config)
if err != nil {
return nil, err
}
2015-10-12 17:50:20 +00:00
return &ExtensionsClient{client}, nil
2015-08-05 01:35:07 +00:00
}
2015-10-12 17:50:20 +00:00
// NewExtensionsOrDie creates a new ExtensionsClient for the given config and
2015-08-05 01:35:07 +00:00
// panics if there is an error in the config.
2015-10-12 17:50:20 +00:00
// Features of Extensions group are not supported and may be changed or removed in
2015-08-05 01:35:07 +00:00
// incompatible ways at any time.
2015-10-12 17:50:20 +00:00
func NewExtensionsOrDie(c *Config) *ExtensionsClient {
client, err := NewExtensions(c)
2015-08-05 01:35:07 +00:00
if err != nil {
panic(err)
}
return client
}
2015-10-12 17:50:20 +00:00
func setExtensionsDefaults(config *Config) error {
// if experimental group is not registered, return an error
g, err := registered.Group(extensions.GroupName)
if err != nil {
return err
}
config.APIPath = defaultAPIPath
2015-08-05 01:35:07 +00:00
if config.UserAgent == "" {
config.UserAgent = DefaultKubernetesUserAgent()
}
// TODO: Unconditionally set the config.Version, until we fix the config.
//if config.Version == "" {
copyGroupVersion := g.GroupVersion
config.GroupVersion = &copyGroupVersion
//}
versionInterfaces, err := g.InterfacesFor(*config.GroupVersion)
2015-08-05 01:35:07 +00:00
if err != nil {
2015-12-02 20:47:42 +00:00
return fmt.Errorf("Extensions API group/version '%v' is not recognized (valid values: %v)",
config.GroupVersion, registered.GroupOrDie(extensions.GroupName).GroupVersions)
2015-08-05 01:35:07 +00:00
}
config.Codec = versionInterfaces.Codec
2015-08-05 01:35:07 +00:00
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}