Skip to content

Commit bfba7d8

Browse files
author
Mykhailo Pechkurov
committed
fix[113]: fixing the key property for the credentialsSecretRef
1 parent 1edc301 commit bfba7d8

7 files changed

Lines changed: 149 additions & 22 deletions

File tree

apis/resources/v1alpha1/serviceinstance_types.go

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/resources/v1alpha1/zz_generated.deepcopy.go

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: my-credentials
6+
namespace: default
7+
type: Opaque
8+
stringData:
9+
login: |
10+
{
11+
"username": "admin",
12+
"password": "secret"
13+
}
14+
config: |
15+
{
16+
"database": {
17+
"host": "localhost",
18+
"port": 5432
19+
}
20+
}
21+
22+
---
23+
# UPS with service credentials from a secret ref
24+
apiVersion: cloudfoundry.crossplane.io/v1alpha1
25+
kind: ServiceInstance
26+
metadata:
27+
name: my-ups
28+
spec:
29+
forProvider:
30+
type: user-provided
31+
name: my-ups
32+
routeServiceUrl: https://my-route-service.example.com
33+
syslogDrainUrl: syslog-tls://example.log-aggregator.com:6514
34+
spaceRef:
35+
name: my-space
36+
policy:
37+
resolve: Always
38+
credentialsSecretRef:
39+
key: login
40+
name: my-credentials
41+
namespace: default
42+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: my-credentials
6+
namespace: default
7+
type: Opaque
8+
stringData:
9+
login: |
10+
{
11+
"username": "admin",
12+
"password": "secret"
13+
}
14+
config: |
15+
{
16+
"database": {
17+
"host": "localhost",
18+
"port": 5432
19+
}
20+
}
21+
22+
---
23+
# UPS with service credentials from a secret ref
24+
apiVersion: cloudfoundry.crossplane.io/v1alpha1
25+
kind: ServiceInstance
26+
metadata:
27+
name: my-ups
28+
spec:
29+
forProvider:
30+
type: user-provided
31+
name: my-ups
32+
routeServiceUrl: https://my-route-service.example.com
33+
syslogDrainUrl: syslog-tls://example.log-aggregator.com:6514
34+
spaceRef:
35+
name: my-space
36+
policy:
37+
resolve: Always
38+
credentialsSecretRef:
39+
name: my-credentials
40+
namespace: default
41+

examples/serviceinstance/ups-dynatrace.yaml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ apiVersion: v1
33
kind: Secret
44
metadata:
55
name: my-credentials
6-
namespace: crossplane-system
6+
namespace: default
77
type: Opaque
88
data:
9-
login: |
10-
{
11-
"username": "admin",
12-
"password": "secret"
13-
}
14-
config: |
15-
{
16-
"database": {
17-
"host": "localhost",
18-
"port": 5432
19-
}
20-
}
9+
login: eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJzZWNyZXQifQ==
10+
config: eyJkYXRhYmFzZSI6eyJob3N0IjoibG9jYWxob3N0IiwicG9ydCI6NTQzMn19
11+
12+
# Above are base64 encoded values of below stringData:
13+
# login: |
14+
# {
15+
# "username": "admin",
16+
# "password": "secret"
17+
# }
18+
# config: |
19+
# {
20+
# "database": {
21+
# "host": "localhost",
22+
# "port": 5432
23+
# }
24+
# }
2125

2226
---
2327
# UPS with service credentials from a secret ref
@@ -37,5 +41,5 @@ spec:
3741
resolve: Always
3842
credentialsSecretRef:
3943
name: my-credentials
40-
namespace: crossplane-system
44+
namespace: default
4145

internal/controller/serviceinstance/controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ func extractCredentialSpec(ctx context.Context, kube k8s.Client, spec v1alpha1.S
309309
return []byte(*spec.JSONParams), nil
310310
}
311311

312-
return clients.ExtractSecret(ctx, kube, spec.ParametersSecretRef, "")
312+
if spec.ParametersSecretRef != nil {
313+
return clients.ExtractSecret(ctx, kube, spec.ParametersSecretRef.SecretReference, spec.ParametersSecretRef.Key)
314+
}
313315
}
314316

315317
if spec.Type == v1alpha1.UserProvidedService {
@@ -320,7 +322,9 @@ func extractCredentialSpec(ctx context.Context, kube k8s.Client, spec v1alpha1.S
320322
if spec.JSONCredentials != nil {
321323
return []byte(*spec.JSONCredentials), nil
322324
}
323-
return clients.ExtractSecret(ctx, kube, spec.CredentialsSecretRef, "")
325+
if spec.CredentialsSecretRef != nil {
326+
return clients.ExtractSecret(ctx, kube, spec.CredentialsSecretRef.SecretReference, spec.CredentialsSecretRef.Key)
327+
}
324328
}
325329
return nil, nil
326330
}

package/crds/cloudfoundry.crossplane.io_serviceinstances.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ spec:
9797
Secret reference. Ignored if `credentials` or `jsonCredentials`
9898
is set.
9999
properties:
100+
key:
101+
description: The key to select.
102+
type: string
100103
name:
101104
description: Name of the secret.
102105
type: string
@@ -145,6 +148,9 @@ spec:
145148
Secret reference. Ignored if `parameters` or `jsonParams` is
146149
set.
147150
properties:
151+
key:
152+
description: The key to select.
153+
type: string
148154
name:
149155
description: Name of the secret.
150156
type: string

0 commit comments

Comments
 (0)