本文整理匯總了Golang中vulcan/kubernetes/pkg/api/latest.GroupOrDie函數的典型用法代碼示例。如果您正苦於以下問題:Golang GroupOrDie函數的具體用法?Golang GroupOrDie怎麽用?Golang GroupOrDie使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GroupOrDie函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
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("").Version will be latest.GroupVersion after we
// have multiple group support
Groups[""] = TestGroup{"", latest.GroupOrDie("").Version, latest.GroupOrDie("").GroupVersion}
}
if _, ok := Groups["extensions"]; !ok {
Groups["extensions"] = TestGroup{"extensions", latest.GroupOrDie("extensions").Version, latest.GroupOrDie("extensions").GroupVersion}
}
Default = Groups[""]
Extensions = Groups["extensions"]
}
示例2: thirdpartyapi
func (m *Master) thirdpartyapi(group, kind, version string) *apiserver.APIGroupVersion {
resourceStorage := thirdpartyresourcedataetcd.NewREST(m.thirdPartyStorage, group, kind)
apiRoot := makeThirdPartyPath("")
storage := map[string]rest.Storage{
strings.ToLower(kind) + "s": resourceStorage,
}
return &apiserver.APIGroupVersion{
Root: apiRoot,
Version: apiutil.GetGroupVersion(group, version),
Creater: thirdpartyresourcedata.NewObjectCreator(group, version, api.Scheme),
Convertor: api.Scheme,
Typer: api.Scheme,
Mapper: thirdpartyresourcedata.NewMapper(latest.GroupOrDie("extensions").RESTMapper, kind, version, group),
Codec: thirdpartyresourcedata.NewCodec(latest.GroupOrDie("extensions").Codec, kind),
Linker: latest.GroupOrDie("extensions").SelfLinker,
Storage: storage,
ServerVersion: latest.GroupOrDie("").GroupVersion,
Context: m.requestContextMapper,
MinRequestTimeout: m.minRequestTimeout,
}
}
示例3: TestExpapi
// TestExpapi verifies that the unexported exapi creates
// the an experimental unversioned.APIGroupVersion.
func TestExpapi(t *testing.T) {
master, config, assert := setUp(t)
expAPIGroup := master.experimental(&config)
assert.Equal(expAPIGroup.Root, master.apiGroupPrefix)
assert.Equal(expAPIGroup.Mapper, latest.GroupOrDie("extensions").RESTMapper)
assert.Equal(expAPIGroup.Codec, latest.GroupOrDie("extensions").Codec)
assert.Equal(expAPIGroup.Linker, latest.GroupOrDie("extensions").SelfLinker)
assert.Equal(expAPIGroup.Version, latest.GroupOrDie("extensions").GroupVersion)
}
示例4: TestInterfacesFor
func TestInterfacesFor(t *testing.T) {
if _, err := latest.GroupOrDie("extensions").InterfacesFor(""); err == nil {
t.Fatalf("unexpected non-error: %v", err)
}
for i, groupVersion := range append([]string{latest.GroupOrDie("extensions").GroupVersion}, latest.GroupOrDie("extensions").GroupVersions...) {
if vi, err := latest.GroupOrDie("extensions").InterfacesFor(groupVersion); err != nil || vi == nil {
t.Fatalf("%d: unexpected result: %v", i, err)
}
}
}
示例5: testPodWithVolume
func testPodWithVolume(image, path string, source *api.EmptyDirVolumeSource) *api.Pod {
podName := "pod-" + string(util.NewUUID())
return &api.Pod{
TypeMeta: unversioned.TypeMeta{
Kind: "Pod",
APIVersion: latest.GroupOrDie("").Version,
},
ObjectMeta: api.ObjectMeta{
Name: podName,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: containerName,
Image: image,
VolumeMounts: []api.VolumeMount{
{
Name: volumeName,
MountPath: path,
},
},
},
},
RestartPolicy: api.RestartPolicyNever,
Volumes: []api.Volume{
{
Name: volumeName,
VolumeSource: api.VolumeSource{
EmptyDir: source,
},
},
},
},
}
}
示例6: encodePods
// encodePods creates an api.PodList object from pods and returns the encoded
// PodList.
func encodePods(pods []*api.Pod) (data []byte, err error) {
podList := new(api.PodList)
for _, pod := range pods {
podList.Items = append(podList.Items, *pod)
}
return latest.GroupOrDie("").Codec.Encode(podList)
}
示例7: rcByNameContainer
func rcByNameContainer(name string, replicas int, image string, labels map[string]string, c api.Container) *api.ReplicationController {
// Add "name": name to the labels, overwriting if it exists.
labels["name"] = name
return &api.ReplicationController{
TypeMeta: unversioned.TypeMeta{
Kind: "ReplicationController",
APIVersion: latest.GroupOrDie("").Version,
},
ObjectMeta: api.ObjectMeta{
Name: name,
},
Spec: api.ReplicationControllerSpec{
Replicas: replicas,
Selector: map[string]string{
"name": name,
},
Template: &api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: labels,
},
Spec: api.PodSpec{
Containers: []api.Container{c},
},
},
},
}
}
示例8: createPodSpec
func (config *KubeletManagedHostConfig) createPodSpec(podName string) *api.Pod {
pod := &api.Pod{
TypeMeta: unversioned.TypeMeta{
Kind: "Pod",
APIVersion: latest.GroupOrDie("").Version,
},
ObjectMeta: api.ObjectMeta{
Name: podName,
Namespace: config.f.Namespace.Name,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "busybox-1",
Image: kubeletEtcHostsImageName,
ImagePullPolicy: api.PullIfNotPresent,
Command: []string{
"sleep",
"900",
},
},
{
Name: "busybox-2",
Image: kubeletEtcHostsImageName,
ImagePullPolicy: api.PullIfNotPresent,
Command: []string{
"sleep",
"900",
},
},
{
Name: "busybox-3",
Image: kubeletEtcHostsImageName,
ImagePullPolicy: api.PullIfNotPresent,
Command: []string{
"sleep",
"900",
},
VolumeMounts: []api.VolumeMount{
{
Name: "host-etc-hosts",
MountPath: "/etc/hosts",
},
},
},
},
Volumes: []api.Volume{
{
Name: "host-etc-hosts",
VolumeSource: api.VolumeSource{
HostPath: &api.HostPathVolumeSource{
Path: "/etc/hosts",
},
},
},
},
},
}
return pod
}
示例9: TestCodec
func TestCodec(t *testing.T) {
daemonSet := extensions.DaemonSet{}
// We do want to use package latest rather than testapi here, because we
// want to test if the package install and package latest work as expected.
data, err := latest.GroupOrDie("extensions").Codec.Encode(&daemonSet)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
other := extensions.DaemonSet{}
if err := json.Unmarshal(data, &other); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if other.APIVersion != latest.GroupOrDie("extensions").GroupVersion || other.Kind != "DaemonSet" {
t.Errorf("unexpected unmarshalled object %#v", other)
}
}
示例10: setExtensionsDefaults
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 == "" {
config.Version = g.GroupVersion
//}
versionInterfaces, err := g.InterfacesFor(config.Version)
if err != nil {
return fmt.Errorf("Extensions API version '%s' is not recognized (valid values: %s)",
config.Version, 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
}
示例11: 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.
// 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 len(config.Version) == 0 {
config.Version = defaultVersionFor(config)
}
version := config.Version
versionInterfaces, err := latest.GroupOrDie("").InterfacesFor(version)
if err != nil {
return fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, 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
}
示例12: runAMaster
func runAMaster(t *testing.T) (*master.Master, *httptest.Server) {
etcdStorage, err := master.NewEtcdStorage(newEtcdClient(), latest.GroupOrDie("").InterfacesFor, testapi.Default.Version(), etcdtest.PathPrefix())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
storageDestinations := master.NewStorageDestinations()
storageDestinations.AddAPIGroup("", etcdStorage)
m := master.New(&master.Config{
StorageDestinations: storageDestinations,
KubeletClient: client.FakeKubeletClient{},
EnableCoreControllers: true,
EnableLogsSupport: false,
EnableProfiling: true,
EnableUISupport: false,
APIPrefix: "/api",
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
AdmissionControl: admit.NewAlwaysAdmit(),
StorageVersions: map[string]string{"": testapi.Default.Version()},
})
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
m.Handler.ServeHTTP(w, req)
}))
return m, s
}
示例13: createTestPodSpec
func (config *KubeProxyTestConfig) createTestPodSpec() *api.Pod {
pod := &api.Pod{
TypeMeta: unversioned.TypeMeta{
Kind: "Pod",
APIVersion: latest.GroupOrDie("").Version,
},
ObjectMeta: api.ObjectMeta{
Name: testPodName,
Namespace: config.f.Namespace.Name,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "webserver",
Image: netexecImageName,
ImagePullPolicy: api.PullIfNotPresent,
Command: []string{
"/netexec",
fmt.Sprintf("--http-port=%d", endpointHttpPort),
fmt.Sprintf("--udp-port=%d", endpointUdpPort),
},
Ports: []api.ContainerPort{
{
Name: "http",
ContainerPort: testContainerHttpPort,
},
},
},
},
},
}
return pod
}
示例14: TestCodec
func TestCodec(t *testing.T) {
pod := internal.Pod{}
// We do want to use package latest rather than testapi here, because we
// want to test if the package install and package latest work as expected.
data, err := latest.GroupOrDie("").Codec.Encode(&pod)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
other := internal.Pod{}
if err := json.Unmarshal(data, &other); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if other.APIVersion != latest.GroupOrDie("").Version || other.Kind != "Pod" {
t.Errorf("unexpected unmarshalled object %#v", other)
}
}
示例15: defaultAPIGroupVersion
func (m *Master) defaultAPIGroupVersion() *apiserver.APIGroupVersion {
return &apiserver.APIGroupVersion{
Root: m.apiPrefix,
Mapper: latest.GroupOrDie("").RESTMapper,
Creater: api.Scheme,
Convertor: api.Scheme,
Typer: api.Scheme,
Linker: latest.GroupOrDie("").SelfLinker,
Admit: m.admissionControl,
Context: m.requestContextMapper,
MinRequestTimeout: m.minRequestTimeout,
}
}