Commit Graph

239 Commits

Author SHA1 Message Date
Nic Cope ca1fe097be Expand and refactor unstructured types
This switches names around from unstructured.Composite (for example) to
composite.Unstructured, mostly to allow several unstructured types to use
identically named options like WithGroupVersionKind. It also adds a few
getters and setters required for resource publications, and introduces the
resource.Requirement type that represents an application's requirement for a
published composite resource.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-23 12:48:22 -07:00
Nic Cope 357942c02d Add a "controller engine" that manages the lifecycles of controllers
A controller engine is somewhat like a controller "sub-manager", in that it's
effectively a group of controllers. Unlike a typical controller manager, the
lifecycle of the controllers an engine manages are not coupled to the lifecycle
of the engine itself. An engine may be used by a parent controller to start and
stop child controllers in accordance with configuration provided by the custom
resource that the parent controller watches.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-23 01:51:27 -07:00
Nic Cope be37c50cc2
Merge pull request #157 from muvaf/unclient
Client for unstructured Crossplane types
2020-04-21 14:10:18 -07:00
Nic Cope 903cf3eff8
Merge pull request #155 from negz/noam
Remove OAM code, which has moved to crossplane/oam-runtime
2020-04-21 13:10:34 -07:00
Muvaffak Onus 9357d0ab18
Controller-runtime client wrapper for objects that are wrappers of unstructured.Unstructured
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2020-04-21 17:42:04 +03:00
Nic Cope 8ada1fa72b Compose the Composite interface of smaller interfaces
This also removes Bindable from the Composite interface, which I believe we will
not need.

Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-20 22:00:04 -07:00
Nic Cope 44099db82c Remove OAM code, which has moved to crossplane/oam-runtime
Signed-off-by: Nic Cope <negz@rk0n.org>
2020-04-20 20:55:51 -07:00
Muvaffak Onus 4a7ece2ff5
Add composition interfaces and unstructured composition structs.
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2020-04-21 03:11:24 +03: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 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
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
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
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 8a48d21abb Pass apply checks as functions to Applicators
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-03-16 16:53:41 -05: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 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
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 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 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
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
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
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
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 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 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
Nic Cope d7b4db0562 Add claim scheduling and defaulting controllers
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-22 17:13:21 -07:00
Nic Cope a2e24876e0 Use custom types for secret references
This allows us to require that name (and namespace where appropriate) are set at
the CRD level. In the case of cluster scoped resources that reference secrets
this is less surprising than defaulting to the `default` namespace when the
namespace is omitted.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-22 17:13:21 -07:00
Nic Cope 9f5188e0cb Assume resources, classes, and providers are cluster scoped
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-22 17:13:21 -07:00
Nic Cope a310ee6a4a Remove support for portable resource classes
This commit renames "non portable resource class" back to "resource class", and
requires that resource claims reference a (non portable) resource class in any
namespace.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-22 17:12:36 -07:00
soorena776 f063ec82d3 - Removing class level reference resolution if we can get away with it
- Removing the panic recovery logic
- Removing the superfluous IsConditionReady method
- Adding Nic's unit-tests for GetCondition and IsConditionTrue
- Minor other fixes

Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 17:05:15 -07:00
soorena776 8df7f7cab7 Change ReferenceResolver signature to accept CanReference type instead of Managed
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 f1f5375f5f move ReferenceResolver to execute before Observer
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 5ecced4f9e Update the Manage Resource after resolving references
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 2a086a07f6 Rename `ValidateReady` to `GetStatus` in `AttributeReferencer` interface, to show more granular information about the status of the referencers
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 b09e1340b6 Adding RefereceResolver tests to managed_reconciler_test.go
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 dad59a3c94 Adding Managed Referece Resolver unit tests
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 5ddae6010a Adding Managed ReferenceResolver to the Managed Reconciler
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 ee01116db1 Adding ManagedResolver
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
soorena776 1c6cccad93 Adding GetCondition to the Managed API
Signed-off-by: soorena776 <javad@upbound.io>
2019-10-21 16:39:26 -07:00
muvaffak onus d72012f1c2 Use managed resource name as external name (#45)
* - Introduces Initializer hook to managed reconciler.
- ManagedNameAsExternalName is introduced and used
  by default by all managed reconcilers.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>

* GetExternalName and SetExternalName functions are implemented

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>

* - Unit tests for ManagedNameAsExternalName struct
- Move ExternalNameAnnotationKey into meta package.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>

* Remove Establisher mechanism and port existing
establisher to Initializer.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>

* Fix claim's external name annotation propagation to
the managed resource.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-10-15 10:23:05 -07:00
Nic Cope 15eb580eec
Merge pull request #42 from negz/spreadingsecrets
Constantly propagate connection secrets
2019-10-09 14:09:27 -07:00
Muvaffak Onus 41dbfa349a Use new naming scheme for managed resources.
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-10-09 21:49:54 +03:00
Nic Cope 88193ba371 Add AllOf watch predicate
Same idea as the existing AnyOf predicate, but it requires all predicates pass.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-08 00:45:05 -07:00
Nic Cope 894481e637 Propagate connection secrets
This commit allows constant propagation of connection secrets from managed
resources to their bound resource claims. It does this by updating the existing
APIManagedConnectionPropagator to add 'propagation annotations', which can be
used by a new 'secret propagating reconciler' to watch both secrets for constant
propagation. The predicates and enqueue handler required to implement this are
included.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-10-08 00:25:11 -07:00
hasheddan d80bbd931a predicates: remove deprecated hasdirectclassreferencekind
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-27 12:14:10 -05:00
Nic Cope d8050430d1
Merge pull request #31 from negz/somanypredicates
Add an IsManagedKind watch predicate.
2019-09-18 17:29:09 -07:00
Nic Cope f1075e19e4 Add an IsManagedKind watch predicate.
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-18 15:13:38 -07:00
Nic Cope 54cc532c3a Add package doc for crossplane-runtime
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-18 14:40:41 -07:00
Nic Cope 0431952909 Rename all predicates to start with 'Has'
...because I am pedantic.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-15 01:36:28 -07:00
Nic Cope 8a3e590467 Refactor predicates to support static provisioning
We currently support dynamic provisioning in the resource claim reconciler
by using a watch predicate that allows either managed resources that directly
reference a non-portable resource class of a given kind, or resource claims that
reference a non-portable resource class of a given kind indirectly via a
portable resource class.

To support static provisioning (i.e. explicitly claiming an existing managed
resource) we must also allow resource claims that explicitly reference a managed
resource. Writing one predicate to do all of this was getting cumbersome, so I
have refactored the predicate interface a little.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-15 01:36:28 -07:00
Nic Cope 57a3b0cff1 Support managed resources that do not reference a class
Controllers built against crossplane-runtime will currently panic if they
encounter a managed resource without a class reference. Any dynamically
provisioned managed resource will have a class reference, but this breaks
the static provisioning workflow.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-13 19:32:10 -07:00
Nic Cope 1e900a411e Add a predicate that supports both resource claims and managed resources
It turns out both our watches use the same predicate and apply it to the watched
kind, not the kind that actually gets enqueued.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-13 00:01:11 -07:00
Nic Cope c170676a62 Have PCR predicate accept a slightly smaller interface.
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-12 23:35:04 -07:00
hasheddan 83aac58038 fix broken error values in tests
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-13 00:41:57 -05:00
Nic Cope 5230aa5383
Merge pull request #13 from hasheddan/portable-class
Implement portable classes
2019-09-11 21:29:03 -07:00
hasheddan 06cc35d1e3 class to nonportable class
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-11 22:59:59 -05:00
hasheddan 161ab47fb3 portable and nonportable
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-11 16:23:44 -05:00
hasheddan 5f7248620b remove CreateOrUpdate in favor of controller-runtime
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-11 09:11:55 -05:00
hasheddan 1232c87947 portable classes: default class reconcile with label
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-11 08:46:51 -05:00
hasheddan 80eeac1347 implement portable classes
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-09-10 19:06:05 -05:00
Nic Cope ab3cac0175 Don't update managed resources if we determine they're up to date
This allows us to determine whether an external resource needs updating inside
the Observe method, which must already get a fresh copy of the external resource
from the cloud provider API in order to determine whether it exists and update
the managed resource's status.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-09-05 01:10:10 -07:00
Nic Cope 06b6b7dd87 Make writeConnectionSecretToRef optional
https://github.com/crossplaneio/crossplane/issues/719

The resource claim reconciler (and API definitions) consider
writeConnectionSecretToRef to be optional, but the managed resource reconciler
fails if it is not specified. This change aligns the codebase on the reference
being optional. Managed resources that do not specify a secret reference will
provision successfully without publishing their connection details to a secret.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-08-27 19:55:29 -07:00
hasheddan 99f439d5b9 runtime migration: markdown and makefile
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-08-20 21:33:39 -05:00
hasheddan 6d90659a5f runtime migration: remove objecthasprovisioner predicate as no longer needed with strongly typed resource classes
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-08-20 09:29:11 -05:00
hasheddan 7d786e2dff runtime migration: strip apis and update dependencies
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-08-20 09:27:20 -05:00
hasheddan 5c1fdc1caa defaultclass: add all policies and remove deprecated default controllers
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-08-19 11:38:54 -05:00
hasheddan a72525edae kubebuilderv2: update core packages and tooling
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Co-authored-by: Muvaffak Onus <onus.muvaffak@gmail.com>
Co-authored-by: Jared Watts <jbw976@gmail.com>
Co-authored-by: hasheddan <georgedanielmangum@gmail.com>
2019-08-13 17:39:59 -05:00
Jared Watts 07d9fe6e26 Merge pull request #626 from hasheddan/strong-phase1
Enable Strongly Typed Resource Classes
2019-08-02 08:41:30 -07:00
hasheddan 9c60da21bc strongly typed phase one: implement default class reconciler for strongly typed resource classes
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Co-authored-by: Nic Cope <negz@rk0n.org>
2019-08-02 09:59:19 -05:00
Muvaffak Onus ca248a6d0f - Added new unit tests to Managed Reconciler.
- Added unit tests for Managed Finalizer Remover & Adder types.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-08-01 09:05:23 +03:00
Nic Cope 1a3451d074 Merge pull request #603 from muvaf/comment-impl
Implement Generic Managed Reconciler
2019-07-31 00:12:26 -07:00
Muvaffak Onus f3905eef13 - Unnecessary comments are removed.
- WithLongWait and WithShortWait are used in tests.
- Some of cosmetic issues are fixed.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-07-31 09:26:14 +03:00
Nic Cope 0681f18c20 Fix typo in license headers
This looks suspiciously like a find and replace bug.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-30 21:07:12 -07:00
Muvaffak Onus 19daef9388 New tests for non-deletion scenarios added to Managed Reconciler.
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-07-30 14:35:57 +03:00
Muvaffak Onus 542990b820 - Elasticache managed reconciler Create call made idempotent to AlreadyExists error.
- Naming fixes.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-07-29 11:12:32 +03:00
Muvaffak Onus 94040da9f9 Managed Reconciler unit tests
- Tests for the interaction between Managed<>External resource.
- make reviewable fixes.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-07-26 18:15:06 +03:00
Muvaffak Onus 447f064ca8 ManagedPublisher is extended to include UnpublishConnection function for manual garbage
collector for the resources that contributor did not hand over to kubernetes.

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-07-25 10:16:27 +03:00
Muvaffak Onus 499278c1dd - Managed resource is finalized only if the deletion of the external resource has been
confirmed by an Observe call.
- Reclaim polciy logic has been moved up to generic managed reconciler since we have
enough information on that level to decide whether external resource should be deleted
or not.
Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
2019-07-25 10:14:35 +03:00
Nic Cope 91598b2e3f Add a shared managed resource reconciler
This reconciler can be used to reconcile any resource that satisfies the Managed
interface.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-23 12:37:19 -07:00
Nic Cope d0240a6a02 Require Managed resources to support setting conditions
This will allow us to set conditions as part of a generic managed resource
reconciler that operates on the Managed interface.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-18 19:53:09 -07:00
Nic Cope 809c979954 Move the claim reconciler to an appropriately named file
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-18 09:19:35 -07:00
Nic Cope 0224bec7d0 Merge pull request #565 from hasheddan/default-resource-classes
Default resource classes
2019-07-17 19:29:09 -07:00
hasheddan 2a0fb9efd4 default resource classes: implementation
Co-Authored-By: Nic Cope <nicc@rk0n.org>
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-07-17 21:19:45 -05:00
hasheddan d787a8c9cf header typos: correct author spelling
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2019-07-17 19:20:04 -05:00
Nic Cope b3da55f2be Update all copyrights to 2019
This commit was generated via s/Copyright 2018/Copyright 2019/g

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-10 20:16:40 -07:00
Nic Cope 6c882fbf83 Rename BindingPhaseUnknown to BindingPhaseUnset
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-08 11:28:47 -07:00
Nic Cope 26e5f5c0b8 Revert to a string BindingPhase
This effectively reverts https://github.com/crossplaneio/crossplane/pull/325.

I still think it would be ideal to represent BindingState as an int with a sane
zero value that marshaled to a JSON string, but it is currently impossible to
override the type of the field that is used when generating an OpenAPI spec per
https://github.com/kubernetes-sigs/controller-tools/issues/155. Until that issue
is closed it seems better to simply make this a string with a meaningless zero
value.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-07-05 16:19:42 -07:00
Nic Cope fcb9e3663a Create managed resources in their resource class's namespace
https://github.com/crossplaneio/crossplane/issues/92

This returns to our historical behaviour of creating managed resources in the
namespace of thier resource class, not that of their resource claim. I believe
this pattern to be flawed, but mostly changed it in order to leverage owner
references (which cannot cross namespaces) in order to allow a claim to watch
the resources it controls.

Instead we maintain the historical behaviour for the time being, using a custom
event handler to enqueue requests for a resource's claim (reference).

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-27 00:20:40 -07:00
Nic Cope 6e3d341349 Follow API conventions for object reference fields
I had previously attempted to standardise on fooReference for an ObjectReference
to a Foo, because we had a mix of fooRef and fooReference. Turns out the API
conventions document has a position on this and says we should use fooRef. I've
kept the actual Go fields named 'FooReference' for readability, but renamed the
struct tags to 'fooRef'. I've also renamed 'writeConnectionSecretTo' to
'writeConnectionSecretToRef' since it is also a reference.

https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#object-references

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-26 11:40:11 -07:00
Nic Cope e75c2b4f5c Set all managed resources to 'unbound' when they become available
The resource claim controller uses this binding phase to determine whether a
managed resource is available for binding to a resource claim.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-24 23:47:12 -07:00
Nic Cope 68a7580935 Add new resource claim reconciler.
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-24 23:47:11 -07:00
Nic Cope 9b70f00113 Use camelcase resource kinds
These kinds must be camelcase in order to resolve them to a runtime.Object via
a runtime.Scheme.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-24 18:06:19 -07:00
Nic Cope a893baf2e8 Rename the ManagedResource interface to Managed
This way it reads resource.Managed, not resource.ManagedResource.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-24 16:10:18 -07:00
Nic Cope b27d9df2c5 Update all API types to satisfy the Resource or Claim interfaces
There's _a lot_ going on in this commit. I've updated all resources to use the
embedded ResourceSpec, ResourceStatus, ResourceClaimSpec, etc structs and added
methods to ensure they satisfy the Resource and Claim interfaces.

I've also updated all controllers to suit. I've tried my best to limit the scope
of these changes to switching all controllers and their tests to:

* Use the new ConditionedStatus
* Use their WriteConnectionSecretTo field instead of generating a secret name
* Use the new ProviderReference field (which supports referencing Providers in
  a different namespace)

I also updated many tests to use the '-want, +got' style annotation. This came
into scope mostly for my own sanity, as it allows me to read all test output the
same way when updating tests across many packages.

Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-24 16:10:18 -07:00
Nic Cope 4f2af2ec96 Replace the core resource and claim interfaces
Signed-off-by: Nic Cope <negz@rk0n.org>
2019-06-24 11:51:22 -07:00