Documentation
¶
Overview ¶
Package fluxsim is a fake source cluster running kustomize-controller and source-controller, for tests of code that drives Flux. It applies the source facts docs/design/apply-trigger.md lists (kustomize-controller v1.9.6), and nothing more.
Index ¶
- func GitRepositoryGVR() schema.GroupVersionResource
- func KustomizationGVR() schema.GroupVersionResource
- func OwnSuspend(t testing.TB, obj *unstructured.Unstructured, suspend bool, manager string, ...) *unstructured.Unstructured
- func SetReady(obj *unstructured.Unstructured, status metav1.ConditionStatus, ...)
- func TickingClock(start time.Time) func() time.Time
- type Sim
- func (s *Sim) Applied() []string
- func (s *Sim) BlockDependencies(blocked bool)
- func (s *Sim) Edit(key types.NamespacedName, change func(*unstructured.Unstructured))
- func (s *Sim) FailApplies(message string)
- func (s *Sim) Fetches(source types.NamespacedName, revision string)
- func (s *Sim) HoldNextApply() <-chan struct{}
- func (s *Sim) Kustomization(key types.NamespacedName) *unstructured.Unstructured
- func (s *Sim) LagSourceCache(source types.NamespacedName, revision string)
- func (s *Sim) PauseKustomizations() func()
- func (s *Sim) Reconciles(key types.NamespacedName) int
- func (s *Sim) Release()
- func (s *Sim) Requeue(key types.NamespacedName)
- func (s *Sim) WriteStatus(_ context.Context, gvr schema.GroupVersionResource, key types.NamespacedName, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GitRepositoryGVR ¶
func GitRepositoryGVR() schema.GroupVersionResource
GitRepositoryGVR is Flux's GitRepository.
func KustomizationGVR ¶
func KustomizationGVR() schema.GroupVersionResource
KustomizationGVR is Flux's Kustomization.
func OwnSuspend ¶
func OwnSuspend(t testing.TB, obj *unstructured.Unstructured, suspend bool, manager string, operation metav1.ManagedFieldsOperationType) *unstructured.Unstructured
OwnSuspend sets a Kustomization's spec.suspend, owned by manager with operation, as a manifest applied by something else, or a `flux suspend`, leaves it.
func SetReady ¶
func SetReady(obj *unstructured.Unstructured, status metav1.ConditionStatus, reason, message string)
SetReady sets a Kustomization's Ready condition.
Types ¶
type Sim ¶
type Sim struct {
// Client is the fake source cluster's client, which the code under test writes through.
Client *dynamicfake.FakeDynamicClient
// contains filtered or unexported fields
}
Sim is a source cluster running kustomize-controller and source-controller, as far as the source facts in docs/design/apply-trigger.md go (kustomize-controller v1.9.6, internal/controller/kustomization_controller.go). It is what the Flux client's lifecycle is tested against, so each fact it relies on is one this fake applies:
- A reconcile reads the object once, when it starts. finalizeStatus is deferred and copies the requestedAt it read to status.lastHandledReconcileAt on every return (:143, :1335-1340).
- A suspended object returns right after that read, before the source is resolved (:189-192): it fetches, builds and applies nothing, and its Ready is left as it was.
- spec.suspend is read only when a reconcile starts, so a suspend does not stop one running.
- lastAttemptedRevision is written before the build (:390); lastAppliedRevision and Ready=True once the apply finished. A failed apply is Ready=False; a dependency not ready is Ready=False, DependencyNotReady (:264-268).
- observedGeneration is set from the generation read whenever Ready is True at the end (:1345).
- A reconcile is enqueued by a new generation, a new requestedAt, or a new artifact of its source (kustomization_manager.go:139-173), and reconciles of one object never overlap.
- A reconcile that gets past the suspend check marks Ready Unknown before it fetches, so the Ready it ends with has a new lastTransitionTime (:331); one that builds upserts its digest in status.history, counting the reconciles of it (:492-563, meta.History.Upsert). A suspended return touches neither.
Two of kustomize-controller's circumstances are a test's to set: its source informer lagging behind the GitRepository (LagSourceCache), and its queue holding a reconcile back while the object changes under it (PauseKustomizations).
Writes go through the fake dynamic client the client under test uses. spec.suspend and the requestedAt annotation keep managedFields, by manager and operation, as the API server does for a server-side apply (forced) and for a merge patch. A Kustomization's resourceVersion moves on every write that changes it, and a server-side apply that carries a resourceVersion or a uid has them checked as preconditions, as the API server checks them.
func New ¶
func New(t testing.TB, client *dynamicfake.FakeDynamicClient) *Sim
New wraps a fake source cluster's client and starts its controllers, which stop with the test.
func (*Sim) BlockDependencies ¶
BlockDependencies makes every apply wait on a dependency that is not ready.
func (*Sim) Edit ¶
func (s *Sim) Edit(key types.NamespacedName, change func(*unstructured.Unstructured))
Edit changes a Kustomization as another writer's update does, on the object as it is now. It writes through the tracker rather than the client, so a test's reactor, which runs while the client is locked, can call it.
func (*Sim) FailApplies ¶
FailApplies makes every apply fail with message, or succeed again when it is empty.
func (*Sim) Fetches ¶
func (s *Sim) Fetches(source types.NamespacedName, revision string)
Fetches sets what the next fetch of a GitRepository finds.
func (*Sim) HoldNextApply ¶
func (s *Sim) HoldNextApply() <-chan struct{}
HoldNextApply stops the next apply after it wrote lastAttemptedRevision, and returns a channel that is closed once it is held there. Release lets it finish.
func (*Sim) Kustomization ¶
func (s *Sim) Kustomization(key types.NamespacedName) *unstructured.Unstructured
Kustomization reads a Kustomization from the fake.
func (*Sim) LagSourceCache ¶
func (s *Sim) LagSourceCache(source types.NamespacedName, revision string)
LagSourceCache makes kustomize-controller read revision as the artifact of the GitRepository source, as its informer does before it catches up with a fetch, until it is called with "". Whether a reconcile is due is still decided by the artifact the GitRepository holds.
func (*Sim) PauseKustomizations ¶
func (s *Sim) PauseKustomizations() func()
PauseKustomizations holds every Kustomization reconcile back until the returned func is called, as a busy queue does: a reconcile due meanwhile starts after it, from the object as it is then.
func (*Sim) Reconciles ¶
func (s *Sim) Reconciles(key types.NamespacedName) int
Reconciles is how many reconciles of the Kustomization started.
func (*Sim) Requeue ¶
func (s *Sim) Requeue(key types.NamespacedName)
Requeue makes a reconcile of the Kustomization due with nothing changed, as a requeue after retryInterval or interval does.
func (*Sim) WriteStatus ¶
func (s *Sim) WriteStatus(_ context.Context, gvr schema.GroupVersionResource, key types.NamespacedName, change func(*unstructured.Unstructured))
WriteStatus changes an object's status as the controller's patcher does: on the object as it is now, leaving its spec and metadata alone. A write that changes the object moves its resourceVersion.