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>
This commit is contained in:
Nic Cope 2019-08-27 19:55:29 -07:00
parent e4d61ee280
commit 06b6b7dd87
3 changed files with 12 additions and 1 deletions

View File

@ -88,7 +88,7 @@ func NewAPIManagedConnectionPropagator(c client.Client, t runtime.ObjectTyper) *
// PropagateConnection details from the supplied resource to the supplied claim.
func (a *APIManagedConnectionPropagator) PropagateConnection(ctx context.Context, cm Claim, mg Managed) error {
// Either this resourace does not expose a connection secret, or this claim
// Either this resource does not expose a connection secret, or this claim
// does not want one.
if mg.GetWriteConnectionSecretToReference().Name == "" || cm.GetWriteConnectionSecretToReference().Name == "" {
return nil

View File

@ -68,6 +68,11 @@ func NewAPISecretPublisher(c client.Client, ot runtime.ObjectTyper) *APISecretPu
// the supplied Managed resource. Applying is a no-op if the secret already
// exists with the supplied ConnectionDetails.
func (a *APISecretPublisher) PublishConnection(ctx context.Context, mg Managed, c ConnectionDetails) error {
// This resource does not want to expose a connection secret.
if mg.GetWriteConnectionSecretToReference().Name == "" {
return nil
}
s := ConnectionSecretFor(mg, MustGetKind(mg, a.typer))
err := util.CreateOrUpdate(ctx, a.client, s, func() error {

View File

@ -138,6 +138,12 @@ func TestAPISecretPublisher(t *testing.T) {
args args
want error
}{
"ResourceDoesNotPublishSecret": {
args: args{
ctx: context.Background(),
mg: &MockManaged{},
},
},
"ManagedSecretConflictError": {
fields: fields{
client: &test.MockClient{