Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

/status subresource and observed generation support #331

Merged
merged 2 commits into from
Sep 28, 2018
Merged

Conversation

ash2k
Copy link
Contributor

@ash2k ash2k commented Sep 26, 2018

Fixes #323.
Fixes #102.

Need to merge #330 first.

@ash2k ash2k self-assigned this Sep 26, 2018
@ash2k ash2k requested a review from a team September 26, 2018 13:13
@ash2k ash2k changed the title /status subresource; observed generation support /status subresource and observed generation support Sep 26, 2018
return func(event watch.Event) (bool, error) {
metaObj := event.Object.(meta_v1.Object)
if metaObj.GetNamespace() != namespace || metaObj.GetName() != name {
return false, nil
}
b := event.Object.(*smith_v1.Bundle)
for _, rv := range resourceVersions {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Die, hack, die.

if err == nil {
if len(b.Finalizers) > 0 {
t.Logf("Removing finalizers from Bundle %q", bundle.Name)
b.Finalizers = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's annoying to remove finalizers manually to make the namespace go away if the test exits abruptly.

// (if the Bundle spec wasn't updated during the last update, the status should be kept with no changes)
// The better solution could be storing "ObservedGeneration" in the status to reflect
// whether the status is up-to-date with the spec or stale
st.bundle.Status.Conditions = []cond_v1.Condition{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are sending an update here to the resource's body (not /status) which, when subresource /status is enabled, ignores .status changes. So there is no point making any changes to .status - they are ignored. See https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource

{Type: smith_v1.BundleReady, Status: cond_v1.ConditionFalse},
{Type: smith_v1.BundleError, Status: cond_v1.ConditionFalse},
}
_, err := st.updateObjectsToDeleteStatus()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also pointless - .status changes are ignored now in this codepath.

@@ -87,8 +87,6 @@ func TestFinalizerAdded(t *testing.T) {
updateBundle := bundleUpdate.GetObject().(*smith_v1.Bundle)
// Make sure that the "deleteResources" finalizer was added
assert.True(t, resources.HasFinalizer(updateBundle, bundlec.FinalizerDeleteResources))

tc.assertObjectsToBeDeleted(t, m1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When finalizer is added, we don't touch .status anymore (see above). So no need to test it.

Copy link
Contributor

@nilebox nilebox left a comment

Choose a reason for hiding this comment

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

Please double check if you actually need to update the whole bundle to remove finalizer.

}
}
return true, nil
return b.Status.ObservedGeneration >= b.Generation, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI: CRDs don't get Generation incremented when annotations/labels updated, see kubernetes/kubernetes#67428
I haven't checked if ResourceVersion get incremented in that case, but just something to keep in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just FYI: CRDs don't get Generation incremented when annotations/labels updated, see kubernetes/kubernetes#67428

Yes, and that is what I would expect. See #325 and the corresponding PR. Just found these docs https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/customresources-subresources.md#status-behavior and kubernetes/kubernetes#45539

I haven't checked if ResourceVersion get incremented in that case, but just something to keep in mind.

Yes, it does. It changes when a mutating request touches /status or / (normal resource path). I tested =)

{Type: smith_v1.BundleError, Status: cond_v1.ConditionFalse},
}
_, err := st.updateObjectsToDeleteStatus()
err := st.updateBundle()
Copy link
Contributor

@nilebox nilebox Sep 26, 2018

Choose a reason for hiding this comment

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

I'm pretty sure that status subresource allows removing finalizers.
I have recently found this code in Service Catalog https://github.com/kubernetes-incubator/service-catalog/blob/master/pkg/controller/controller_instance.go#L2420 and double checked that it actually works.
So unless CRD implementation is different, you shouldn't need to invoke this update separately from status update.
Also, there should only be one update request per processing, as we all learned the hard way.

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'm pretty sure that status subresource allows removing finalizers.

But it should not. See the design doc and the issues I linked above.

So unless CRD implementation is different, you shouldn't need to invoke this update separately from status update.

When adding finalizers we don't perform bundle processing and hence do not update its status.

Also, there should only be one update request per processing, as we all learned the hard way.

Yes. That is how it was and this PR does not change this behaviour.

@ash2k ash2k changed the base branch from schema-for-status to master September 27, 2018 07:53
@ash2k
Copy link
Contributor Author

ash2k commented Sep 27, 2018

The second commit just splits a method into two to simplify it and make the linter happy, no functional changes.

@ash2k ash2k merged commit c647fc4 into master Sep 28, 2018
@ash2k ash2k deleted the split-status branch September 28, 2018 04:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants