Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kubectl stop rc with sequence numbers #9739

Merged
merged 1 commit into from
Jun 19, 2015

Conversation

bprashanth
Copy link
Contributor

Introduces the concept of sequence numbers for rcs fixing the behavior of kubectl stop rc in the process.
@lavalamp @bgrant0607 #9147

Still need to think of a good description string and look at why the conversion generating script doesn't autogenerate for rc.Spec changes (https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/api/v1/conversion.go#L30)

@smarterclayton
Copy link
Contributor

Is sequenceNumber the right name? I assume this a pattern we'll use in the future for other reasons.

@@ -47,14 +48,26 @@ func (rcStrategy) NamespaceScoped() bool {
func (rcStrategy) PrepareForCreate(obj runtime.Object) {
controller := obj.(*api.ReplicationController)
controller.Status = api.ReplicationControllerStatus{}
controller.Spec.SequenceNumber = 0
controller.Spec.SequenceNumber = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i meant status

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably this should not be here at all; it looks like defaulting, so it should go in defaulting code, but 0 is the default for a number anyway so you don't really need to do anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, the intent here is to override the specification in rc.json, if any

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh-- gotcha. I think it's not important to do that though-- does it cause any harm if it starts out with seq 42?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why allow it? I think people might be tempted to update if we allow initialization (the only use case i can think of is cloning all the keys by getting and reputting to a diffferent apiserver). I'm fine defaulting the SequenceNumber to the answer to life the universe and everything, if that's what you meant :)

@lavalamp
Copy link
Member

@smarterclayton Yeah, it's a general pattern. SequenceNumber is the most obvious name, but that doesn't mean there's not a better name possible :)

I think the interesting debate to have about it is:
a) Does it go in metadata? (IMO: yes)
b) Do we implement it for all objects? (IMO: eventually, yes-- but it doesn't have to work everywhere immediately)
c) Does this imply that there should only be a single writer of obj.Status? (IMO: Yes! This should force us to clarify our rapidly-increasing-in-complexity web of object readers & writers.)

@lavalamp
Copy link
Member

The basic idea, of course, is to give you some idea about what version of the object is being used by the object's actuator, so that you can--in a generic way--tell when the system has quiesced.

@bgrant0607 I've forgotten why we can't just have the actuator just reiterate the resourceVersion that it's acting on? Is this only because updates to status also increase the resourceVersion, or is there another reason, too?

@@ -998,14 +998,16 @@ type ReplicationControllerSpec struct {
// insufficient replicas are detected. Internally, this takes precedence over a
// TemplateRef.
// Must be set before converting to a v1beta1 or v1beta2 API object.
Template *PodTemplateSpec `json:"template,omitempty"`
Template *PodTemplateSpec `json:"template,omitempty"`
SequenceNumber int `json:"sequenceNumber"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int64-- no ints in the API, they are variable-width.

@k8s-bot
Copy link

k8s-bot commented Jun 12, 2015

GCE e2e build/test passed for commit 379916efde76ee47ffb825884aea63416dcc940f.

// Any changes to the spec increment the sequence number, any changes to the
// status reflect the sequence number of the corresponding spec
if !reflect.DeepEqual(oldController.Spec, newController.Spec) {
newController.Spec.SequenceNumber += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be newController.Spec.SequenceNumber = oldController.Spec.SequenceNumber + 1 otherwise it's gameable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure that's easy enough to do, but so is the resource version right (this is the logic i've mostly applied when thinking about what to validate etc)? if someone tries to game it, all bets are off

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resourceVersion is generated by etcd & isn't gameable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if someone doesn't re-get but just iterates through all the rvs
I agree it's different in that etcd will also reject if it's different

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a different kind of gaming. We can't ultimately stop a client that's determined to get it wrong. But we can ignore the seq # they pass in :)

@lavalamp
Copy link
Member

And adding to my earlier list--
d) Some objects may be dependent on other objects. E.g., arguably endpoints should be using the sequence number from the service object.

...now that I think about it, endpoints should really be a subresource of services, or part of service.status.

@bprashanth
Copy link
Contributor Author

I've forgotten why we can't just have the actuator just reiterate the resourceVersion that it's acting on? Is this only because updates to status also increase the resourceVersion, or is there another reason, too?

I can't think into the future enough to say it's safe to compare the resource version, even of a single resource, against itself. can we assume a future version of the same resource will have a higher resource version even if its from a different member/shard? The sequence number going up property is useful when a client wants to know the controller has seen an update, but doesn't care if it's seen many updates after that.

@smarterclayton
Copy link
Contributor

On Jun 12, 2015, at 6:13 PM, Daniel Smith notifications@github.com wrote:

@smarterclayton Yeah, it's a general pattern. SequenceNumber is the most obvious name, but that doesn't mean there's not a better name possible :)

I think the interesting debate to have about it is:
a) Does it go in metadata? (IMO: yes)

Agree, unless we have a need to subdivide the object into multiple sets, but it's likely those objects probably need a different pattern anyway.
b) Do we implemented for all objects? (IMO: eventually, yes-- but it doesn't have to work everywhere immediately)

Or an object which doesn't have an obvious actuator just doesn't expose it in status. For instance, a service isn't actuated so much as propagated.
c) Does this imply that there should only be a single writer of obj.Status? (IMO: Yes! This should force us to clarify our rapidly-increasing-in-complexity web of object readers & writers.)


Reply to this email directly or view it on GitHub.

@lavalamp
Copy link
Member

The sequence number going up property is useful when a client wants to know the controller has seen an update, but doesn't care if it's seen many updates after that.

Ah, yes, thank you-- I forgot about that part. We want to allow >=, not just ==.

}

// ReplicationControllerStatus represents the current status of a replication
// controller.
type ReplicationControllerStatus struct {
// Replicas is the number of actual replicas.
Replicas int `json:"replicas" description:"most recently oberved number of replicas"`
Replicas int `json:"replicas" description:"most recently oberved number of replicas"`
SequenceNumber int `json:"sequenceNumber" description:""`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing descriptions in swagger

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured people will change what i write anyway, so I'd just leave it blank till someone says: write this :)

@bprashanth
Copy link
Contributor Author

PTAL, moved the Status.SequenceNumber code into the controller manager and added some more unittests

@k8s-bot
Copy link

k8s-bot commented Jun 15, 2015

GCE e2e build/test passed for commit cc767d3e32c4eb06f62d63eca2abe8a6157cdead.

@k8s-bot
Copy link

k8s-bot commented Jun 15, 2015

GCE e2e build/test passed for commit 915d36b0f848225ec6d8acde693e4b36f8a74bba.

@k8s-bot
Copy link

k8s-bot commented Jun 15, 2015

GCE e2e build/test passed for commit 7bb39e4a2a2fb3f703087850454d7f847c3266cf.

for i, rc := 0, &controller; ; i++ {
rc.Status.Replicas = numReplicas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra blank line

@lavalamp
Copy link
Member

I think this looks pretty good. I'd like to nail down whether sequenceNumber should go in metadata or in spec before we merge it, though.

@smarterclayton
Copy link
Contributor

I haven't thought of a concrete reason to need two sequence numbers that couldn't be solved in spec directly (container sequence, for instance). If we add this to metadata we probably want to define it for objects which don't have clear specs (something like a user record, or an event). Also, probably need to clarify whether it applies to spec for things like nodes (answer is probably yes, but spec is a bit less clear for that type).

On Jun 15, 2015, at 7:15 PM, Daniel Smith notifications@github.com wrote:

I think this looks pretty good. I'd like to nail down whether sequenceNumber should go in metadata or in spec before we merge it, though.


Reply to this email directly or view it on GitHub.

@@ -998,14 +998,16 @@ type ReplicationControllerSpec struct {
// insufficient replicas are detected. Internally, this takes precedence over a
// TemplateRef.
// Must be set before converting to a v1beta1 or v1beta2 API object.
Template *PodTemplateSpec `json:"template,omitempty"`
Template *PodTemplateSpec `json:"template,omitempty"`
SequenceNumber int64 `json:"sequenceNumber"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bprashanth mind adding a comment for this, since we are under api?

@bgrant0607
Copy link
Member

See also #7328

@bprashanth
Copy link
Contributor Author

'Pologies for the delay, got sidetracked debugging an unrelated e2e failure to confirm it's not this change. Might still update some of the comments/descriptions but my latest set of commits has a Generation embedded in the object. PTAL.

@k8s-bot
Copy link

k8s-bot commented Jun 18, 2015

GCE e2e build/test passed for commit f75736f48e4553ccf218482756986b2bdd391252.

@k8s-bot
Copy link

k8s-bot commented Jun 19, 2015

GCE e2e build/test passed for commit 52f559bb6c7f9229746b1e7da871c2a3dd5a8dd7.

@k8s-bot
Copy link

k8s-bot commented Jun 19, 2015

GCE e2e build/test passed for commit b69e033a80d2c6462679a87e0673857426bbb667.

@k8s-bot
Copy link

k8s-bot commented Jun 19, 2015

GCE e2e build/test passed for commit 79760a54a00839cb3ae2bdd96c4473b487fed9a7.

@k8s-bot
Copy link

k8s-bot commented Jun 19, 2015

GCE e2e build/test passed for commit 66edecf930f16439ada47e29b9f32f62e1330024.

@@ -1001,11 +1004,15 @@ type ReplicationControllerSpec struct {
type ReplicationControllerStatus struct {
// Replicas is the number of actual replicas.
Replicas int `json:"replicas" description:"most recently oberved number of replicas"`

// ObservedGeneration is the most recent generation observed by the controller.
ObservedGeneration int64 `json:"generation,omitempty" description:"reflects the generation of the most recently observed replication controller"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json: observedGeneration

@bgrant0607
Copy link
Member

Looks pretty good. Just a couple minor comments.

@bgrant0607
Copy link
Member

Please regenerate the swagger so that shippable can run.
hack/update-swagger-spec.sh

@bprashanth
Copy link
Contributor Author

I did run update-swagger a few times (and the new commits ended up triggering k8s bot as well), I'll need to dig into why that doesn't seem to have worked

@bprashanth
Copy link
Contributor Author

PTAL, I'll figure out the swagger bug later, somehow verify followed by updated seems to have cleared some state and it worked.

@k8s-bot
Copy link

k8s-bot commented Jun 19, 2015

GCE e2e build/test passed for commit 1b31fc8b6c14151a231aab3872a95ffc8d2fd405.

@bprashanth
Copy link
Contributor Author

Shippable failure is a flake because n/w latencies are really high for some reason (took ~20s for a watch in my last run). Bumped up an integration test timeout that doesn't really need to be that short anyway with my last commit.

@k8s-bot
Copy link

k8s-bot commented Jun 19, 2015

GCE e2e build/test passed for commit 9ed9bd1.

@bgrant0607
Copy link
Member

LGTM

@bgrant0607 bgrant0607 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2015
@bgrant0607 bgrant0607 added this to the v1.0 milestone Jun 19, 2015
satnam6502 added a commit that referenced this pull request Jun 19, 2015
Fix kubectl stop rc with sequence numbers
@satnam6502 satnam6502 merged commit b964f3c into kubernetes:master Jun 19, 2015
@bprashanth bprashanth deleted the sno branch October 26, 2015 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants