type InTreePlugin … const fsTypeKey … const csiFsTypeKey … const zoneKey … const zonesKey … // replaceTopology overwrites an existing key in NodeAffinity by a new one. // If there are any newKey already exist in an expression of a term, we will // not combine the replaced key Values with the existing ones. // So there might be duplication if there is any newKey expression // already in the terms. func replaceTopology(pv *v1.PersistentVolume, oldKey, newKey string) error { … } // getTopologyValues returns all unique topology values with the given key found in // the PV NodeAffinity. Sort by alphabetical order. // This function collapses multiple zones into a list that is ORed. This assumes that // the plugin does not support a constraint like key in "zone1" AND "zone2" func getTopologyValues(pv *v1.PersistentVolume, key string) []string { … } // addTopology appends the topology to the given PV to all Terms. func addTopology(pv *v1.PersistentVolume, topologyKey string, zones []string) error { … } // translateTopologyFromInTreeToCSI converts existing zone labels or in-tree topology to CSI topology. // In-tree topology has precedence over zone labels. When both in-tree topology and zone labels exist // for a particular CSI topology, in-tree topology will be used. // This function will remove the Beta version Kubernetes topology label in case the node upgrade to a // newer version where it does not have any Beta topology label anymore func translateTopologyFromInTreeToCSI(pv *v1.PersistentVolume, csiTopologyKey string) error { … } // getTopologyLabel checks if the kubernetes topology label used in this // PV is GA and return the zone/region label used. // The version checking follows the following orders // 1. Check NodeAffinity // 1.1 Check if zoneGA exists, if yes return GA labels // 1.2 Check if zoneBeta exists, if yes return Beta labels // 2. Check PV labels // 2.1 Check if zoneGA exists, if yes return GA labels // 2.2 Check if zoneBeta exists, if yes return Beta labels func getTopologyLabel(pv *v1.PersistentVolume) (zoneLabel string, regionLabel string) { … } // TopologyKeyExist checks if a certain key exists in a VolumeNodeAffinity func TopologyKeyExist(key string, vna *v1.VolumeNodeAffinity) bool { … } type regionParserFn … // translateTopologyFromCSIToInTree translate a CSI topology to // Kubernetes topology and add topology labels to it. Note that this function // will only work for plugin with a single topologyKey that translates to // Kubernetes zone(and region if regionParser is passed in). // If a plugin has more than one topologyKey, it will need to be processed // separately by the plugin. // If regionParser is nil, no region NodeAffinity will be added. If not nil, // it'll be passed to regionTopologyHandler, which will add region topology NodeAffinity // and labels for the given PV. It assumes the Zone NodeAffinity already exists. // In short this function will, // 1. Replace all CSI topology to Kubernetes Zone topology label // 2. Process and generate region topology if a regionParser is passed // 3. Add Kubernetes Topology labels(zone) if they do not exist func translateTopologyFromCSIToInTree(pv *v1.PersistentVolume, csiTopologyKey string, regionParser regionParserFn) error { … } // translateAllowedTopologies translates allowed topologies within storage class or PV // from legacy failure domain to given CSI topology key func translateAllowedTopologies(terms []v1.TopologySelectorTerm, key string) ([]v1.TopologySelectorTerm, error) { … } // regionTopologyHandler will process the PV and add region // kubernetes topology label to its NodeAffinity and labels // It assumes the Zone NodeAffinity already exists // Each provider is responsible for providing their own regionParser func regionTopologyHandler(pv *v1.PersistentVolume, regionParser regionParserFn) error { … }