Skip to content

Commit e342b6b

Browse files
authored
Merge pull request #132 from SAP/fix_cf_secret_key
fix[113]: fixing the key property for the credentialsSecretRef
2 parents 1edc301 + adca6bb commit e342b6b

6 files changed

Lines changed: 131 additions & 8 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+

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)