Merge pull request #16866 from justinsb/zone_labels_on_nodes
Auto commit by PR queue bot
This commit is contained in:
		
							
								
								
									
										20
									
								
								pkg/api/unversioned/well_known_labels.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								pkg/api/unversioned/well_known_labels.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| /* | ||||
| Copyright 2015 The Kubernetes Authors All rights reserved. | ||||
|  | ||||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| you may not use this file except in compliance with the License. | ||||
| You may obtain a copy of the License at | ||||
|  | ||||
|     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  | ||||
| Unless required by applicable law or agreed to in writing, software | ||||
| distributed under the License is distributed on an "AS IS" BASIS, | ||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| See the License for the specific language governing permissions and | ||||
| limitations under the License. | ||||
| */ | ||||
|  | ||||
| package unversioned | ||||
|  | ||||
| const LabelZoneFailureDomain = "kubernetes.io/zone-failure-domain" | ||||
| const LabelZoneRegion = "kubernetes.io/zone-region" | ||||
| @@ -898,6 +898,23 @@ func (kl *Kubelet) initialNodeStatus() (*api.Node, error) { | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
|  | ||||
| 		// If the cloud has zone information, label the node with the zone information | ||||
| 		zones, ok := kl.cloud.Zones() | ||||
| 		if ok { | ||||
| 			zone, err := zones.GetZone() | ||||
| 			if err != nil { | ||||
| 				return nil, fmt.Errorf("failed to get zone from cloud provider: %v", err) | ||||
| 			} | ||||
| 			if zone.FailureDomain != "" { | ||||
| 				glog.Infof("Adding node label from cloud provider: %s=%s", unversioned.LabelZoneFailureDomain, zone.FailureDomain) | ||||
| 				node.ObjectMeta.Labels[unversioned.LabelZoneFailureDomain] = zone.FailureDomain | ||||
| 			} | ||||
| 			if zone.Region != "" { | ||||
| 				glog.Infof("Adding node label from cloud provider: %s=%s", unversioned.LabelZoneRegion, zone.Region) | ||||
| 				node.ObjectMeta.Labels[unversioned.LabelZoneRegion] = zone.Region | ||||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
| 		node.Spec.ExternalID = kl.hostname | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 k8s-merge-robot
					k8s-merge-robot