本文整理汇总了Golang中k8s/io/kubernetes/pkg/api.PersistentVolumeClaim类的典型用法代码示例。如果您正苦于以下问题:Golang PersistentVolumeClaim类的具体用法?Golang PersistentVolumeClaim怎么用?Golang PersistentVolumeClaim使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistentVolumeClaim类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newClaim
// newClaim returns a new claim with given attributes
func newClaim(name, claimUID, capacity, boundToVolume string, phase api.PersistentVolumeClaimPhase, annotations ...string) *api.PersistentVolumeClaim {
claim := api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: testNamespace,
UID: types.UID(claimUID),
ResourceVersion: "1",
},
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce, api.ReadOnlyMany},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse(capacity),
},
},
VolumeName: boundToVolume,
},
Status: api.PersistentVolumeClaimStatus{
Phase: phase,
},
}
// Make sure api.GetReference(claim) works
claim.ObjectMeta.SelfLink = testapi.Default.SelfLink("pvc", name)
if len(annotations) > 0 {
claim.Annotations = make(map[string]string)
for _, a := range annotations {
claim.Annotations[a] = "yes"
}
}
return &claim
}
示例2: newClaim
func newClaim(ns string, alpha bool) *api.PersistentVolumeClaim {
claim := api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
GenerateName: "pvc-",
Namespace: ns,
},
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse(requestedSize),
},
},
},
}
if alpha {
claim.Annotations = map[string]string{
storageutil.AlphaStorageClassAnnotation: "",
}
} else {
claim.Annotations = map[string]string{
storageutil.StorageClassAnnotation: "fast",
}
}
return &claim
}
示例3: newClaim
func newClaim(t storageClassTest, ns, suffix string, alpha bool) *api.PersistentVolumeClaim {
claim := api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
GenerateName: "pvc-",
Namespace: ns,
},
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse(t.claimSize),
},
},
},
}
if alpha {
claim.Annotations = map[string]string{
"volume.alpha.kubernetes.io/storage-class": "",
}
} else {
claim.Annotations = map[string]string{
"volume.beta.kubernetes.io/storage-class": "myclass-" + suffix,
}
}
return &claim
}
示例4: newClaim
// newClaim returns a new claim with given attributes
func newClaim(name, claimUID, capacity, boundToVolume string, phase api.PersistentVolumeClaimPhase, annotations ...string) *api.PersistentVolumeClaim {
claim := api.PersistentVolumeClaim{
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: testNamespace,
UID: types.UID(claimUID),
ResourceVersion: "1",
},
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce, api.ReadOnlyMany},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse(capacity),
},
},
VolumeName: boundToVolume,
},
Status: api.PersistentVolumeClaimStatus{
Phase: phase,
},
}
// Make sure api.GetReference(claim) works
claim.ObjectMeta.SelfLink = testapi.Default.SelfLink("pvc", name)
if len(annotations) > 0 {
claim.Annotations = make(map[string]string)
for _, a := range annotations {
switch a {
case storageutil.StorageClassAnnotation:
claim.Annotations[a] = "gold"
case annStorageProvisioner:
claim.Annotations[a] = mockPluginName
default:
claim.Annotations[a] = "yes"
}
}
}
// Bound claims must have proper Status.
if phase == api.ClaimBound {
claim.Status.AccessModes = claim.Spec.AccessModes
// For most of the tests it's enough to copy claim's requested capacity,
// individual tests can adjust it using withExpectedCapacity()
claim.Status.Capacity = claim.Spec.Resources.Requests
}
return &claim
}
示例5: CouchdbPVClaim
// create pvc claim for couchdb pod, used for rc spawner
// pvc name is automatically generated by kubernetes
// @param cluster *CouchdbCluster - cluster that will be using this pvc
// @return *api.PersistentVolumeClaim - filled pvc claim struct ready to be created
func (cluster *CouchdbCluster) CouchdbPVClaim() *api.PersistentVolumeClaim {
// resource list
rsList := make(api.ResourceList)
// SIZE
rsList[api.ResourceStorage] = *(resource.NewQuantity(COUCHDB_VOLUME_SIZE, resource.BinarySI))
// pvc SPEC, witch readWriteOnce access mode
pvcSpec := api.PersistentVolumeClaimSpec{AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce}}
pvcSpec.Resources.Requests = api.ResourceList(rsList)
// PVC
pvc := api.PersistentVolumeClaim{Spec: pvcSpec}
pvc.GenerateName = CLUSTER_PREFIX + cluster.Tag + "-"
pvc.Labels = cluster.Labels
return &pvc
}
示例6: CreatePetSet
// PetSet - available only in kubernetes v1.3+
// big advantage: it allow create persistentVolume template
// this template can create persistent volumeClaim for each POD automatically
//
// create petSet for couchdb cluster
// init all necessary struct for petSet and then via kube client creates it
// @ param cluster - struct CouchdbCluster - required:
// @return extensions.Deployment - created kube deployment
// @return error - errors that occur during creation
//
func (cluster *CouchdbCluster) CreatePetSet() (*apps.PetSet, error) {
/*
PET SET, included in kube 1.3+
http://kubernetes-v1-3.github.io/docs/user-guide/petset/
// TESTING - ALPHA
*/
// pod template with volumes
podTemplate := *cluster.CouchdbPodTemplate(true, CLUSTER_PREFIX+cluster.Tag)
// pet set spec label selector
lSelector := unversioned.LabelSelector{MatchLabels: cluster.Labels}
// pvc claim
pvc := api.PersistentVolumeClaim{}
pvc.Name = CLUSTER_PREFIX + cluster.Tag
pvc.Annotations = make(map[string]string)
pvc.Annotations["volume.alpha.kubernetes.io/storage-class"] = "anything"
// resource list for pvc claim template
rsList := make(api.ResourceList)
// SIZE
rsList[api.ResourceStorage] = *(resource.NewQuantity(5*1024*1024*1024, resource.BinarySI))
// pvc SPEC
pvcSpec := api.PersistentVolumeClaimSpec{}
pvcSpec.Resources.Requests = api.ResourceList(rsList)
pvc.Spec = pvcSpec
// pet set specs
petSetSPec := apps.PetSetSpec{Replicas: int(cluster.Replicas), Template: podTemplate,
Selector: &lSelector, VolumeClaimTemplates: []api.PersistentVolumeClaim{pvc}}
// pet set
petSet := apps.PetSet{Spec: petSetSPec}
petSet.Name = CLUSTER_PREFIX + cluster.Tag
petSet.Labels = cluster.Labels
// get a new kube extensions client
c, err := KubeClientApps(KUBE_API)
// check for errors
if err != nil {
ErrorLog("kube_control: createPetSet: Cannot connect to Kubernetes api ")
ErrorLog(err)
return nil, err
} else {
// create deployment
return c.PetSets(cluster.Namespace).Create(&petSet)
}
}