Repository navigation
Description
Followup from #645. ServingState as implemented today, and especially as proposed in #645 (comment), mixes spec and status in a way that makes its intended behavior unclear (to me). Here's an alternate design that implements the same behavior while keeping spec and status separate. It also (IMHO) provides a better separation of responsibilities for each controller.
API changes proposed
- Add Scale sub-resource to Revision. Autoscalers use the Revision's Scale API to propose scale changes. See docs here for how to add Scale to a custom resource. (FYI this is a new feature in Kubernetes 1.10)
- Reduce ServingState to two possible values: Active and Inactive. Revisions are initially in the Active state. The activator updates the ServingState field to tell the revision controller when to expect traffic on a revision.
- Create Condition(s) for Revision controller to communicate deactivation progress. This includes the Reserve (all resources deleted, but still routed) and Retired (no longer routed) states previously encoded in ServingState.
- Add activation state to Route Traffic status. This state signals to the activator whether a revision should be Active or Inactive, and is driven by the revision's Ready status as observed by the route controller.
Activation Flows
A <- B is “component A senses signal B”.
A -> B is “component A effects change B”.
Scale to zero
-
Autoscaler <- (metrics)
-
Autoscaler -> revision Scale = 0
-
Revision controller <- revision Scale == 0
-
Revision controller -> revision Ready = False
-
Route controller <- revision Ready == False
-
Route controller -> route Traffic Rule = Inactive
-
Activator <- route Traffic Rule Status == Inactive
-
Activator -> revision ServingState = Inactive
-
Revision controller <- revision ServingState == Inactive
-
Revision controller -> deployment Scale = 0 (and other resource teardown)
-
Revision controller -> (revision deactivation progress)
Scale from zero
-
Activator <- (traffic)
-
Activator -> revision ServingState = Active
-
Revision controller <- revision ServingState == Active
-
Revision controller -> Scale = N
-
Revision controller -> Deployment Scale = N (plus other resource turnup)
-
Revision controller <- Deployment Scale == N (plus other resource status)
-
Revision controller -> Ready = True
-
Route controller <- revision Ready == True
-
Route controller -> route Traffic Rule = Active
-
Activator <- route Traffic Rule Status == Active
-
Activator -> (forward queued requests)


Activity
drewinglis commentedon Apr 16, 2018
/cc @vaikas-google
drewinglis commentedon Apr 16, 2018
Grant and I just spent a few minutes chatting about this. I have a few minor comments, but overall this LGTM. (And it eliminates a race where we could drop traffic. Way to bury the lede! :))
Nits:
This may not be necessary; you could also have the Autoscaler set
Revision.Conditions.Readyinstead.I think this should start as Active, to keep the behavior the same as it is currently (it might be good to explicitly specify this).
N.b. currently Reserve refers to the revision being scaled to 0 and all resources deleted, but still in a route.
grantr commentedon Apr 17, 2018
That would work, but it feels cleaner to me to make the Revision status (including conditions) only writable by the revision controller.
If other controllers can update revision status, there is a risk of racing or flapping between those controllers and the revision controller. For example: a security vulnerability was found in a revision's image, and it has to immediately scale down, but the rebuild with the security fix failed and the revision can't scale back up again until it succeeds. The revision needs to be unready but the autoscaler will force it back to ready because it's still getting traffic. This is a fanciful example but the point is that the revision's lifecycle can be arbitrarily complex, and the autoscaler's input is but one signal that the revision controller must consider.
Philosophically, the revision lifecycle will be easier to understand and modify if it's entirely contained in and owned by the revision controller. If the autoscaler also implements revision lifecycle logic, along with the activator and the route controller, IMO it will be difficult to get a complete picture of how the revision actually works, and even more difficult to modify and test it.
Agreed, I updated the issue body above.
Correct, I misunderstood this. @mattmoor separately pointed out that there is no practical difference between Reserve and Retired as implemented today.
drewinglis commentedon Apr 17, 2018
I think as proposed currently the spec is actually pretty resilient to this (modulo the race from Active -> Reserve state that we've already identified, and the corresponding one in the opposite direction, but those only drop traffic, not corrupt the controller state). In the example you proposed, I think the correct solution would not be to modify ServingState, but instead to take the revision out of all TrafficTargets, which would cause the ServingState to be set to Retired and all the Revision's resources to be deleted.
I've gotten a bit off topic here, though. :)
Correct, though we (currently) are planning to use Retired/Reserve to differentiate between "the route needs to exist, but pointing to the activator" and "the route should be deleted".
grantr commentedon Apr 19, 2018
@josephburnett pointed out an issue with the activator's behavior as proposed above.
When a revision has first been scaled from zero, it will have spec ServingState == Active but status Ready == false. Because Ready == false, the Route will continue to have status Rule == Inactive.
This presents a conflict for the activator: it prefers to set ServingState = Inactive when Rule == Inactive. In the just activated case, it knows there are requests enqueued so it can resolve the conflict and do nothing. However, if the activator restarts, or if another component sets ServingState = Active, the activator won't know how to resolve the conflict. As described above, it doesn't have enough information to derive the intended state of the system. A naive implementation would immediately set ServingState back to Inactive as soon as it was set to Active, making it impossible to activate a revision.
@josephburnett (IIUC, correct me if I'm wrong Joe) proposes moving the Active/Inactive ServingState field to the Route TrafficTarget spec and using the scale API to signal to the revision that it should scale to or from zero. I'm still thinking about the implications of that change.
mattmoor commentedon Oct 31, 2018
ServingState is gone.