Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

✨Wait until APIExport virtual workspace URLs are ready #33

Merged
merged 8 commits into from
Dec 2, 2022
Merged

✨Wait until APIExport virtual workspace URLs are ready #33

merged 8 commits into from
Dec 2, 2022

Conversation

astefanutti
Copy link
Member

This PR follows up kcp-dev/kcp#2135 so that the manager is started, only after its APIExport virtual workspace URLs are ready.

@astefanutti
Copy link
Member Author

/retest

@astefanutti astefanutti changed the title Wait until APIExport virtual workspace URLs are ready ✨Wait until APIExport virtual workspace URLs are ready Nov 24, 2022
Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

We need to do a GET or LIST first to see the current state (and short-circuit if the live read shows a URL), and use that resource version to start the watch. Also, likely best to have watch resumption on errors and re-list on compaction - which makes me wonder if we should instead start an informer.

main.go Outdated
}

if !slices.Contains(apiExport.Spec.LatestResourceSchemas, "today.widgets.data.my.domain") {
// This is not this controller APIExport
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this check is likely superfluous and if it were to be true, the controller can do nothing except for panic and process exit, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

This may be useful for the case where the APIExport name is not provided, as a way to pick the expected one. That's true the controller won't be able to to anything if the APIExport specified by name does not pass that check. So maybe add that check only when the name is not provided?

Copy link
Contributor

Choose a reason for hiding this comment

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

If no name is specified, won't the watch with the metadata.name field selector return nothing?

Copy link
Member Author

Choose a reason for hiding this comment

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

The metadata.name field selector is only appended when the name is provided. We could skip the check as well in that case or fail-fast.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the apiExportName == "" condition to the check.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should just make it required - why not?

Copy link
Member Author

Choose a reason for hiding this comment

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

I took it as an invariant that was already there, but making it required, possibly with a sensible default, would make sense and simplify things.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the api-export-name option to default to the controller APIExport name, so it avoids watching for multiple resources.

@astefanutti
Copy link
Member Author

We need to do a GET or LIST first to see the current state (and short-circuit if the live read shows a URL), and use that resource version to start the watch. Also, likely best to have watch resumption on errors and re-list on compaction - which makes me wonder if we should instead start an informer.

Ah, I have assumed this is what the controller runtime cached client actually does by default for typed objects. Let me check.

@astefanutti
Copy link
Member Author

astefanutti commented Nov 29, 2022

We need to do a GET or LIST first to see the current state (and short-circuit if the live read shows a URL), and use that resource version to start the watch. Also, likely best to have watch resumption on errors and re-list on compaction - which makes me wonder if we should instead start an informer.

Ah, I have assumed this is what the controller runtime cached client actually does by default for typed objects. Let me check.

OK, I realise my assumption was wrong, for the obvious reason the split / caching client that relies on informers is that of the manager, which we aim to create here 🙃!

So, as it stands, that is with unset resourceVersion, the semantic for watch requests is "Get State and Start at Most Recent", which is starting at the most recent resource version, beginning with synthetic "Added" events of all resources instances that exist at that starting resource version. While it functionally works, it may be less efficient / scalable, than explicitly setting resourceVersion, as it requires a quorum read to be served. Yet that may be acceptable in that use case. More details can be found at https://kubernetes.io/docs/reference/using-api/api-concepts/#semantics-for-watch.

@stevekuznetsov
Copy link
Contributor

I see - in any case, no reason that a closed watch stream while waiting should cause process exit, right?

@astefanutti
Copy link
Member Author

I see - in any case, no reason that a closed watch stream while waiting should cause process exit, right?

I've added a retry logic in case the channel has been closed, so it resumes watching for APIExports if the previous watch stream timed out on idle, or just fails if the connection to the server cannot be re-established.

@openshift-ci
Copy link

openshift-ci bot commented Dec 2, 2022

@astefanutti: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e 1899c14 link true /test e2e

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2022
@openshift-ci
Copy link

openshift-ci bot commented Dec 2, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: astefanutti, stevekuznetsov

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2022
@stevekuznetsov stevekuznetsov merged commit 1db5ec2 into kcp-dev:main Dec 2, 2022
@astefanutti astefanutti deleted the pr-01 branch December 2, 2022 16:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants