Skip to content

Commit

Permalink
+ add ConnectionDetail/SkipPartOfReleaseCheck bool field to skip chec…
Browse files Browse the repository at this point in the history
…k for resources that not a part of helm release

Signed-off-by: RangerX <1791673+Ranger-X@users.noreply.github.com>
  • Loading branch information
Ranger-X committed Nov 29, 2022
1 parent 2153863 commit ab8da4a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apis/release/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build
4 changes: 4 additions & 0 deletions package/crds/helm.crossplane.io_releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/release/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
41 changes: 41 additions & 0 deletions pkg/controller/release/observe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ab8da4a

Please sign in to comment.