当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.PersistentVolumes方法代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/client.Client.PersistentVolumes方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.PersistentVolumes方法的具体用法?Golang Client.PersistentVolumes怎么用?Golang Client.PersistentVolumes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在k8s/io/kubernetes/pkg/client.Client的用法示例。


在下文中一共展示了Client.PersistentVolumes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: createPersistentVolume

func createPersistentVolume(cmd *cobra.Command, ns string, c *k8sclient.Client, fac *cmdutil.Factory) (Result, error) {
	flags := cmd.Flags()
	hostPath := flags.Lookup(hostPathFlag).Value.String()
	name := flags.Lookup(nameFlag).Value.String()
	pvs := c.PersistentVolumes()
	rc, err := pvs.List(labels.Everything(), fields.Everything())
	if err != nil {
		util.Errorf("Failed to load PersistentVolumes with error %v", err)
		return Failure, err
	}
	items := rc.Items
	for _, volume := range items {
		// TODO use the external load balancer as a way to know if we should create a route?
		vname := volume.ObjectMeta.Name
		if vname == name {
			util.Infof("Already created PersistentVolumes for %s\n", name)
			return Success, nil
		}
	}
	if hostPath == "" {
		return missingFlag(cmd, hostPathFlag)
	}
	if confirmAction(flags) == false {
		return Failure, nil
	}

	// lets create a new PV
	util.Infof("PersistentVolume name %s will be created on host path %s\n", name, hostPath)
	pv := api.PersistentVolume{
		ObjectMeta: api.ObjectMeta{
			Name: name,
		},
		Spec: api.PersistentVolumeSpec{
			Capacity: api.ResourceList{
				api.ResourceName(api.ResourceStorage): resource.MustParse("100G"),
			},
			AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteMany},
			PersistentVolumeSource: api.PersistentVolumeSource{
				HostPath: &api.HostPathVolumeSource{Path: hostPath},
			},
		},
	}

	_, err = pvs.Create(&pv)
	if err != nil {
		util.Errorf("Failed to create PersistentVolume %s at %s with error %v", name, hostPath, err)
		return Failure, err
	}
	return Success, nil
}
开发者ID:ALRubinger,项目名称:gofabric8,代码行数:50,代码来源:volume.go

示例2:

			serverPorts: []int{2049},
		}

		defer func() {
			volumeTestCleanup(c, config)
		}()

		pod := startVolumeServer(c, config)
		serverIP := pod.Status.PodIP
		Logf("NFS server IP address: %v", serverIP)

		pv := makePersistentVolume(serverIP)
		pvc := makePersistentVolumeClaim(ns)

		Logf("Creating PersistentVolume using NFS")
		pv, err := c.PersistentVolumes().Create(pv)
		Expect(err).NotTo(HaveOccurred())

		Logf("Creating PersistentVolumeClaim")
		pvc, err = c.PersistentVolumeClaims(ns).Create(pvc)
		Expect(err).NotTo(HaveOccurred())

		// allow the binder a chance to catch up.  should not be more than 20s.
		waitForPersistentVolumePhase(api.VolumeBound, c, pv.Name, 1*time.Second, 30*time.Second)

		pv, err = c.PersistentVolumes().Get(pv.Name)
		Expect(err).NotTo(HaveOccurred())
		if pv.Spec.ClaimRef == nil {
			Failf("Expected PersistentVolume to be bound, but got nil ClaimRef: %+v", pv)
		}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:30,代码来源:persistent_volumes.go


注:本文中的k8s/io/kubernetes/pkg/client.Client.PersistentVolumes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。