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

Remove plan dao methods #766

Merged
merged 2 commits into from
Feb 16, 2018
Merged

Conversation

shawn-hurley
Copy link
Contributor

Currently, we save a mapping between names and id and have the data in
the spec already.
This was a convenience method to quickly get that data, but when moving
to CRDs I don't think we should create a resource for a single value
mapping

Changes proposed in this pull request

  • Remove all interface and implementation methods for plans
  • Add helper method on spec to get plans from ID
  • Remove pointer to spec values memory when getting plans. Makes it more memory safe

* Currently we save a mapping between names and id and have the data in
the spec already.
* This was a convince method to quickly get that data, but when moving
to CRDs I don't think we should create a resource for a single value
mapping
@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 15, 2018
@shawn-hurley shawn-hurley added feature needs-review 3.10 | release-1.2 Kubernetes 1.10 | Openshift 3.10 | Broker release-1.2 labels Feb 15, 2018
@jmontleon
Copy link
Contributor

ACK

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, if the pointer isn't really needed, ignore my suggestion :)

pkg/apb/types.go Outdated
return Plan{}, false
}

// GetPlanFromID - retrieves a refernece to a plan from a spec by name. Will return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: refernece -> reference

return plan, true
}
}
return Plan{}, false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a common pattern? Seems kind of weird to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be bad to still return a pointer but then return a copy of the plan?

func (s *Spec) GetPlanFromID(id string) *Plan {
    for _, plan := range s.Plans {
        if plan.ID == id {
            var copy = &Plan{}
            *copy = *s.plan
            return copy
        }   
    }   
    return nil
}  

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't be bad as far as I know and if you have strong feelings then I'll change it, but the above behavior is the same behavior you get from the map. val, ok := map["unknownkey"] returns the empty value for val and false.

I would argue that the pointer here does not make sense. We don't want to manipulate the plan in the Spec and therefore a pointer return is misleading IMO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning-by-value makes sense to me here if we're going to be returning a copy anyway.

Copy link
Contributor

@eriknelson eriknelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels much cleaner, and is deleting a bunch of code that isn't required, which is always a good thing. +1 from me.

@jmrodri jmrodri merged commit 1526cd8 into openshift:master Feb 16, 2018
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
* remove plans names -> id mapping from storage.

* Currently we save a mapping between names and id and have the data in
the spec already.
* This was a convince method to quickly get that data, but when moving
to CRDs I don't think we should create a resource for a single value
mapping

* clean up copied comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 | release-1.2 Kubernetes 1.10 | Openshift 3.10 | Broker release-1.2 feature needs-review size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants