Commit Graph

481 Commits

Author SHA1 Message Date
Nic Cope 211e232f1a Remove unused reference.Resolver interface
Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-16 18:06:40 -07:00
Nic Cope e8ebeb9b32 Add convenience methods for references that resolve to a pointer string
Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-16 18:05:03 -07:00
Nic Cope 55a4bb6323
Merge pull request #149 from muvaf/applyfix
apply should work for objects with only generateName
2020-04-15 22:01:04 -07:00
Nic Cope c8339c6c71 Return an error when reference resolution results in empty value
This will be the case when the referenced managed resource exists, but the field
from which we want to extract a value is empty. Consider for example a status
field that does not have a useful value until the resource has been created.
Blocking on the referenced resource field being non-zero is roughly equivalent
to blocking on the referenced resource being in condition Ready.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-15 19:00:24 -07:00
Nic Cope 1ac8ded427 Docstring fixes.
Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-15 14:48:38 -07:00
Nic Cope b9255d7fcc Simplify resource references, and introduce reference selection
This commit introduces managed.APISimpleReferenceResolver, which satisfies the
managed.ReferenceResolver interface. This variant requires much less plumbing
and reflection because it expects that managed resources expose a single
ResolveReferences method that will optionally select and then resolve any
resource references. It also adds a new pkg/reference which contains a library
that managed resource authors _may_ choose to use to avoid reimplementing common
reference selection and resolution logic.

The existing managed.APIReferenceResolver implementation remains the default,
but is marked deprecated and will be removed once all managed resources use the
APISimpleReferenceResolver. Notably, the "reference resolution" condition is no
longer set by managed.Reconciler - managed resources will report reference
resolution issues via the Synced condition (i.e. as a ReconcileError).

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-15 13:59:53 -07:00
Nic Cope bc4cf86077
Merge pull request #147 from muvaf/finalizeme
Make APIFinalizer interface compatible with all Kubernetes resources
2020-04-14 11:07:23 -07:00
Muvaffak Onus 3301bfef95
apply should work for objects with only generateName
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2020-04-14 20:35:44 +03:00
Muvaffak Onus fbeeb71921
Make APIFinalizer interface compatible with all Kubernetes resources
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2020-04-13 17:02:04 +03:00
hasheddan 993994446a
Pass workload kind to trait reconciler
Because we no longer include the UID of
the workload in a trait's workloadRef it
is necessary to pass the workload kind to
the trait reconciler so that we can get the
referenced workload on each reconcile and
use its UID for ensuring the corresponding
translation is controllable by it.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-04-10 07:34:52 -05:00
hasheddan 294db229df
Update OAM trait and workload reconcilers to use MustBeControllableBy
In order to enable backup and restore of OAM traits
and workloads, resources they own should be able to
be regained control of if they are not already
controlled by a different owner.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-04-09 15:27:52 -05:00
Nic Cope f9d4e859f4
Merge pull request #126 from hasheddan/intignore
Ignore previously cleaned up CRDs in integration tests
2020-04-05 19:09:56 -07:00
Nic Cope cf8d3a6a26 Make connection secret propagation UID-agnostic
This allows propagation to function even when the propagating and/or propagated
secrets have been deleted and recreated, and thus allocated new UIDs.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-05 15:16:25 -07:00
hasheddan 8d3f52dd66
Format tmp dir hash as hex
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-04-04 10:00:47 -05:00
hasheddan 18caa604b9
Ignore previously cleaned up CRDs in integration tests
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-04-04 10:00:46 -05:00
Nic Cope 067847f938 Rename ExternalNameAnnotationKey to AnnotationKeyExternalName
We typically include the type hint at the start of enum-ish types, e.g.
AnnotationKeyFoo and ExternalResourceTagKeyBar. This was the one exception
to that pattern. Presumably this should not be noticed by most consumers of
this API, which use meta.GetExternalName to get this field.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-03 20:28:30 -07:00
Nic Cope b8b606426d Introduce an updating Applicator
This is roughly the same functionality as controllerutil.CreateOrUpdate, albeit
a little simpler. This variant is useful to us because it satisfies our
Applicator interface.

The key difference between the patching and updating applicators is that the
patching applicator will leave any existing, unset fields untouched (to the
extent that a JSON merge patch allows), while the updating applicator will
always update any existing object to exactly match the desired object.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-02 14:28:38 -07:00
Nic Cope ee9b68e00c Introduce a distinct secret type for connection secrets
This allows resource claims and managed resources to adopt existing orphaned
connection secrets without needing to be concerned with the fact that they
might be adopting an existing secret that is unrelated to Crossplane.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-02 14:28:38 -07:00
Nic Cope ff8a47bab6 Add a MustBeControllableBy ApplyOption
This option replaces ControllersMustMatch. It works slightly differently in that
it takes the expected controller UID explicitly instead of inferring it from the
desired object, and considers current objects with no controller reference to be
controllable. Presumable objects with no controller reference will be adopted.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-01 22:20:18 -07:00
Nic Cope 51d293df2f Don't require callers to pass a client.Client to Applicator implementations
The Apply method of the resource.Applicator interface took a client.Client
largely because it was extracted from the pre-existing resource.Apply function
to allow pluggable Apply implementations. Now that we have types that satisfy
resource.Applicator it makes more sense for those types to include a client,
rather than being passed one for every Apply call.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-01 18:23:17 -07:00
hasheddan bb562fce25
Clean up OAM reconcilers
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-20 09:48:15 -05:00
hasheddan 57df15c56c
Make WorkloadReferencer use non-pointer types
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-19 16:54:20 -05:00
hasheddan 7d845c0a81
Add TypedObjectReference and use in OAM reconcilers
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-18 21:49:28 -05:00
hasheddan 9b2363aad2 Add OAM trait reconciler
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-18 17:25:54 -05:00
hasheddan 273f291f76 Add OAM workload reconciler
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-18 17:25:06 -05:00
hasheddan 8a48d21abb Pass apply checks as functions to Applicators
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-16 16:53:41 -05:00
Nic Cope c77cb4d6a2
Merge pull request #102 from muvaf/status-update-always
managed reconciler: status update has its own context
2020-03-16 10:17:20 -07:00
Muvaffak Onus 1bccacf563
managed reconciler: external client has its own context
so that managed reconciler is able to call k8s functions
even though the deadline is exceeded during external client
operations.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2020-03-12 11:10:03 +03:00
Muvaffak Onus 34f8959f86
Implement GetExternalTags to return Crossplane tags for managed resource controllers to tag their external resources
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2020-03-04 11:18:24 +03:00
hasheddan 73c6076ff3 Add Applicator interface
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-03 19:20:02 -06:00
Nic Cope 625ec3bf23 Fix controller mismatch detection in resource.Apply
Signed-off-by: Nic Cope <negz@rk0n.org>
2020-03-02 22:37:14 -08:00
Nic Cope b33c53e6d5 Round-trip paved values through JSON serialisation before setting them
Paved objects expect their internal unstructured content to be of the types
produced by json.Unmarshal. This allows us to enforce that for any call to
p.SetValue("some.path", T) where T is any JSON serialisable type.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-03-02 22:03:54 -08:00
Nic Cope 1eec52890b Stash desired, not existing object when applying changes
Getting, creating, or patching an object using the controller-runtime client
updates said object with the latest state from the API server. This commit
alters our resource.Apply logic to patch 'into' the supplied object, not a
deepcopy of that object. This ensures the object passed to apply is updated
with the latest view from the API server, whether it is created or patched.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-03-02 22:00:40 -08:00
Nic Cope 6ef3f96332 Add an Apply object function
This function either creates a new object or patches an existing one. I think
it belongs in crossplane-runtime because we have at least two implementations in
the wild, and I need another one for a new controller.

https://github.com/crossplane/templating-controller/blob/a035e2/pkg/controllers/templating_reconciler.go#L168
https://github.com/crossplane/crossplane/blob/c1933feab/pkg/controller/workload/kubernetes/resource/resource.go#L260

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-02-27 16:42:02 -08:00
Nic Cope ca61a42964 Add getters and setters for unstructured content
This helps convert a *fieldpath.Paved to and from an *unstructured.Unstructured.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-02-26 21:05:37 -08:00
Nic Cope f67177024d Add a package for getting and setting unstructured fields by path
https://github.com/kubernetes-sigs/kustomize/blob/d190e1/api/k8sdeps/kunstruct/helper.go
https://github.com/kubernetes/apimachinery/blob/2373d0/pkg/apis/meta/v1/unstructured/helpers.go

This package is similar to the above two, with some key differences:

* Our fieldpath lexer is a little stricter; it won't allow dangling open braces,
  unexpected periods, or empty brackets. It also supplies the position of any
  syntax error if lexing fails.
* We support setting and getting fields within a pkg/json unmarshalled object by
  fieldpath. Other packages support only getting fields, or only setting fields
  in paths that do not contain any array indexes.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-02-25 12:56:34 -08:00
hasheddan 16aa98bd07 Update go mod and refs with crossplane org name
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-02-18 18:17:32 -06:00
Nic Cope d31744b76f Remove the util package
All functions defined by this package now either live alongside their (few)
callers, or have moved into distinct crossplane-runtime packages.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-31 16:41:25 -08:00
Nic Cope 8df758d202 Move password generation into its own package
https://github.com/sethvargo/go-password

I considered using the above library, but its API is a little overkill for our
needs. I chose not to keep the previous GeneratePassword implementation because
I felt the length argument was a unintuitive. The argument specified the length
of the randomly generated bytes, which were then base64 encoded resulting in a
~33% overhead. So for example GeneratePassword(20) generated a 27 character
password.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-31 16:41:25 -08:00
Nic Cope dfb4939937 Remove deprecated util functions
https://github.com/crossplaneio/crossplane-runtime/issues/1

Each of these functions were called by only a single package, so I've raised
PRs to move them to the packages that call them. All relevant PRs are cross
linked from the above issue

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-31 02:11:47 -08:00
Nic Cope 2b04b4da2e Add debug logging and events to all reconcilers
This commit introduces new logging and eventing libraries, and adds debug logs
and events to all reconcilers.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-26 19:24:49 -08:00
Nic Cope 5e66b02110 Remove some referencer types back to pkg/resource
These types are used by infrastructure stack API types, which should not need to
import reconciler code.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-15 15:15:58 -08:00
Nic Cope 96f3434172 Fix conflicting package names
...and the stuttering name linter warnings created by said fix.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-15 12:52:35 -08:00
Nic Cope 2e53eb2645 Add package doc for packages that currently lack it.
Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-15 12:27:16 -08:00
hasheddan 6c51d15948 log: remove deprecated package
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-01-15 08:05:50 -06:00
Nic Cope 0c47e947d0 Make target reconciler's secret propagator configurable
This allows us to plug in a no-op secret propagator for our unit tests, allowing
those tests to focus on testing the reconciler rather than 'testing through' to
the default secret propagator implementation (which has its own tests).

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-14 19:52:53 -08:00
Nic Cope 034c58db2c Break reconcilers out into distinct packages
I'm hoping this will help us pass in loggers and eventers using variadic options
without awkward names like WithClaimBindingReconcilerLogger. This is a huge diff
but there's no functional changes - only moving things around and renaming them.

I was hoping we'd be able to do with without a breaking API change by using type
aliases, but doing so would create cyclic imports, because the new reconciler
packages depend on the resource package, which is where we'd need to create the
type alias to the reconciler packages.

I've broken up api.go (which contained most of the 'Kubernetes API' - i.e.
default - implementations of most of the pluggable interfaces used by our
reconcilers) into several files. My heuristic here was:

* If the implementation is used by a single reconciler, put it in that
  reconciler's package.
* If the implementation is used by more than one reconciler, put it in the
  resource package.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-01-14 19:52:53 -08:00
Daniel Mangum 5ece4af54b Implement Target interface and reconciler (#103)
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-01-14 12:36:41 -08:00
Daniel Mangum d5c9dedd2a secret reconciler: allow for propagation to multiple secrets (#92)
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-01-06 16:51:27 -05:00
Muvaffak Onus f2f4e36608
api: Provider interface corrected
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-12-20 23:14:34 +03:00
Muvaffak Onus 5a3ce4f6c8
Removed Mock word from mocks in package fake.
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-12-12 15:02:06 +03:00
Muvaffak Onus 3cf4bd1275
Move MockManager into fake package
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-12-11 16:06:14 +03:00
Muvaffak Onus 81a7488824
Make mock of our interfaces available to be used out of this repository for testing purposes
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-12-11 16:03:16 +03:00
hasheddan c574b3dddd integration tests: use fnv over md5
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-12-10 18:43:08 -06:00
hasheddan 5304d0c8c6 integration tests: check hashing error
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-12-10 17:25:25 -06:00
hasheddan 9254132398 integration tests: one args for all path types
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-12-10 17:24:01 -06:00
hasheddan c9471f6288 integration tests: support downloading remote CRDs
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-12-10 17:24:01 -06:00
Nic Cope e02208ed02
Merge pull request #93 from muvaf/prov-interface
Add Provider interface
2019-12-10 12:23:31 -08:00
Muvaffak Onus 912af9daab
Add Provider interface for consumers to be able to identify provider type resources
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-12-06 21:54:26 +03:00
Muvaffak Onus 1fe048748d
Bump controller-runtime to v0.4.0
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-12-06 14:11:12 +03:00
Nic Cope bd43e78aa7
Merge pull request #89 from hasheddan/integrationpkg
Add integration testing package
2019-11-25 23:31:09 -08:00
hasheddan 65b35a9566 test: clean up integration testing framework
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-11-25 23:10:51 -06:00
hasheddan 269bace98f managed reconciler: use lowercase error messages
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-11-25 15:55:09 -06:00
hasheddan 30ab5322a8 managed reconciler: add method ref to external client errors
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-11-25 10:45:45 -06:00
hasheddan 0ee25af7eb test: fix linter warnings
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-11-22 11:32:15 -06:00
hasheddan 5ba6fc5ef0 test: support variadic crd directory paths
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-11-21 16:14:38 -06:00
hasheddan 3e648dda92 test: add integration testing framework
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-11-21 16:13:03 -06:00
Nic Cope 37066650a1
Merge pull request #87 from negz/reclaim
Mirror PersistentVolume ReclaimPolicy semantics
2019-11-19 14:48:27 -08:00
Nic Cope ca4b6b46c9 Mirror PersistentVolume ReclaimPolicy semantics
This commit changes the meaning of the resource claim resource policy to match
https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reclaiming as
closely as possible, minus the deprecated 'Recycle' policy. Previously the
reclaim policy dictated only what happened to the external resource when its
managed resource was deleted.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-19 14:43:25 -08:00
Nic Cope 32ce7ceb0f
Merge pull request #82 from negz/dieutildie
Remove unused util functions
2019-11-18 23:06:15 -08:00
Nic Cope 7b38692c99 Don't set controller references for dynamically provisioned resources
Resource claims are namespaced, but the managed resources they dynamically
provision are cluster scoped. A namespaced resource cannot, by design, own
a cluster scoped resource. This has been a known issue for a long time, but
we recently learned that it can result in the managed resources being
unintentionally garbage collected by Kubernetes per
https://github.com/crossplaneio/stack-gcp/issues/99.

Resource claims and managed resources already reference each other via their
resourceRef and claimRef; we had set the owner reference purely to delete
dynamically provisioned managed resources along with their claim. Dynamically
provisioned managed resources will now always stick around until explicitly
cleaned up. We intend to address this by repurposing the existing reclaimPolicy
field per https://github.com/crossplaneio/crossplane-runtime/issues/21

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-18 13:03:01 -08:00
Nic Cope ae800cb8b6 Remove unused util functions
These functions have been marked deprecated for as long as crossplane-runtime
has existed. As far as I can tell they are no longer used.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-18 10:08:44 -08:00
Nic Cope 29347c9f0a Don't resolve references when being deleted
Per the comment, there's too high a chance we'll get stuck and not process the
delete because we reference resources that are also being deleted. I considered:

* Processing references at delete time but not blocking on accessor errors. I
  felt this introduced too much complexity for little gain compared to just not
  trying resolution at all.
* Making AttributeReferencers no-ops when the field they would set already had a
  value. I think this is an avenue we should investigate (issue forthcoming) but
  it is awkward to implement with the current AttributeReferencer interface.
* Enforcing ordered deletes, such that a referenced resource cannot be deleted
  (at least not by Crossplane) until its referencers have all been deleted. This
  is the most bulletproof, but also the most complicated solution and would
  require further design investigation to pursue.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-05 00:12:57 -08:00
Nic Cope 8d85a75dac Have claim reconciler default to using the status subresource
All resource claims use the status subresource, but at the time the claim
reconciler was introduced most managed resources did not. This is no longer
true - all managed resources use the status subresource with the exception of a
few stragglers.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-03 18:53:16 -08:00
Nic Cope 11ec9aceb4
Merge pull request #70 from negz/finality
Add managed resource finalizer immediately before creating
2019-11-03 17:53:02 -08:00
Nic Cope 8fc49848d6 Set binding phase after update when unbinding
Previously we set the binding phase to unbound, then called Update(), which
reset the binding status to the API server value before we called
Status().Update() to persist it.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-02 02:16:32 -07:00
Nic Cope 6e49f843c2 Don't update claim statuses after they've been deleted
Unless someone else added a finalizer (and didn't yet remove it) the claim will
cease to exist as soon as the finalizer is removed, so there's nothing to update.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-02 01:42:27 -07:00
Nic Cope 105d2dd705 Fix grammar in managed reconciler commentary
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-01 16:49:39 -07:00
Nic Cope 3ec572329d Add claim finalizer before binding, not creation
The claim reconciler uses the finalizer to unbind the managed resource. If we
never bound to the resource there's nothing to do. Keep in mind we currently
rely on garbage collection to ensure dynamically provisioned managed resources
are deleted when the claim is deleted.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-01 16:49:37 -07:00
Nic Cope a3a5f918ac Add managed resource finalizer immediately before creating
This commit moves where we set the finalizer for managed resources to right
before creating them, not at the beginning of the reconcile. This means we'll be
less likely to encounter issues where we can't delete a managed resource because
we could never create it in the first place, but we added a finalizer.

* By the time we get here we know our Observe call worked. If (for example) our
  cloud provider credentials were completely wrong, we'd never proceed far
  enough to add the finalizer.
* If Observe works but Create fails (for example because we had RO cloud
  provider credentials) we would already have added the finalizer, but...
* When the managed resource was deleted we'd be able to Observe that the
  external resource does not exist (because we were never able to Create it) and
  thus would not call Delete on the external resource and go straight to
  unpublishing credentials and removing the finalizer.

This commit also renames and refactors a bunch of our interfaces to use less
obtuse names. Previously sometimes a "finalize" method unbound a managed
resource, while at other times it removed the finalizer. Similarly, finalizers
were added in "initialize". We now have a 'Binder' interface with bind and
unbind methods, and two 'Finalizer' interfaces (one for Claim, and one for
Managed) that add and remove finalizers, as you would expect.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-01 15:48:09 -07:00
Nic Cope e834b8ab98 GoDoc tweaks
Clarify the purpose of a few types, and make their documentation a little more
similar to the documentation of existing similar patterns.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-01 15:48:09 -07:00
Nic Cope b01c234701 Don't attempt to update resource status after finalizer removal
This status update is only useful when:

* Some other controller also added a finalizer to this managed resource.
* The other controller has not yet processed the delete and removed its finalizer.

Given that this is a rare (or non-existent) edge case, and given that attempting
to update the status of a non-existent managed resource results in spurious
errors in the logs, I think it's safe to remove this logic.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-01 15:14:07 -07:00
Nic Cope 78e91b4b29 Don't trigger a requeue after a successful deletion
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-11-01 15:00:10 -07:00
Nic Cope a63f5b1c93 Requeue when no resource claims match labels or default annotations
Previously if no controller could schedule or default new claims they would
never try again.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 20:00:18 -07:00
Nic Cope 9b74c6d769 Make resource.CanReference a type of runtime.Object
We no longer need CanReference types to satisfy the metav1.Object interface. It
was used only to determine the namespace of the referencing object before all
such objects became cluster scoped.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 16:11:10 -07:00
Nic Cope bc04c33519 Resolve references on every reconcile
Reference resolution is now a no-op if nothing changes, so we run it on every
reconcile. We also run it after delete has been handled, so unresolved
references will only block creates and updates.

This commit means we'll make more get calls to the cache (or API) in order to
resolve our references each reconcile, and also risk potentially changing the
values of 'immutable' fields automatically if and when our references resources
change. I believe we should address this by having referencers be no-ops when
the field value they would set is already set.

I attempted to move reference resolution to right before we call create or
update (i.e. after observe and delete), but it turns out certain resources
(specifically GCP Connections) could need references to be resolved in order to
observe the external resource.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 16:11:10 -07:00
Nic Cope 5468d81383 Use real conditioned and binding statuses in mock objects
The mock binding status was identical to the real one, while the mock
conditioned status set only the most recent condition, leading to a few
slightly broken managed resource reconciler tests.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 13:27:40 -07:00
Nic Cope d5dadd4e74 Requeue after a short wait when references are not ready
the established convention is for the managed resource reconciler to requeue
after a short wait (typically 30 seconds) when it knows it is waiting for an
operation.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 13:27:30 -07:00
Nic Cope 5b01de5a4d Make reference resolution a no-op if assignments did not change anything
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 13:27:30 -07:00
Nic Cope 242629474a Remove attributereferencer tag check, make referencer finder pluggable
This commit refactors ResolveReferencers to allow the code that finds types
within a struct that satisfy AttributeReferencer to be swapped out. It also
updates the default AttributeReferencerFinder to avoid checking struct tags.

Previously errors were returned when:

1. A struct field tagged as a referencer did not satisfy AttributeReferencer
2. A struct field not tagged as a referencer satisfied AttributeReferencer

If either of these scenarios occurred, ResolveReferences would panic with the
returned error the first time it encountered an incorrectly written API type.
My feeling is that both of these conditions are testing for programmer errors
that would be better caught at build time than at runtime.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 13:27:30 -07:00
Nic Cope 4fbddd0d00 Clean up managed resource reconciler tests
No functional updates to the code here, just tidying up the tests a bit to
ensure they all mock out their various moving parts via options.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-31 12:35:28 -07:00
Nic Cope 6db5ced56a Trivial comment updates
Just wrapping a comment and updating the linter override to reflect that we've
moved beyond "slightly" over our cyclomatic complexity goal. :(

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-28 16:01:38 -07:00
Nic Cope 551efff860 Add tests for external name annotation back-propagation
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-24 21:07:40 -07:00
Nic Cope 799c22bda6 Set managed resource claim ref at binding time
We already set this reference at dynamic provisioning time, but we need it set
for (bound) statically provisioned managed resources too, so we set it
(potentially again) at binding time.

We must still set the reference at dynamic provisioning time in order to ensure
reconciles are queued for dynamically provisioned managed resources when they
become available.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-24 21:07:40 -07:00
Nic Cope 94a6b45721 Don't assume the class reference is set by dynamic provisioning time
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-24 02:30:11 -07:00
Nic Cope 6a97932337 Demonstrate panic when a resource references a claim without references
Despite past negz's optimistic comment to the contrary, we can't assume the
class reference is set by the time we get to the dynamic provisioning stage.
We are queued for managed resources that reference a claim, so we could reach
the dynamic provisioning stage without a class reference being set if a managed
resource referenced a claim that had no class reference or resource reference.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-24 02:29:46 -07:00
Nic Cope bd7fed5ad4 Requeue when a referenced managed resource does not yet exist
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-24 02:29:45 -07:00
Nic Cope 2baf308c91 Demonstrate panic when a claim references a non-existent resource
If a resource claim specifies a managed resource reference to a non-existent
managed resource we'll panic because we proceed and try to operate on our
managed resource's nil class reference.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-24 02:29:38 -07:00
Nic Cope a81fb19350 Increase claim scheduling and defaulting max jitter to 1.5 seconds
200ms seems low enough that GCP consistently beats Azure when scheduling
RedisCluster claims in my experiments.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-22 17:13:21 -07:00
Nic Cope 701387a302 Add a HasResourceClass predicate
For resource claim controllers, now that we're unconcerned with indirect
resource classes.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-22 17:13:21 -07:00