stateful_set_control.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package statefulset
  14. import (
  15. "math"
  16. "sort"
  17. apps "k8s.io/api/apps/v1"
  18. v1 "k8s.io/api/core/v1"
  19. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  20. utilerrors "k8s.io/apimachinery/pkg/util/errors"
  21. "k8s.io/client-go/tools/record"
  22. "k8s.io/klog"
  23. "k8s.io/kubernetes/pkg/controller/history"
  24. )
  25. // StatefulSetControl implements the control logic for updating StatefulSets and their children Pods. It is implemented
  26. // as an interface to allow for extensions that provide different semantics. Currently, there is only one implementation.
  27. type StatefulSetControlInterface interface {
  28. // UpdateStatefulSet implements the control logic for Pod creation, update, and deletion, and
  29. // persistent volume creation, update, and deletion.
  30. // If an implementation returns a non-nil error, the invocation will be retried using a rate-limited strategy.
  31. // Implementors should sink any errors that they do not wish to trigger a retry, and they may feel free to
  32. // exit exceptionally at any point provided they wish the update to be re-run at a later point in time.
  33. UpdateStatefulSet(set *apps.StatefulSet, pods []*v1.Pod) error
  34. // ListRevisions returns a array of the ControllerRevisions that represent the revisions of set. If the returned
  35. // error is nil, the returns slice of ControllerRevisions is valid.
  36. ListRevisions(set *apps.StatefulSet) ([]*apps.ControllerRevision, error)
  37. // AdoptOrphanRevisions adopts any orphaned ControllerRevisions that match set's Selector. If all adoptions are
  38. // successful the returned error is nil.
  39. AdoptOrphanRevisions(set *apps.StatefulSet, revisions []*apps.ControllerRevision) error
  40. }
  41. // NewDefaultStatefulSetControl returns a new instance of the default implementation StatefulSetControlInterface that
  42. // implements the documented semantics for StatefulSets. podControl is the PodControlInterface used to create, update,
  43. // and delete Pods and to create PersistentVolumeClaims. statusUpdater is the StatefulSetStatusUpdaterInterface used
  44. // to update the status of StatefulSets. You should use an instance returned from NewRealStatefulPodControl() for any
  45. // scenario other than testing.
  46. func NewDefaultStatefulSetControl(
  47. podControl StatefulPodControlInterface,
  48. statusUpdater StatefulSetStatusUpdaterInterface,
  49. controllerHistory history.Interface,
  50. recorder record.EventRecorder) StatefulSetControlInterface {
  51. return &defaultStatefulSetControl{podControl, statusUpdater, controllerHistory, recorder}
  52. }
  53. type defaultStatefulSetControl struct {
  54. podControl StatefulPodControlInterface
  55. statusUpdater StatefulSetStatusUpdaterInterface
  56. controllerHistory history.Interface
  57. recorder record.EventRecorder
  58. }
  59. // UpdateStatefulSet executes the core logic loop for a stateful set, applying the predictable and
  60. // consistent monotonic update strategy by default - scale up proceeds in ordinal order, no new pod
  61. // is created while any pod is unhealthy, and pods are terminated in descending order. The burst
  62. // strategy allows these constraints to be relaxed - pods will be created and deleted eagerly and
  63. // in no particular order. Clients using the burst strategy should be careful to ensure they
  64. // understand the consistency implications of having unpredictable numbers of pods available.
  65. func (ssc *defaultStatefulSetControl) UpdateStatefulSet(set *apps.StatefulSet, pods []*v1.Pod) error {
  66. // list all revisions and sort them
  67. revisions, err := ssc.ListRevisions(set)
  68. if err != nil {
  69. return err
  70. }
  71. history.SortControllerRevisions(revisions)
  72. currentRevision, updateRevision, err := ssc.performUpdate(set, pods, revisions)
  73. if err != nil {
  74. return utilerrors.NewAggregate([]error{err, ssc.truncateHistory(set, pods, revisions, currentRevision, updateRevision)})
  75. }
  76. // maintain the set's revision history limit
  77. return ssc.truncateHistory(set, pods, revisions, currentRevision, updateRevision)
  78. }
  79. func (ssc *defaultStatefulSetControl) performUpdate(
  80. set *apps.StatefulSet, pods []*v1.Pod, revisions []*apps.ControllerRevision) (*apps.ControllerRevision, *apps.ControllerRevision, error) {
  81. // get the current, and update revisions
  82. currentRevision, updateRevision, collisionCount, err := ssc.getStatefulSetRevisions(set, revisions)
  83. if err != nil {
  84. return currentRevision, updateRevision, err
  85. }
  86. // perform the main update function and get the status
  87. status, err := ssc.updateStatefulSet(set, currentRevision, updateRevision, collisionCount, pods)
  88. if err != nil {
  89. return currentRevision, updateRevision, err
  90. }
  91. // update the set's status
  92. err = ssc.updateStatefulSetStatus(set, status)
  93. if err != nil {
  94. return currentRevision, updateRevision, err
  95. }
  96. klog.V(4).Infof("StatefulSet %s/%s pod status replicas=%d ready=%d current=%d updated=%d",
  97. set.Namespace,
  98. set.Name,
  99. status.Replicas,
  100. status.ReadyReplicas,
  101. status.CurrentReplicas,
  102. status.UpdatedReplicas)
  103. klog.V(4).Infof("StatefulSet %s/%s revisions current=%s update=%s",
  104. set.Namespace,
  105. set.Name,
  106. status.CurrentRevision,
  107. status.UpdateRevision)
  108. return currentRevision, updateRevision, nil
  109. }
  110. func (ssc *defaultStatefulSetControl) ListRevisions(set *apps.StatefulSet) ([]*apps.ControllerRevision, error) {
  111. selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
  112. if err != nil {
  113. return nil, err
  114. }
  115. return ssc.controllerHistory.ListControllerRevisions(set, selector)
  116. }
  117. func (ssc *defaultStatefulSetControl) AdoptOrphanRevisions(
  118. set *apps.StatefulSet,
  119. revisions []*apps.ControllerRevision) error {
  120. for i := range revisions {
  121. adopted, err := ssc.controllerHistory.AdoptControllerRevision(set, controllerKind, revisions[i])
  122. if err != nil {
  123. return err
  124. }
  125. revisions[i] = adopted
  126. }
  127. return nil
  128. }
  129. // truncateHistory truncates any non-live ControllerRevisions in revisions from set's history. The UpdateRevision and
  130. // CurrentRevision in set's Status are considered to be live. Any revisions associated with the Pods in pods are also
  131. // considered to be live. Non-live revisions are deleted, starting with the revision with the lowest Revision, until
  132. // only RevisionHistoryLimit revisions remain. If the returned error is nil the operation was successful. This method
  133. // expects that revisions is sorted when supplied.
  134. func (ssc *defaultStatefulSetControl) truncateHistory(
  135. set *apps.StatefulSet,
  136. pods []*v1.Pod,
  137. revisions []*apps.ControllerRevision,
  138. current *apps.ControllerRevision,
  139. update *apps.ControllerRevision) error {
  140. history := make([]*apps.ControllerRevision, 0, len(revisions))
  141. // mark all live revisions
  142. live := map[string]bool{}
  143. if current != nil {
  144. live[current.Name] = true
  145. }
  146. if update != nil {
  147. live[update.Name] = true
  148. }
  149. for i := range pods {
  150. live[getPodRevision(pods[i])] = true
  151. }
  152. // collect live revisions and historic revisions
  153. for i := range revisions {
  154. if !live[revisions[i].Name] {
  155. history = append(history, revisions[i])
  156. }
  157. }
  158. historyLen := len(history)
  159. historyLimit := int(*set.Spec.RevisionHistoryLimit)
  160. if historyLen <= historyLimit {
  161. return nil
  162. }
  163. // delete any non-live history to maintain the revision limit.
  164. history = history[:(historyLen - historyLimit)]
  165. for i := 0; i < len(history); i++ {
  166. if err := ssc.controllerHistory.DeleteControllerRevision(history[i]); err != nil {
  167. return err
  168. }
  169. }
  170. return nil
  171. }
  172. // getStatefulSetRevisions returns the current and update ControllerRevisions for set. It also
  173. // returns a collision count that records the number of name collisions set saw when creating
  174. // new ControllerRevisions. This count is incremented on every name collision and is used in
  175. // building the ControllerRevision names for name collision avoidance. This method may create
  176. // a new revision, or modify the Revision of an existing revision if an update to set is detected.
  177. // This method expects that revisions is sorted when supplied.
  178. func (ssc *defaultStatefulSetControl) getStatefulSetRevisions(
  179. set *apps.StatefulSet,
  180. revisions []*apps.ControllerRevision) (*apps.ControllerRevision, *apps.ControllerRevision, int32, error) {
  181. var currentRevision, updateRevision *apps.ControllerRevision
  182. revisionCount := len(revisions)
  183. history.SortControllerRevisions(revisions)
  184. // Use a local copy of set.Status.CollisionCount to avoid modifying set.Status directly.
  185. // This copy is returned so the value gets carried over to set.Status in updateStatefulSet.
  186. var collisionCount int32
  187. if set.Status.CollisionCount != nil {
  188. collisionCount = *set.Status.CollisionCount
  189. }
  190. // create a new revision from the current set
  191. updateRevision, err := newRevision(set, nextRevision(revisions), &collisionCount)
  192. if err != nil {
  193. return nil, nil, collisionCount, err
  194. }
  195. // find any equivalent revisions
  196. equalRevisions := history.FindEqualRevisions(revisions, updateRevision)
  197. equalCount := len(equalRevisions)
  198. if equalCount > 0 && history.EqualRevision(revisions[revisionCount-1], equalRevisions[equalCount-1]) {
  199. // if the equivalent revision is immediately prior the update revision has not changed
  200. updateRevision = revisions[revisionCount-1]
  201. } else if equalCount > 0 {
  202. // if the equivalent revision is not immediately prior we will roll back by incrementing the
  203. // Revision of the equivalent revision
  204. updateRevision, err = ssc.controllerHistory.UpdateControllerRevision(
  205. equalRevisions[equalCount-1],
  206. updateRevision.Revision)
  207. if err != nil {
  208. return nil, nil, collisionCount, err
  209. }
  210. } else {
  211. //if there is no equivalent revision we create a new one
  212. updateRevision, err = ssc.controllerHistory.CreateControllerRevision(set, updateRevision, &collisionCount)
  213. if err != nil {
  214. return nil, nil, collisionCount, err
  215. }
  216. }
  217. // attempt to find the revision that corresponds to the current revision
  218. for i := range revisions {
  219. if revisions[i].Name == set.Status.CurrentRevision {
  220. currentRevision = revisions[i]
  221. break
  222. }
  223. }
  224. // if the current revision is nil we initialize the history by setting it to the update revision
  225. if currentRevision == nil {
  226. currentRevision = updateRevision
  227. }
  228. return currentRevision, updateRevision, collisionCount, nil
  229. }
  230. // updateStatefulSet performs the update function for a StatefulSet. This method creates, updates, and deletes Pods in
  231. // the set in order to conform the system to the target state for the set. The target state always contains
  232. // set.Spec.Replicas Pods with a Ready Condition. If the UpdateStrategy.Type for the set is
  233. // RollingUpdateStatefulSetStrategyType then all Pods in the set must be at set.Status.CurrentRevision.
  234. // If the UpdateStrategy.Type for the set is OnDeleteStatefulSetStrategyType, the target state implies nothing about
  235. // the revisions of Pods in the set. If the UpdateStrategy.Type for the set is PartitionStatefulSetStrategyType, then
  236. // all Pods with ordinal less than UpdateStrategy.Partition.Ordinal must be at Status.CurrentRevision and all other
  237. // Pods must be at Status.UpdateRevision. If the returned error is nil, the returned StatefulSetStatus is valid and the
  238. // update must be recorded. If the error is not nil, the method should be retried until successful.
  239. func (ssc *defaultStatefulSetControl) updateStatefulSet(
  240. set *apps.StatefulSet,
  241. currentRevision *apps.ControllerRevision,
  242. updateRevision *apps.ControllerRevision,
  243. collisionCount int32,
  244. pods []*v1.Pod) (*apps.StatefulSetStatus, error) {
  245. // get the current and update revisions of the set.
  246. currentSet, err := ApplyRevision(set, currentRevision)
  247. if err != nil {
  248. return nil, err
  249. }
  250. updateSet, err := ApplyRevision(set, updateRevision)
  251. if err != nil {
  252. return nil, err
  253. }
  254. // set the generation, and revisions in the returned status
  255. status := apps.StatefulSetStatus{}
  256. status.ObservedGeneration = set.Generation
  257. status.CurrentRevision = currentRevision.Name
  258. status.UpdateRevision = updateRevision.Name
  259. status.CollisionCount = new(int32)
  260. *status.CollisionCount = collisionCount
  261. replicaCount := int(*set.Spec.Replicas)
  262. // slice that will contain all Pods such that 0 <= getOrdinal(pod) < set.Spec.Replicas
  263. replicas := make([]*v1.Pod, replicaCount)
  264. // slice that will contain all Pods such that set.Spec.Replicas <= getOrdinal(pod)
  265. condemned := make([]*v1.Pod, 0, len(pods))
  266. unhealthy := 0
  267. firstUnhealthyOrdinal := math.MaxInt32
  268. var firstUnhealthyPod *v1.Pod
  269. // First we partition pods into two lists valid replicas and condemned Pods
  270. for i := range pods {
  271. status.Replicas++
  272. // count the number of running and ready replicas
  273. if isRunningAndReady(pods[i]) {
  274. status.ReadyReplicas++
  275. }
  276. // count the number of current and update replicas
  277. if isCreated(pods[i]) && !isTerminating(pods[i]) {
  278. if getPodRevision(pods[i]) == currentRevision.Name {
  279. status.CurrentReplicas++
  280. }
  281. if getPodRevision(pods[i]) == updateRevision.Name {
  282. status.UpdatedReplicas++
  283. }
  284. }
  285. if ord := getOrdinal(pods[i]); 0 <= ord && ord < replicaCount {
  286. // if the ordinal of the pod is within the range of the current number of replicas,
  287. // insert it at the indirection of its ordinal
  288. replicas[ord] = pods[i]
  289. } else if ord >= replicaCount {
  290. // if the ordinal is greater than the number of replicas add it to the condemned list
  291. condemned = append(condemned, pods[i])
  292. }
  293. // If the ordinal could not be parsed (ord < 0), ignore the Pod.
  294. }
  295. // for any empty indices in the sequence [0,set.Spec.Replicas) create a new Pod at the correct revision
  296. for ord := 0; ord < replicaCount; ord++ {
  297. if replicas[ord] == nil {
  298. replicas[ord] = newVersionedStatefulSetPod(
  299. currentSet,
  300. updateSet,
  301. currentRevision.Name,
  302. updateRevision.Name, ord)
  303. }
  304. }
  305. // sort the condemned Pods by their ordinals
  306. sort.Sort(ascendingOrdinal(condemned))
  307. // find the first unhealthy Pod
  308. for i := range replicas {
  309. if !isHealthy(replicas[i]) {
  310. unhealthy++
  311. if ord := getOrdinal(replicas[i]); ord < firstUnhealthyOrdinal {
  312. firstUnhealthyOrdinal = ord
  313. firstUnhealthyPod = replicas[i]
  314. }
  315. }
  316. }
  317. for i := range condemned {
  318. if !isHealthy(condemned[i]) {
  319. unhealthy++
  320. if ord := getOrdinal(condemned[i]); ord < firstUnhealthyOrdinal {
  321. firstUnhealthyOrdinal = ord
  322. firstUnhealthyPod = condemned[i]
  323. }
  324. }
  325. }
  326. if unhealthy > 0 {
  327. klog.V(4).Infof("StatefulSet %s/%s has %d unhealthy Pods starting with %s",
  328. set.Namespace,
  329. set.Name,
  330. unhealthy,
  331. firstUnhealthyPod.Name)
  332. }
  333. // If the StatefulSet is being deleted, don't do anything other than updating
  334. // status.
  335. if set.DeletionTimestamp != nil {
  336. return &status, nil
  337. }
  338. monotonic := !allowsBurst(set)
  339. // Examine each replica with respect to its ordinal
  340. for i := range replicas {
  341. // delete and recreate failed pods
  342. if isFailed(replicas[i]) {
  343. ssc.recorder.Eventf(set, v1.EventTypeWarning, "RecreatingFailedPod",
  344. "StatefulSet %s/%s is recreating failed Pod %s",
  345. set.Namespace,
  346. set.Name,
  347. replicas[i].Name)
  348. if err := ssc.podControl.DeleteStatefulPod(set, replicas[i]); err != nil {
  349. return &status, err
  350. }
  351. if getPodRevision(replicas[i]) == currentRevision.Name {
  352. status.CurrentReplicas--
  353. }
  354. if getPodRevision(replicas[i]) == updateRevision.Name {
  355. status.UpdatedReplicas--
  356. }
  357. status.Replicas--
  358. replicas[i] = newVersionedStatefulSetPod(
  359. currentSet,
  360. updateSet,
  361. currentRevision.Name,
  362. updateRevision.Name,
  363. i)
  364. }
  365. // If we find a Pod that has not been created we create the Pod
  366. if !isCreated(replicas[i]) {
  367. if err := ssc.podControl.CreateStatefulPod(set, replicas[i]); err != nil {
  368. return &status, err
  369. }
  370. status.Replicas++
  371. if getPodRevision(replicas[i]) == currentRevision.Name {
  372. status.CurrentReplicas++
  373. }
  374. if getPodRevision(replicas[i]) == updateRevision.Name {
  375. status.UpdatedReplicas++
  376. }
  377. // if the set does not allow bursting, return immediately
  378. if monotonic {
  379. return &status, nil
  380. }
  381. // pod created, no more work possible for this round
  382. continue
  383. }
  384. // If we find a Pod that is currently terminating, we must wait until graceful deletion
  385. // completes before we continue to make progress.
  386. if isTerminating(replicas[i]) && monotonic {
  387. klog.V(4).Infof(
  388. "StatefulSet %s/%s is waiting for Pod %s to Terminate",
  389. set.Namespace,
  390. set.Name,
  391. replicas[i].Name)
  392. return &status, nil
  393. }
  394. // If we have a Pod that has been created but is not running and ready we can not make progress.
  395. // We must ensure that all for each Pod, when we create it, all of its predecessors, with respect to its
  396. // ordinal, are Running and Ready.
  397. if !isRunningAndReady(replicas[i]) && monotonic {
  398. klog.V(4).Infof(
  399. "StatefulSet %s/%s is waiting for Pod %s to be Running and Ready",
  400. set.Namespace,
  401. set.Name,
  402. replicas[i].Name)
  403. return &status, nil
  404. }
  405. // Enforce the StatefulSet invariants
  406. if identityMatches(set, replicas[i]) && storageMatches(set, replicas[i]) {
  407. continue
  408. }
  409. // Make a deep copy so we don't mutate the shared cache
  410. replica := replicas[i].DeepCopy()
  411. if err := ssc.podControl.UpdateStatefulPod(updateSet, replica); err != nil {
  412. return &status, err
  413. }
  414. }
  415. // At this point, all of the current Replicas are Running and Ready, we can consider termination.
  416. // We will wait for all predecessors to be Running and Ready prior to attempting a deletion.
  417. // We will terminate Pods in a monotonically decreasing order over [len(pods),set.Spec.Replicas).
  418. // Note that we do not resurrect Pods in this interval. Also note that scaling will take precedence over
  419. // updates.
  420. for target := len(condemned) - 1; target >= 0; target-- {
  421. // wait for terminating pods to expire
  422. if isTerminating(condemned[target]) {
  423. klog.V(4).Infof(
  424. "StatefulSet %s/%s is waiting for Pod %s to Terminate prior to scale down",
  425. set.Namespace,
  426. set.Name,
  427. condemned[target].Name)
  428. // block if we are in monotonic mode
  429. if monotonic {
  430. return &status, nil
  431. }
  432. continue
  433. }
  434. // if we are in monotonic mode and the condemned target is not the first unhealthy Pod block
  435. if !isRunningAndReady(condemned[target]) && monotonic && condemned[target] != firstUnhealthyPod {
  436. klog.V(4).Infof(
  437. "StatefulSet %s/%s is waiting for Pod %s to be Running and Ready prior to scale down",
  438. set.Namespace,
  439. set.Name,
  440. firstUnhealthyPod.Name)
  441. return &status, nil
  442. }
  443. klog.V(2).Infof("StatefulSet %s/%s terminating Pod %s for scale down",
  444. set.Namespace,
  445. set.Name,
  446. condemned[target].Name)
  447. if err := ssc.podControl.DeleteStatefulPod(set, condemned[target]); err != nil {
  448. return &status, err
  449. }
  450. if getPodRevision(condemned[target]) == currentRevision.Name {
  451. status.CurrentReplicas--
  452. }
  453. if getPodRevision(condemned[target]) == updateRevision.Name {
  454. status.UpdatedReplicas--
  455. }
  456. if monotonic {
  457. return &status, nil
  458. }
  459. }
  460. // for the OnDelete strategy we short circuit. Pods will be updated when they are manually deleted.
  461. if set.Spec.UpdateStrategy.Type == apps.OnDeleteStatefulSetStrategyType {
  462. return &status, nil
  463. }
  464. // we compute the minimum ordinal of the target sequence for a destructive update based on the strategy.
  465. updateMin := 0
  466. if set.Spec.UpdateStrategy.RollingUpdate != nil {
  467. updateMin = int(*set.Spec.UpdateStrategy.RollingUpdate.Partition)
  468. }
  469. // we terminate the Pod with the largest ordinal that does not match the update revision.
  470. for target := len(replicas) - 1; target >= updateMin; target-- {
  471. // delete the Pod if it is not already terminating and does not match the update revision.
  472. if getPodRevision(replicas[target]) != updateRevision.Name && !isTerminating(replicas[target]) {
  473. klog.V(2).Infof("StatefulSet %s/%s terminating Pod %s for update",
  474. set.Namespace,
  475. set.Name,
  476. replicas[target].Name)
  477. err := ssc.podControl.DeleteStatefulPod(set, replicas[target])
  478. status.CurrentReplicas--
  479. return &status, err
  480. }
  481. // wait for unhealthy Pods on update
  482. if !isHealthy(replicas[target]) {
  483. klog.V(4).Infof(
  484. "StatefulSet %s/%s is waiting for Pod %s to update",
  485. set.Namespace,
  486. set.Name,
  487. replicas[target].Name)
  488. return &status, nil
  489. }
  490. }
  491. return &status, nil
  492. }
  493. // updateStatefulSetStatus updates set's Status to be equal to status. If status indicates a complete update, it is
  494. // mutated to indicate completion. If status is semantically equivalent to set's Status no update is performed. If the
  495. // returned error is nil, the update is successful.
  496. func (ssc *defaultStatefulSetControl) updateStatefulSetStatus(
  497. set *apps.StatefulSet,
  498. status *apps.StatefulSetStatus) error {
  499. // complete any in progress rolling update if necessary
  500. completeRollingUpdate(set, status)
  501. // if the status is not inconsistent do not perform an update
  502. if !inconsistentStatus(set, status) {
  503. return nil
  504. }
  505. // copy set and update its status
  506. set = set.DeepCopy()
  507. if err := ssc.statusUpdater.UpdateStatefulSetStatus(set, status); err != nil {
  508. return err
  509. }
  510. return nil
  511. }
  512. var _ StatefulSetControlInterface = &defaultStatefulSetControl{}