diff --git a/apis/release/v1beta1/types.go b/apis/release/v1beta1/types.go index 9631229..8721287 100644 --- a/apis/release/v1beta1/types.go +++ b/apis/release/v1beta1/types.go @@ -124,6 +124,8 @@ type ReleaseStatus struct { type ConnectionDetail struct { v1.ObjectReference `json:",inline"` ToConnectionSecretKey string `json:"toConnectionSecretKey,omitempty"` + // SkipPartOfReleaseCheck skips check for meta.helm.sh/release-name annotation. + SkipPartOfReleaseCheck bool `json:"skipPartOfReleaseCheck,omitempty"` } // +kubebuilder:object:root=true diff --git a/build b/build index 2fc4678..207d7d1 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 2fc4678a45e227e73719a84dfe88dadce47efafb +Subproject commit 207d7d194db6a24862e0c8c6279a9ed5388541e7 diff --git a/package/crds/helm.crossplane.io_releases.yaml b/package/crds/helm.crossplane.io_releases.yaml index 56966f3..74307ac 100644 --- a/package/crds/helm.crossplane.io_releases.yaml +++ b/package/crds/helm.crossplane.io_releases.yaml @@ -555,6 +555,10 @@ spec: description: 'Specific resourceVersion to which this reference is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' type: string + skipPartOfReleaseCheck: + description: SkipPartOfReleaseCheck skips check for meta.helm.sh/release-name + annotation. + type: boolean toConnectionSecretKey: type: string uid: diff --git a/pkg/controller/release/observe.go b/pkg/controller/release/observe.go index b283a28..64ae702 100644 --- a/pkg/controller/release/observe.go +++ b/pkg/controller/release/observe.go @@ -134,8 +134,7 @@ func connectionDetails(ctx context.Context, kube client.Client, connDetails []v1 return mcd, errors.Wrap(err, "cannot get object") } - // TODO(hasan): consider making this check configurable, i.e. possible to skip via a field in spec - if !partOfRelease(ro, relName, relNamespace) { + if !cd.SkipPartOfReleaseCheck && !partOfRelease(ro, relName, relNamespace) { return mcd, errors.Errorf(errObjectNotPartOfRelease, cd.ObjectReference) } diff --git a/pkg/controller/release/observe_test.go b/pkg/controller/release/observe_test.go index eac7c58..da1db69 100644 --- a/pkg/controller/release/observe_test.go +++ b/pkg/controller/release/observe_test.go @@ -475,7 +475,48 @@ func Test_connectionDetails(t *testing.T) { }, }, }, + + "Success_NotPartOfReleaseAndSkipPartOfReleaseCheck": { + args: args{ + kube: &test.MockClient{ + MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error { + if o, ok := obj.(*unstructured.Unstructured); o.GetKind() == "Secret" && ok && key.Name == testSecretName && key.Namespace == testNamespace { + *obj.(*unstructured.Unstructured) = unstructured.Unstructured{ + Object: map[string]interface{}{ + "data": map[string]interface{}{ + "db-password": "MTIzNDU=", + }, + }, + } + } + return nil + }, + }, + + connDetails: []v1beta1.ConnectionDetail{ + { + ObjectReference: corev1.ObjectReference{ + Kind: "Secret", + Namespace: testNamespace, + Name: testSecretName, + APIVersion: "v1", + FieldPath: "data.db-password", + }, + ToConnectionSecretKey: "password", + SkipPartOfReleaseCheck: true, + }, + }, + relName: testReleaseName, + relNamespace: testNamespace, + }, + want: want{ + out: managed.ConnectionDetails{ + "password": []byte("12345"), + }, + }, + }, } + for name, tc := range cases { t.Run(name, func(t *testing.T) { got, gotErr := connectionDetails(context.Background(), tc.args.kube, tc.args.connDetails, tc.args.relName, tc.args.relNamespace)