Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(group): Ignore empty resolve values in referencers #118

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions apis/groups/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ func fromPtrValue(v *int) string {
}

// resolve string value to int pointer
func toPtrValue(v string) *int {
func toPtrValue(v string) (*int, error) {
if v == "" {
return nil
return nil, nil
}

r, err := strconv.Atoi(v)
if err != nil {
return nil
}

return &r
return &r, err
}

// ResolveReferences of this Variable
Expand All @@ -64,7 +60,12 @@ func (mg *Variable) ResolveReferences(ctx context.Context, c client.Reader) erro
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = toPtrValue(rsp.ResolvedValue)
resolvedID, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedID
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
Expand All @@ -87,7 +88,12 @@ func (mg *Member) ResolveReferences(ctx context.Context, c client.Reader) error
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = toPtrValue(rsp.ResolvedValue)
resolvedID, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedID
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
Expand All @@ -110,7 +116,12 @@ func (mg *DeployToken) ResolveReferences(ctx context.Context, c client.Reader) e
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = toPtrValue(rsp.ResolvedValue)
resolvedID, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "spec.forProvider.groupId")
}

mg.Spec.ForProvider.GroupID = resolvedID
mg.Spec.ForProvider.GroupIDRef = rsp.ResolvedReference

return nil
Expand Down Expand Up @@ -143,12 +154,12 @@ func (mg *Group) ResolveReferences(ctx context.Context, c client.Reader) error {
return errors.Wrap(err, "mg.Spec.ForProvider.ParentID")
}

id, err := strconv.Atoi(rsp.ResolvedValue)
id, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "mg.Spec.ForProvider.ParentID")
}

mg.Spec.ForProvider.ParentID = &id
mg.Spec.ForProvider.ParentID = id
mg.Spec.ForProvider.ParentIDRef = rsp.ResolvedReference

for i3 := 0; i3 < len(mg.Spec.ForProvider.SharedWithGroups); i3++ {
Expand All @@ -167,11 +178,11 @@ func (mg *Group) ResolveReferences(ctx context.Context, c client.Reader) error {
return errors.Wrap(err, "mg.Spec.ForProvider.SharedWithGroups[i3].GroupID")
}

id, err = strconv.Atoi(rsp.ResolvedValue)
id, err := toPtrValue(rsp.ResolvedValue)
if err != nil {
return errors.Wrap(err, "mg.Spec.ForProvider.SharedWithGroups[i3].GroupID")
}
mg.Spec.ForProvider.SharedWithGroups[i3].GroupID = &id
mg.Spec.ForProvider.SharedWithGroups[i3].GroupID = id
mg.Spec.ForProvider.SharedWithGroups[i3].GroupIDRef = rsp.ResolvedReference

}
Expand Down
Loading