Skip to content

Commit 7981967

Browse files
author
Mykhailo Pechkurov
committed
fix[114]: fixing ServiceInstance creation without credentials
1 parent ee80170 commit 7981967

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

internal/clients/serviceinstance/serviceinstance.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (c *Client) Create(ctx context.Context, spec v1alpha1.ServiceInstanceParame
152152
return c.createManaged(ctx, spec, creds)
153153

154154
case v1alpha1.UserProvidedService:
155-
return c.createUserProvided(ctx, spec)
155+
return c.createUserProvided(ctx, spec, creds)
156156
default:
157157
return nil, errors.New("unknown service instance type")
158158
}
@@ -185,7 +185,7 @@ func (c *Client) createManaged(ctx context.Context, spec v1alpha1.ServiceInstanc
185185
}
186186

187187
// createUserProvided creates a user-provided service instance according to CR's ForProvider spec
188-
func (c *Client) createUserProvided(ctx context.Context, spec v1alpha1.ServiceInstanceParameters) (*resource.ServiceInstance, error) {
188+
func (c *Client) createUserProvided(ctx context.Context, spec v1alpha1.ServiceInstanceParameters, creds json.RawMessage) (*resource.ServiceInstance, error) {
189189
// throw error if no space is provided
190190
if spec.Space == nil {
191191
return nil, errors.New("no space reference provided")
@@ -198,8 +198,11 @@ func (c *Client) createUserProvided(ctx context.Context, spec v1alpha1.ServiceIn
198198
}
199199

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

205208
return c.ServiceInstance.UpdateUserProvided(ctx, si.GUID, upt)
@@ -259,15 +262,15 @@ func (c *Client) updateManaged(ctx context.Context, observed *resource.ServiceIn
259262
func (c *Client) updateUserProvided(ctx context.Context, observed *resource.ServiceInstance, desired *v1alpha1.ServiceInstanceParameters, creds json.RawMessage) (*resource.ServiceInstance, error) {
260263
upd := resource.NewServiceInstanceUserProvidedUpdate()
261264

262-
if creds == nil {
263-
return nil, errors.New("Missing or invalid credentials")
264-
265-
}
266265
if observed.Name != *desired.Name {
267266
upd.WithName(*desired.Name)
268267
}
269268

270-
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)
271274

272275
return c.ServiceInstance.UpdateUserProvided(ctx, observed.GUID, upd)
273276
}

test/e2e/crs/service/ups_no_credentials.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
spec:
88
forProvider:
99
type: user-provided
10-
name: 2e-ups-no-credentials
10+
name: e2e-ups-no-credentials
1111
routeServiceUrl: https://e2e-route-service.example.com
1212
syslogDrainUrl: syslog-tls://example.log-aggregator.com:6514
1313
spaceRef:

0 commit comments

Comments
 (0)