This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
Sort resources using dependency order before applying #1117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Kubernetes resource kinds have a partial order relation of (loosely) "may refer to": a Deployment may mount a ConfigMap as a volume; most resources are scoped to a namespace; a RoleBinding refers to a Role or ClusterRole; and so on.
Usually, you want the referenced resources to be created or changed before the referring resources. In general, Kubernetes is designed so that it will sort itself out eventually, but things go more smoothly if things are present before they are needed.
Here I've boiled the ordering down to a small number of ranks, with each rank containing kinds that refer only to kinds in the ranks before. When applying resources, they are sorted by rank, so that resources that depend on other resources will get updated or created after those others.
We used to separate resources into those that don't mention a namespace and those that do, before applying each set in turn. This was for two reasons:
--namespace
argument to kubectl, because otherwise un-namespaced resources would be created in the same namespace as flux; but, if you supply that argument, applying anything that does have a namespace can be an error.If we give kubectl a context by putting one in
/root/.kube/config
though, we don't have to use the--namespace
argument, and can apply everything together.