當前位置: 首頁>>代碼示例>>Golang>>正文


Golang api.PersistentVolume類代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/api.PersistentVolume的典型用法代碼示例。如果您正苦於以下問題:Golang PersistentVolume類的具體用法?Golang PersistentVolume怎麽用?Golang PersistentVolume使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PersistentVolume類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Provision

func (r *glusterfsVolumeProvisioner) Provision() (*api.PersistentVolume, error) {
	var err error
	if r.options.PVC.Spec.Selector != nil {
		glog.V(4).Infof("glusterfs: not able to parse your claim Selector")
		return nil, fmt.Errorf("glusterfs: not able to parse your claim Selector")
	}
	glog.V(4).Infof("glusterfs: Provison VolumeOptions %v", r.options)
	scName := storageutil.GetClaimStorageClass(r.options.PVC)
	cfg, err := parseClassParameters(r.options.Parameters, r.plugin.host.GetKubeClient())
	if err != nil {
		return nil, err
	}
	r.provisioningConfig = *cfg

	glog.V(4).Infof("glusterfs: creating volume with configuration %+v", r.provisioningConfig)

	gidTable, err := r.plugin.getGidTable(scName, cfg.gidMin, cfg.gidMax)
	if err != nil {
		return nil, fmt.Errorf("glusterfs: failed to get gidTable: %v", err)
	}

	gid, _, err := gidTable.AllocateNext()
	if err != nil {
		glog.Errorf("glusterfs: failed to reserve gid from table: %v", err)
		return nil, fmt.Errorf("glusterfs: failed to reserve gid from table: %v", err)
	}

	glog.V(2).Infof("glusterfs: got gid [%d] for PVC %s", gid, r.options.PVC.Name)

	glusterfs, sizeGB, err := r.CreateVolume(gid)
	if err != nil {
		if release_err := gidTable.Release(gid); release_err != nil {
			glog.Errorf("glusterfs:  error when releasing gid in storageclass: %s", scName)
		}

		glog.Errorf("glusterfs: create volume err: %v.", err)
		return nil, fmt.Errorf("glusterfs: create volume err: %v.", err)
	}
	pv := new(api.PersistentVolume)
	pv.Spec.PersistentVolumeSource.Glusterfs = glusterfs
	pv.Spec.PersistentVolumeReclaimPolicy = r.options.PersistentVolumeReclaimPolicy
	pv.Spec.AccessModes = r.options.PVC.Spec.AccessModes
	if len(pv.Spec.AccessModes) == 0 {
		pv.Spec.AccessModes = r.plugin.GetAccessModes()
	}

	gidStr := strconv.FormatInt(int64(gid), 10)
	pv.Annotations = map[string]string{volumehelper.VolumeGidAnnotationKey: gidStr}

	pv.Spec.Capacity = api.ResourceList{
		api.ResourceName(api.ResourceStorage): resource.MustParse(fmt.Sprintf("%dGi", sizeGB)),
	}
	return pv, nil
}
開發者ID:jsafrane,項目名稱:origin,代碼行數:54,代碼來源:glusterfs.go

示例2: addVolumeAnnotation

func addVolumeAnnotation(volume *api.PersistentVolume, annName, annValue string) *api.PersistentVolume {
	if volume.Annotations == nil {
		volume.Annotations = make(map[string]string)
	}
	volume.Annotations[annName] = annValue
	return volume
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:7,代碼來源:controller_test.go

示例3: CreatePersistentVolume

func (c *mockControllerClient) CreatePersistentVolume(pv *api.PersistentVolume) (*api.PersistentVolume, error) {
	if pv.GenerateName != "" && pv.Name == "" {
		pv.Name = fmt.Sprintf(pv.GenerateName, util.NewUUID())
	}
	c.volume = pv
	return c.volume, nil
}
開發者ID:richm,項目名稱:origin,代碼行數:7,代碼來源:persistentvolume_provisioner_controller_test.go

示例4: newVolume

// newVolume returns a new volume with given attributes
func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase api.PersistentVolumePhase, reclaimPolicy api.PersistentVolumeReclaimPolicy, annotations ...string) *api.PersistentVolume {
	volume := api.PersistentVolume{
		ObjectMeta: api.ObjectMeta{
			Name:            name,
			ResourceVersion: "1",
		},
		Spec: api.PersistentVolumeSpec{
			Capacity: api.ResourceList{
				api.ResourceName(api.ResourceStorage): resource.MustParse(capacity),
			},
			PersistentVolumeSource: api.PersistentVolumeSource{
				GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{},
			},
			AccessModes:                   []api.PersistentVolumeAccessMode{api.ReadWriteOnce, api.ReadOnlyMany},
			PersistentVolumeReclaimPolicy: reclaimPolicy,
		},
		Status: api.PersistentVolumeStatus{
			Phase: phase,
		},
	}

	if boundToClaimName != "" {
		volume.Spec.ClaimRef = &api.ObjectReference{
			Kind:       "PersistentVolumeClaim",
			APIVersion: "v1",
			UID:        types.UID(boundToClaimUID),
			Namespace:  testNamespace,
			Name:       boundToClaimName,
		}
	}

	if len(annotations) > 0 {
		volume.Annotations = make(map[string]string)
		for _, a := range annotations {
			switch a {
			case annDynamicallyProvisioned:
				volume.Annotations[a] = mockPluginName
			case annClass:
				volume.Annotations[a] = "gold"
			default:
				volume.Annotations[a] = "yes"
			}
		}
	}

	return &volume
}
開發者ID:ncdc,項目名稱:kubernetes,代碼行數:48,代碼來源:framework_test.go

示例5: paramToAnnotations

func paramToAnnotations(admin, adminSecretNamespace, adminSecretName string, pv *api.PersistentVolume) {
	if pv.Annotations == nil {
		pv.Annotations = make(map[string]string)
	}
	pv.Annotations[annCephAdminID] = admin
	pv.Annotations[annCephAdminSecretName] = adminSecretName
	pv.Annotations[annCephAdminSecretNameSpace] = adminSecretNamespace
}
開發者ID:Random-Liu,項目名稱:kubernetes,代碼行數:8,代碼來源:rbd.go

示例6: AddVolumeAnnotations

// AddVolumeAnnotations adds a golang Map as annotation to a PersistentVolume
func AddVolumeAnnotations(pv *api.PersistentVolume, annotations map[string]string) {
	if pv.Annotations == nil {
		pv.Annotations = map[string]string{}
	}

	for k, v := range annotations {
		pv.Annotations[k] = v
	}
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:10,代碼來源:util.go

示例7: Provision

func (r *glusterfsVolumeProvisioner) Provision() (*api.PersistentVolume, error) {
	var err error
	var reqGid int64
	gidRandomizer := rand.New(rand.NewSource(time.Now().UnixNano()))
	if r.options.PVC.Spec.Selector != nil {
		glog.V(4).Infof("glusterfs: not able to parse your claim Selector")
		return nil, fmt.Errorf("glusterfs: not able to parse your claim Selector")
	}
	glog.V(4).Infof("glusterfs: Provison VolumeOptions %v", r.options)

	cfg, err := parseClassParameters(r.options.Parameters, r.plugin.host.GetKubeClient())
	if err != nil {
		return nil, err
	}
	r.provisioningConfig = *cfg
	glog.V(4).Infof("glusterfs: creating volume with configuration %+v", r.provisioningConfig)
	reqGid = gidMin + gidRandomizer.Int63n(gidMax)
	glusterfs, sizeGB, err := r.CreateVolume(reqGid)
	if err != nil {
		glog.Errorf("glusterfs: create volume err: %v.", err)
		return nil, fmt.Errorf("glusterfs: create volume err: %v.", err)
	}
	pv := new(api.PersistentVolume)
	pv.Spec.PersistentVolumeSource.Glusterfs = glusterfs
	pv.Spec.PersistentVolumeReclaimPolicy = r.options.PersistentVolumeReclaimPolicy
	pv.Spec.AccessModes = r.options.PVC.Spec.AccessModes
	if len(pv.Spec.AccessModes) == 0 {
		pv.Spec.AccessModes = r.plugin.GetAccessModes()
	}
	sGid := strconv.FormatInt(reqGid, 10)
	pv.Annotations = map[string]string{volumehelper.VolumeGidAnnotationKey: sGid}
	pv.Spec.Capacity = api.ResourceList{
		api.ResourceName(api.ResourceStorage): resource.MustParse(fmt.Sprintf("%dGi", sizeGB)),
	}
	return pv, nil
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:36,代碼來源:glusterfs.go

示例8: Provision

func (c *awsElasticBlockStoreProvisioner) Provision(pv *api.PersistentVolume) error {
	volumeID, sizeGB, labels, err := c.manager.CreateVolume(c)
	if err != nil {
		return err
	}
	pv.Spec.PersistentVolumeSource.AWSElasticBlockStore.VolumeID = volumeID
	pv.Spec.Capacity = api.ResourceList{
		api.ResourceName(api.ResourceStorage): resource.MustParse(fmt.Sprintf("%dGi", sizeGB)),
	}

	if len(labels) != 0 {
		if pv.Labels == nil {
			pv.Labels = make(map[string]string)
		}
		for k, v := range labels {
			pv.Labels[k] = v
		}
	}

	return nil
}
開發者ID:thed00de,項目名稱:hypernetes,代碼行數:21,代碼來源:aws_ebs.go


注:本文中的k8s/io/kubernetes/pkg/api.PersistentVolume類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。