func setExtensionsDefaults(config *Config) error { // if experimental group is not registered, return an error g, err := latest.Group(extensions.GroupName) if err != nil { return err } config.Prefix = "apis/" 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 = ©GroupVersion //} versionInterfaces, err := g.InterfacesFor(*config.GroupVersion) if err != nil { return fmt.Errorf("Extensions API group/version '%v' is not recognized (valid values: %v)", config.GroupVersion, latest.GroupOrDie(extensions.GroupName).GroupVersions) } config.Codec = versionInterfaces.Codec if config.QPS == 0 { config.QPS = 5 } if config.Burst == 0 { config.Burst = 10 } return nil }
func init() { kubeTestAPI := os.Getenv("KUBE_TEST_API") if kubeTestAPI != "" { testGroupVersions := strings.Split(kubeTestAPI, ",") for _, gvString := range testGroupVersions { groupVersion, err := unversioned.ParseGroupVersion(gvString) if err != nil { panic(fmt.Sprintf("Error parsing groupversion %v: %v", gvString, err)) } Groups[groupVersion.Group] = TestGroup{ externalGroupVersion: groupVersion, internalGroupVersion: unversioned.GroupVersion{Group: groupVersion.Group}, } } } if _, ok := Groups[api.GroupName]; !ok { Groups[api.GroupName] = TestGroup{ externalGroupVersion: unversioned.GroupVersion{Group: api.GroupName, Version: latest.GroupOrDie(api.GroupName).GroupVersion.Version}, internalGroupVersion: api.SchemeGroupVersion, } } if _, ok := Groups[extensions.GroupName]; !ok { Groups[extensions.GroupName] = TestGroup{ externalGroupVersion: unversioned.GroupVersion{Group: extensions.GroupName, Version: latest.GroupOrDie(extensions.GroupName).GroupVersion.Version}, internalGroupVersion: extensions.SchemeGroupVersion, } } Default = Groups[api.GroupName] Extensions = Groups[extensions.GroupName] }
// MetadataAccessor returns the MetadataAccessor for the API version to test against, // as set by the KUBE_TEST_API env var. func (g TestGroup) MetadataAccessor() meta.MetadataAccessor { interfaces, err := latest.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion) if err != nil { panic(err) } return interfaces.MetadataAccessor }
// Converter returns the api.Scheme for the API version to test against, as set by the // KUBE_TEST_API env var. func (g TestGroup) Converter() runtime.ObjectConvertor { interfaces, err := latest.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion) if err != nil { panic(err) } return interfaces.ObjectConvertor }
// Codec returns the codec for the API version to test against, as set by the // KUBE_TEST_API env var. func (g TestGroup) Codec() runtime.Codec { // TODO: caesarxuchao: Restructure the body once we have a central `latest`. interfaces, err := latest.GroupOrDie(g.externalGroupVersion.Group).InterfacesFor(g.externalGroupVersion) if err != nil { panic(err) } return interfaces.Codec }
// SavePodToFile will encode and save a pod to a given path & permissions func SavePodToFile(pod *api.Pod, filePath string, perm os.FileMode) error { if filePath == "" { return fmt.Errorf("file path not specified") } data, err := latest.GroupOrDie(api.GroupName).Codec.Encode(pod) if err != nil { return fmt.Errorf("failed encoding pod: %v", err) } return ioutil.WriteFile(filePath, data, perm) }
// defaultVersionFor is shared between defaultServerUrlFor and RESTClientFor func defaultVersionFor(config *Config) *unversioned.GroupVersion { if config.GroupVersion == nil { // Clients default to the preferred code API version // TODO: implement version negotiation (highest version supported by server) // TODO this drops out when groupmeta is refactored copyGroupVersion := latest.GroupOrDie(api.GroupName).GroupVersion return ©GroupVersion } return config.GroupVersion }
// LoadPodFromFile will read, decode, and return a Pod from a file. func LoadPodFromFile(filePath string) (*api.Pod, error) { if filePath == "" { return nil, fmt.Errorf("file path not specified") } podDef, err := ioutil.ReadFile(filePath) if err != nil { return nil, fmt.Errorf("failed to read file path %s: %+v", filePath, err) } if len(podDef) == 0 { return nil, fmt.Errorf("file was empty: %s", filePath) } pod := &api.Pod{} if err := latest.GroupOrDie(api.GroupName).Codec.DecodeInto(podDef, pod); err != nil { return nil, fmt.Errorf("failed decoding file: %v", err) } return pod, nil }
func (g TestGroup) RESTMapper() meta.RESTMapper { return latest.GroupOrDie(g.externalGroupVersion.Group).RESTMapper }
// 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. // TODO: this method needs to be split into one that sets defaults per group, expected to be fix in PR "Refactoring clientcache.go and helper.go #14592" func SetKubernetesDefaults(config *Config) error { if config.Prefix == "" { config.Prefix = "/api" } if len(config.UserAgent) == 0 { config.UserAgent = DefaultKubernetesUserAgent() } g, err := latest.Group(api.GroupName) if err != nil { return err } // TODO: Unconditionally set the config.Version, until we fix the config. copyGroupVersion := g.GroupVersion config.GroupVersion = ©GroupVersion versionInterfaces, err := g.InterfacesFor(*config.GroupVersion) if err != nil { return fmt.Errorf("API version '%v' is not recognized (valid values: %v)", *config.GroupVersion, latest.GroupOrDie(api.GroupName).GroupVersions) } 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 }