예제 #1
0
파일: testapi.go 프로젝트: jordic/k8s
func init() {
	kubeTestAPI := os.Getenv("KUBE_TEST_API")
	if kubeTestAPI != "" {
		testGroupVersions := strings.Split(kubeTestAPI, ",")
		for _, groupVersion := range testGroupVersions {
			// TODO: caesarxuchao: the apiutil package is hacky, it will be replaced
			// by a following PR.
			Groups[apiutil.GetGroup(groupVersion)] =
				TestGroup{apiutil.GetGroup(groupVersion), apiutil.GetVersion(groupVersion), groupVersion}
		}
	}

	// TODO: caesarxuchao: we need a central place to store all available API
	// groups and their metadata.
	if _, ok := Groups[""]; !ok {
		// TODO: The second latest.GroupOrDie("").GroupVersion.Version will be latest.GroupVersion after we
		// have multiple group support
		Groups[""] = TestGroup{"", latest.GroupOrDie("").GroupVersion.Version, latest.GroupOrDie("").GroupVersion.String()}
	}
	if _, ok := Groups["extensions"]; !ok {
		Groups["extensions"] = TestGroup{"extensions", latest.GroupOrDie("extensions").GroupVersion.Version, latest.GroupOrDie("extensions").GroupVersion.String()}
	}

	Default = Groups[""]
	Extensions = Groups["extensions"]
}
예제 #2
0
파일: extensions.go 프로젝트: jordic/k8s
func setExtensionsDefaults(config *Config) error {
	// if experimental group is not registered, return an error
	g, err := latest.Group("extensions")
	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 = &copyGroupVersion
	//}

	versionInterfaces, err := g.InterfacesFor(config.GroupVersion.String())
	if err != nil {
		return fmt.Errorf("Extensions API group/version '%v' is not recognized (valid values: %s)",
			config.GroupVersion, strings.Join(latest.GroupOrDie("extensions").Versions, ", "))
	}
	config.Codec = versionInterfaces.Codec
	if config.QPS == 0 {
		config.QPS = 5
	}
	if config.Burst == 0 {
		config.Burst = 10
	}
	return nil
}
예제 #3
0
파일: helper.go 프로젝트: jordic/k8s
// 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()
	}
	if config.GroupVersion == nil {
		config.GroupVersion = defaultVersionFor(config)
	}
	versionInterfaces, err := latest.GroupOrDie("").InterfacesFor(config.GroupVersion.String())
	if err != nil {
		return fmt.Errorf("API version '%v' is not recognized (valid values: %s)", *config.GroupVersion, strings.Join(latest.GroupOrDie("").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
}
예제 #4
0
파일: testapi.go 프로젝트: jordic/k8s
// 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.Group).InterfacesFor(g.GroupVersionUnderTest)
	if err != nil {
		panic(err)
	}
	return interfaces.Codec
}
예제 #5
0
파일: testapi.go 프로젝트: jordic/k8s
// 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 {
	// TODO: caesarxuchao: Restructure the body once we have a central `latest`.
	if g.Group == "" {
		interfaces, err := latest.GroupOrDie("").InterfacesFor(g.VersionUnderTest)
		if err != nil {
			panic(err)
		}
		return interfaces.MetadataAccessor
	}
	if g.Group == "extensions" {
		interfaces, err := latest.GroupOrDie("extensions").InterfacesFor(g.VersionUnderTest)
		if err != nil {
			panic(err)
		}
		return interfaces.MetadataAccessor
	}
	panic(fmt.Errorf("cannot test group %s", g.Group))
}
예제 #6
0
파일: io.go 프로젝트: jordic/k8s
// 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("").Codec.Encode(pod)
	if err != nil {
		return fmt.Errorf("failed encoding pod: %v", err)
	}
	return ioutil.WriteFile(filePath, data, perm)
}
예제 #7
0
파일: helper.go 프로젝트: jordic/k8s
// 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("").GroupVersion
		return &copyGroupVersion
	}

	return config.GroupVersion
}
예제 #8
0
파일: jobs.go 프로젝트: jordic/k8s
// Delete deletes a job, returns error if one occurs.
func (c *jobs) Delete(name string, options *api.DeleteOptions) (err error) {
	if options == nil {
		return c.r.Delete().Namespace(c.ns).Resource("jobs").Name(name).Do().Error()
	}

	body, err := api.Scheme.EncodeToVersion(options, latest.GroupOrDie("").GroupVersion.String())
	if err != nil {
		return err
	}
	return c.r.Delete().Namespace(c.ns).Resource("jobs").Name(name).Body(body).Do().Error()
}
예제 #9
0
파일: io.go 프로젝트: jordic/k8s
// 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("").Codec.DecodeInto(podDef, pod); err != nil {
		return nil, fmt.Errorf("failed decoding file: %v", err)
	}
	return pod, nil
}
예제 #10
0
파일: testapi.go 프로젝트: jordic/k8s
func (g TestGroup) RESTMapper() meta.RESTMapper {
	return latest.GroupOrDie(g.Group).RESTMapper
}