StatefulSet controller no longer attempts to mutate v1.PodSpec.Hostname or v1.PodSpec.Subdomain

This commit is contained in:
Kenneth Owens
2017-08-21 11:48:56 -07:00
parent baf2f85e73
commit a6473d82dc
3 changed files with 10 additions and 62 deletions

View File

@@ -111,9 +111,7 @@ func identityMatches(set *apps.StatefulSet, pod *v1.Pod) bool {
return ordinal >= 0 &&
set.Name == parent &&
pod.Name == getPodName(set, ordinal) &&
pod.Namespace == set.Namespace &&
pod.Spec.Hostname == pod.Name &&
pod.Spec.Subdomain == set.Spec.ServiceName
pod.Namespace == set.Namespace
}
// storageMatches returns true if pod's Volumes cover the set of PersistentVolumeClaims
@@ -181,12 +179,18 @@ func updateStorage(set *apps.StatefulSet, pod *v1.Pod) {
pod.Spec.Volumes = newVolumes
}
func initIdentity(set *apps.StatefulSet, pod *v1.Pod) {
updateIdentity(set, pod)
// Set these immutable fields only on initial Pod creation, not updates.
pod.Spec.Hostname = pod.Name
pod.Spec.Subdomain = set.Spec.ServiceName
}
// updateIdentity updates pod's name, hostname, and subdomain to conform to set's name and headless service.
func updateIdentity(set *apps.StatefulSet, pod *v1.Pod) {
pod.Name = getPodName(set, getOrdinal(pod))
pod.Namespace = set.Namespace
pod.Spec.Hostname = pod.Name
pod.Spec.Subdomain = set.Spec.ServiceName
}
// isRunningAndReady returns true if pod is in the PodRunning Phase, if it has a condition of PodReady.
@@ -240,7 +244,7 @@ func getPodRevision(pod *v1.Pod) string {
func newStatefulSetPod(set *apps.StatefulSet, ordinal int) *v1.Pod {
pod, _ := controller.GetPodFromTemplate(&set.Spec.Template, set, metav1.NewControllerRef(set, controllerKind))
pod.Name = getPodName(set, ordinal)
updateIdentity(set, pod)
initIdentity(set, pod)
updateStorage(set, pod)
return pod
}