Example #1
0
func init() {
	validGroupVersions := map[unversioned.GroupVersion]bool{
		unversioned.GroupVersion{Group: "", Version: "v1"}:                      true,
		unversioned.GroupVersion{Group: "extensions", Version: "v1beta1"}:       true,
		unversioned.GroupVersion{Group: "componentconfig", Version: "v1alpha1"}: true,
		unversioned.GroupVersion{Group: "metrics", Version: "v1alpha1"}:         true,
	}

	// The default list of supported api versions, in order of most preferred to the least.
	supportedVersions := []unversioned.GroupVersion{
		{Group: "", Version: "v1"},
		{Group: "extensions", Version: "v1beta1"},
		{Group: "componentconfig", Version: "v1alpha1"},
	}

	// Env var KUBE_API_VERSIONS is a comma separated list of API versions that should be registered in the scheme.
	// The versions should be in the order of most preferred to the least.
	userRequestedVersions := os.Getenv("KUBE_API_VERSIONS")
	if len(userRequestedVersions) != 0 {
		// reset the supported versions
		supportedVersions = []unversioned.GroupVersion{}
		for _, version := range strings.Split(userRequestedVersions, ",") {
			gv, err := unversioned.ParseGroupVersion(version)
			if err != nil {
				glog.Fatalf("invalid api version: %s in KUBE_API_VERSIONS: %s. List of valid API versions: %v",
					version, os.Getenv("KUBE_API_VERSIONS"), validGroupVersions)
			}

			// Verify that the version is valid.
			valid, ok := validGroupVersions[gv]
			if !ok || !valid {
				// Not a valid API version.
				glog.Fatalf("invalid api version: %s in KUBE_API_VERSIONS: %s. List of valid API versions: %v",
					version, os.Getenv("KUBE_API_VERSIONS"), validGroupVersions)
			}

			supportedVersions = append(supportedVersions, gv)
		}
	}

	RegisteredGroupVersions = supportedVersions
}
Example #2
0
File: node.go Project: jordic/k8s
func GetHostname(hostnameOverride string) string {
	hostname := hostnameOverride
	if string(hostname) == "" {
		nodename, err := exec.Command("uname", "-n").Output()
		if err != nil {
			glog.Fatalf("Couldn't determine hostname: %v", err)
		}
		hostname = string(nodename)
	}
	return strings.ToLower(strings.TrimSpace(hostname))
}