Skip to content

Commit 1edc301

Browse files
authored
Merge pull request #129 from SAP/fix_ups_without_credentials
fix[114]: fixing ServiceInstance creation without credentials
2 parents 411af5c + 7981967 commit 1edc301

5 files changed

Lines changed: 48 additions & 18 deletions

File tree

examples/resources/orgspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
apiVersion: cloudfoundry.crossplane.io/v1alpha1
3-
kind: Org
3+
kind: Organization
44
metadata:
55
namespace: default
66
name: my-org
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
# UPS without service credentials
3+
apiVersion: cloudfoundry.crossplane.io/v1alpha1
4+
kind: ServiceInstance
5+
metadata:
6+
name: my-ups
7+
spec:
8+
forProvider:
9+
type: user-provided
10+
name: my-ups
11+
routeServiceUrl: https://my-route-service.example.com
12+
syslogDrainUrl: syslog-tls://example.log-aggregator.com:6514
13+
spaceRef:
14+
name: my-space
15+
policy:
16+
resolve: Always

internal/clients/serviceinstance/serviceinstance.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ func (c *Client) createManaged(ctx context.Context, spec v1alpha1.ServiceInstanc
186186

187187
// createUserProvided creates a user-provided service instance according to CR's ForProvider spec
188188
func (c *Client) createUserProvided(ctx context.Context, spec v1alpha1.ServiceInstanceParameters, creds json.RawMessage) (*resource.ServiceInstance, error) {
189-
// Credential is required for UPS
190-
if creds == nil {
191-
return nil, errors.New("Missing or invalid credentials")
192-
}
193-
194189
// throw error if no space is provided
195190
if spec.Space == nil {
196191
return nil, errors.New("no space reference provided")
@@ -203,9 +198,11 @@ func (c *Client) createUserProvided(ctx context.Context, spec v1alpha1.ServiceIn
203198
}
204199

205200
// workaround: cf-goclient supports few ups options at creation time.
206-
upt := resource.NewServiceInstanceUserProvidedUpdate().
207-
WithCredentials(creds).
208-
WithRouteServiceURL(spec.RouteServiceURL).
201+
upt := resource.NewServiceInstanceUserProvidedUpdate()
202+
if creds != nil {
203+
upt.WithCredentials(creds)
204+
}
205+
upt.WithRouteServiceURL(spec.RouteServiceURL).
209206
WithSyslogDrainURL(spec.SyslogDrainURL)
210207

211208
return c.ServiceInstance.UpdateUserProvided(ctx, si.GUID, upt)
@@ -265,15 +262,15 @@ func (c *Client) updateManaged(ctx context.Context, observed *resource.ServiceIn
265262
func (c *Client) updateUserProvided(ctx context.Context, observed *resource.ServiceInstance, desired *v1alpha1.ServiceInstanceParameters, creds json.RawMessage) (*resource.ServiceInstance, error) {
266263
upd := resource.NewServiceInstanceUserProvidedUpdate()
267264

268-
if creds == nil {
269-
return nil, errors.New("Missing or invalid credentials")
270-
271-
}
272265
if observed.Name != *desired.Name {
273266
upd.WithName(*desired.Name)
274267
}
275268

276-
upd.WithRouteServiceURL(desired.RouteServiceURL).WithSyslogDrainURL(desired.SyslogDrainURL).WithCredentials(creds)
269+
if creds != nil {
270+
upd.WithCredentials(creds)
271+
}
272+
upd.WithRouteServiceURL(desired.RouteServiceURL).
273+
WithSyslogDrainURL(desired.SyslogDrainURL)
277274

278275
return c.ServiceInstance.UpdateUserProvided(ctx, observed.GUID, upd)
279276
}

test/e2e/cloudfoundry_services_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ func TestCloudFoundryServices(t *testing.T) {
2828
// updated checks if resource is updated, normally by observing a new value on managed field.
2929
updated func(k8s.Object) (bool, error)
3030
}{
31-
"space": {name: "service-space", obj: &v1alpha1.Space{}},
32-
"service_instance": {name: "e2e-service-instance", obj: &v1alpha1.ServiceInstance{}},
33-
"ups": {name: "e2e-ups", obj: &v1alpha1.ServiceInstance{}},
34-
"scb_key": {name: "e2e-scb-key", obj: &v1alpha1.ServiceCredentialBinding{}},
31+
"space": {name: "service-space", obj: &v1alpha1.Space{}},
32+
"service_instance": {name: "e2e-service-instance", obj: &v1alpha1.ServiceInstance{}},
33+
"ups": {name: "e2e-ups", obj: &v1alpha1.ServiceInstance{}},
34+
"ups_no_credentials": {name: "e2e-ups-no-credentials", obj: &v1alpha1.ServiceInstance{}},
35+
"scb_key": {name: "e2e-scb-key", obj: &v1alpha1.ServiceCredentialBinding{}},
3536
}
3637

3738
var feat = features.New("CO-159 cloudfoundry e2e test services").Setup(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: cloudfoundry.crossplane.io/v1alpha1
3+
kind: ServiceInstance
4+
metadata:
5+
namespace: service-test
6+
name: e2e-ups-no-credentials
7+
spec:
8+
forProvider:
9+
type: user-provided
10+
name: e2e-ups-no-credentials
11+
routeServiceUrl: https://e2e-route-service.example.com
12+
syslogDrainUrl: syslog-tls://example.log-aggregator.com:6514
13+
spaceRef:
14+
name: service-space
15+
policy:
16+
resolve: Always

0 commit comments

Comments
 (0)