Skip to content

Commit

Permalink
improve observe
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Jan 15, 2025
1 parent 6ea6820 commit 46a2879
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion internal/controller/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, errors.New(errNotGroup)
}

observedGroup, err := c.cloudianService.GetGroup(ctx, meta.GetExternalName(mg))
externalName := meta.GetExternalName(cr)
if externalName == "" {
return managed.ExternalObservation{}, nil
}

observedGroup, err := c.cloudianService.GetGroup(ctx, externalName)
if err != nil {
if errors.Is(err, cloudian.ErrNotFound) {
return managed.ExternalObservation{ResourceExists: false}, nil
Expand Down
13 changes: 12 additions & 1 deletion internal/controller/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,18 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, errors.New(errNotUser)
}

users, err := c.cloudianService.ListUsers(ctx, cr.Spec.ForProvider.Group, nil)
externalName := meta.GetExternalName(cr)
if externalName == "" {
return managed.ExternalObservation{}, nil
}

group := cr.Spec.ForProvider.Group
if group == "" {
return managed.ExternalObservation{}, nil
}

// TODO: GET User instead of listing users for group
users, err := c.cloudianService.ListUsers(ctx, group, nil)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, errListUsers)
}
Expand Down

0 comments on commit 46a2879

Please sign in to comment.