ServiceInstance External-Name Handling#311
Conversation
Signed-off-by: Zoltan Szabo <zoltan.szabo03@sap.com>
Signed-off-by: Zoltan Szabo <zoltan.szabo03@sap.com>
SatabdiG
left a comment
There was a problem hiding this comment.
Good work, Some comments from my side.
| // - Follows Standard: yes | ||
| // - Format: ServiceInstance GUID (UUID format) | ||
| // - How to find: | ||
| // - UI: In the BTP Cockpit, navigate to your service instance; the GUID is the ID in the URL |
There was a problem hiding this comment.
I think there is an indentation off here, UI and CLI are children of How to find right?
There was a problem hiding this comment.
Other resources has the same because gofmt rewrites the comment in case of nesting. We could definitely work on this, but currently gofmt would fail.
|
|
||
| // MatchSingle retrieves external resource by matching CR's ForProvider spec | ||
| func (c *Client) MatchSingle(ctx context.Context, spec v1alpha1.ServiceInstanceParameters) (*resource.ServiceInstance, error) { | ||
| // Backward-compat lookup requires at least a name to match on. |
There was a problem hiding this comment.
I know you didn't touch this part, but reading it together, we might have a bug.
I see pollJobComplete intentionally swallows async timeout errors (comment explains this is by design, deferring to later state observation), and the subsequent MatchSingle call returns (nil, nil) when no match is found yet — treating "not visible yet" the same as "doesn't exist".
So c.serviceinstance.Create can return (nil, nil) for a managed service instance whose creation is still in progress when the poll times out. err is nil, so the guard above doesn't catch it, and r.GUID panics.
Maybe we can safeguard it here, make external name handling more robust, what do you think?
There was a problem hiding this comment.
Very true, fixed with a new UT!
| return managed.ExternalDelete{}, errors.New(errDelete) | ||
| // ADR: the external-name (GUID) identifies the resource to delete; nothing to do if unset. | ||
| guid := meta.GetExternalName(cr) | ||
| if guid == "" { |
There was a problem hiding this comment.
minor: Should we also validate the guid here? Worse case here is CF-side crash but still.
There was a problem hiding this comment.
Good point, fixed as well.
| @@ -140,19 +140,25 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex | |||
| return managed.ExternalObservation{}, errors.New(errWrongCRType) | |||
| } | |||
There was a problem hiding this comment.
nit: You didn;t touch part of this code:
if _, err := uuid.Parse(guid); err == nil {
// We have a valid external-name annotation
return nil
}
but should we replace uuid.Parse(guid) with clients.IsValidGUID for a single source of truth on what counts as a valid external-nam
There was a problem hiding this comment.
True, fixed, dropped the now unused uuid.
| }, | ||
| want: want{ | ||
| mg: serviceInstance("managed", withExternalName(guid)), | ||
| mg: serviceInstance("managed", withExternalName(guid), withSpace(spaceGUID), withServicePlan(v1alpha1.ServicePlanParameters{ID: &servicePlan})), |
There was a problem hiding this comment.
I see TestObserve, TestCreate, TestCreate case structs declare the kube k8s.Client.
But the test runner never reads tc.kube; it always constructs a hardcoded &test.MockClient{MockUpdate: test.NewMockUpdateFn(nil)}. Wouldn't that mean there's currently no way to simulate c.kube.Update failing? So in return the Observe's adoption path (meta.SetExternalName + c.kube.Update) and postCreate (c.kube.Update then c.kube.Status().Update) both have an errUpdateCR error path that would never exercised?
There was a problem hiding this comment.
Good catch, fixed!
|
|
||
| serviceInstance := &v1alpha1.ServiceInstance{} | ||
|
|
||
| err = r.Get(ctx, serviceInstanceName, cfg.Namespace(), serviceInstance) |
There was a problem hiding this comment.
Should we also use SchemeBuilder here same as PreUpgrade
There was a problem hiding this comment.
AddToScheme already covers PostUpgrade I think, same as in the other resources, but we could mirror App if that's preferred.
Signed-off-by: Zoltan Szabo <zoltan.szabo03@sap.com>
Closes: #246