-
Notifications
You must be signed in to change notification settings - Fork 84
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
Conversation
* 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
ACK |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
* 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.
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