Skip to content

Commit

Permalink
Merge pull request kubernetes#26733 from pmorie/pv-controller-typos
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Fix typo and linewrap comments in PV controller

Fix some typos and linewrap long comments that I found while going over this code investigating something.
  • Loading branch information
k8s-merge-robot committed Jun 3, 2016
2 parents d93f80c + 277c0a4 commit 59e008d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
16 changes: 8 additions & 8 deletions pkg/controller/persistentvolume/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ const annBoundByController = "pv.kubernetes.io/bound-by-controller"
const annClass = "volume.alpha.kubernetes.io/storage-class"

// This annotation is added to a PV that has been dynamically provisioned by
// Kubernetes. It's value is name of volume plugin that created the volume.
// Kubernetes. Its value is name of volume plugin that created the volume.
// It serves both user (to show where a PV comes from) and Kubernetes (to
// recognize dynamically provisioned PVs in its decissions).
// recognize dynamically provisioned PVs in its decisions).
const annDynamicallyProvisioned = "pv.kubernetes.io/provisioned-by"

// Name of a tag attached to a real volume in cloud (e.g. AWS EBS or GCE PD)
Expand All @@ -103,7 +103,7 @@ const createProvisionedPVInterval = 10 * time.Second

// PersistentVolumeController is a controller that synchronizes
// PersistentVolumeClaims and PersistentVolumes. It starts two
// framework.Controllers that watch PerstentVolume and PersistentVolumeClaim
// framework.Controllers that watch PersistentVolume and PersistentVolumeClaim
// changes.
type PersistentVolumeController struct {
volumeController *framework.Controller
Expand Down Expand Up @@ -670,8 +670,8 @@ func (ctrl *PersistentVolumeController) bindVolumeToClaim(volume *api.Persistent
return volume, nil
}

// bindClaimToVolume modifes given claim to be bound to a volume and saves it to
// API server. The volume is not modified in this method!
// bindClaimToVolume modifies the given claim to be bound to a volume and
// saves it to API server. The volume is not modified in this method!
func (ctrl *PersistentVolumeController) bindClaimToVolume(claim *api.PersistentVolumeClaim, volume *api.PersistentVolume) (*api.PersistentVolumeClaim, error) {
glog.V(4).Infof("updating PersistentVolumeClaim[%s]: binding to %q", claimToClaimKey(claim), volume.Name)

Expand Down Expand Up @@ -1198,7 +1198,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa
}

if err != nil {
// Delete failed several times. There is orphaned volume and there
// Delete failed several times. There is an orphaned volume and there
// is nothing we can do about it.
strerr := fmt.Sprintf("Error cleaning provisioned volume for claim %s: %v. Please delete manually.", claimToClaimKey(claim), err)
glog.V(2).Info(strerr)
Expand All @@ -1210,7 +1210,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claimObj interfa
}

// getProvisionedVolumeNameForClaim returns PV.Name for the provisioned volume.
// The name must be unique
// The name must be unique.
func (ctrl *PersistentVolumeController) getProvisionedVolumeNameForClaim(claim *api.PersistentVolumeClaim) string {
return "pvc-" + string(claim.UID)
}
Expand Down Expand Up @@ -1242,7 +1242,7 @@ func (ctrl *PersistentVolumeController) scheduleOperation(operationName string,
return
}

// Run the operation in separate goroutine
// Run the operation in a separate goroutine
go func() {
glog.V(4).Infof("scheduleOperation[%s]: running the operation", operationName)
operation(arg)
Expand Down
52 changes: 33 additions & 19 deletions pkg/controller/persistentvolume/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
"k8s.io/kubernetes/pkg/labels"
)

// persistentVolumeOrderedIndex is a cache.Store that keeps persistent volumes indexed by AccessModes and ordered by storage capacity.
// persistentVolumeOrderedIndex is a cache.Store that keeps persistent volumes
// indexed by AccessModes and ordered by storage capacity.
type persistentVolumeOrderedIndex struct {
store cache.Indexer
}
Expand All @@ -35,7 +36,8 @@ func newPersistentVolumeOrderedIndex() persistentVolumeOrderedIndex {
return persistentVolumeOrderedIndex{cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{"accessmodes": accessModesIndexFunc})}
}

// accessModesIndexFunc is an indexing function that returns a persistent volume's AccessModes as a string
// accessModesIndexFunc is an indexing function that returns a persistent
// volume's AccessModes as a string
func accessModesIndexFunc(obj interface{}) ([]string, error) {
if pv, ok := obj.(*api.PersistentVolume); ok {
modes := api.GetAccessModesAsString(pv.Spec.AccessModes)
Expand All @@ -44,7 +46,8 @@ func accessModesIndexFunc(obj interface{}) ([]string, error) {
return []string{""}, fmt.Errorf("object is not a persistent volume: %v", obj)
}

// listByAccessModes returns all volumes with the given set of AccessModeTypes. The list is unsorted!
// listByAccessModes returns all volumes with the given set of
// AccessModeTypes. The list is unsorted!
func (pvIndex *persistentVolumeOrderedIndex) listByAccessModes(modes []api.PersistentVolumeAccessMode) ([]*api.PersistentVolume, error) {
pv := &api.PersistentVolume{
Spec: api.PersistentVolumeSpec{
Expand All @@ -70,14 +73,19 @@ type matchPredicate func(compareThis, toThis *api.PersistentVolume) bool

// find returns the nearest PV from the ordered list or nil if a match is not found
func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *api.PersistentVolumeClaim, matchPredicate matchPredicate) (*api.PersistentVolume, error) {
// PVs are indexed by their access modes to allow easier searching. Each index is the string representation of a set of access modes.
// There is a finite number of possible sets and PVs will only be indexed in one of them (whichever index matches the PV's modes).
// PVs are indexed by their access modes to allow easier searching. Each
// index is the string representation of a set of access modes. There is a
// finite number of possible sets and PVs will only be indexed in one of
// them (whichever index matches the PV's modes).
//
// A request for resources will always specify its desired access modes. Any matching PV must have at least that number
// of access modes, but it can have more. For example, a user asks for ReadWriteOnce but a GCEPD is available, which is ReadWriteOnce+ReadOnlyMany.
// A request for resources will always specify its desired access modes.
// Any matching PV must have at least that number of access modes, but it
// can have more. For example, a user asks for ReadWriteOnce but a GCEPD
// is available, which is ReadWriteOnce+ReadOnlyMany.
//
// Searches are performed against a set of access modes, so we can attempt not only the exact matching modes but also
// potential matches (the GCEPD example above).
// Searches are performed against a set of access modes, so we can attempt
// not only the exact matching modes but also potential matches (the GCEPD
// example above).
allPossibleModes := pvIndex.allPossibleMatchingAccessModes(claim.Spec.AccessModes)

var smallestVolume *api.PersistentVolume
Expand Down Expand Up @@ -167,19 +175,23 @@ func matchStorageCapacity(pvA, pvB *api.PersistentVolume) bool {
return aSize <= bSize
}

// allPossibleMatchingAccessModes returns an array of AccessMode arrays that can satisfy a user's requested modes.
// allPossibleMatchingAccessModes returns an array of AccessMode arrays that
// can satisfy a user's requested modes.
//
// see comments in the Find func above regarding indexing.
//
// allPossibleMatchingAccessModes gets all stringified accessmodes from the index and returns all those that
// contain at least all of the requested mode.
// allPossibleMatchingAccessModes gets all stringified accessmodes from the
// index and returns all those that contain at least all of the requested
// mode.
//
// For example, assume the index contains 2 types of PVs where the stringified accessmodes are:
// For example, assume the index contains 2 types of PVs where the stringified
// accessmodes are:
//
// "RWO,ROX" -- some number of GCEPDs
// "RWO,ROX,RWX" -- some number of NFS volumes
//
// A request for RWO could be satisfied by both sets of indexed volumes, so allPossibleMatchingAccessModes returns:
// A request for RWO could be satisfied by both sets of indexed volumes, so
// allPossibleMatchingAccessModes returns:
//
// [][]api.PersistentVolumeAccessMode {
// []api.PersistentVolumeAccessMode {
Expand All @@ -190,16 +202,17 @@ func matchStorageCapacity(pvA, pvB *api.PersistentVolume) bool {
// },
// }
//
// A request for RWX can be satisfied by only one set of indexed volumes, so the return is:
// A request for RWX can be satisfied by only one set of indexed volumes, so
// the return is:
//
// [][]api.PersistentVolumeAccessMode {
// []api.PersistentVolumeAccessMode {
// api.ReadWriteOnce, api.ReadOnlyMany, api.ReadWriteMany,
// },
// }
//
// This func returns modes with ascending levels of modes to give the user what is closest to what they actually asked for.
//
// This func returns modes with ascending levels of modes to give the user
// what is closest to what they actually asked for.
func (pvIndex *persistentVolumeOrderedIndex) allPossibleMatchingAccessModes(requestedModes []api.PersistentVolumeAccessMode) [][]api.PersistentVolumeAccessMode {
matchedModes := [][]api.PersistentVolumeAccessMode{}
keys := pvIndex.store.ListIndexFuncValues("accessmodes")
Expand All @@ -210,8 +223,9 @@ func (pvIndex *persistentVolumeOrderedIndex) allPossibleMatchingAccessModes(requ
}
}

// sort by the number of modes in each array with the fewest number of modes coming first.
// this allows searching for volumes by the minimum number of modes required of the possible matches.
// sort by the number of modes in each array with the fewest number of
// modes coming first. this allows searching for volumes by the minimum
// number of modes required of the possible matches.
sort.Sort(byAccessModes{matchedModes})
return matchedModes
}
Expand Down

0 comments on commit 59e008d

Please sign in to comment.