refactor condition consts to be typed and available in api package#691
refactor condition consts to be typed and available in api package#691alex-bezek wants to merge 14 commits into
Conversation
|
|
||
| // Standard condition reasons | ||
| const ( | ||
| ReasonEndpointActive = "EndpointActive" |
There was a problem hiding this comment.
nit: We could alias these from the ngrokv1alpha1 package to make the code easier to read. Just a thought
There was a problem hiding this comment.
what strat would you use here? We already import the CRDs through the same package, and each package contains multiple CRDs so i don't think i can alias it to something CRD specific or condition specific
There was a problem hiding this comment.
I left it as a nit because its more of a personal preference on easier reading. Here's a diff of what it would look like https://github.com/ngrok/ngrok-operator/compare/alex/conditions-types-refactoring...jonstacks:ngrok-operator:stacks/condition-refactoring?expand=1
My main thought was the lines were getting really long and the with the import alias in there already it was hard to read. We're also in the agent package already, so for the aliases: ngrokv1alpha1.AgentEndpointReasonActive -> ReasonActive in this package was the thought.
If you think its an improvement, feel free to merge it into your branch
There was a problem hiding this comment.
Looking at this more closely, i do like the readability, but I'm not a big fan of the aliases.go file. The branch has it setup for the agent conditions, but we would need to do this for each of the conditions in each package that has conditions. I worry this will just be more maintenance and confusing on where to add conditions. Additionally, it looks like you lose out on the original type documentation


If you just want to reduce the line length, we could import the v1alpha1 package like this instead
. "github.com/ngrok/ngrok-operator/api/ngrok/v1alpha1"
and drop the ngrokv1alpha1 from a bunch of lines

Although in theory hopefully these become just v1 soon
I also considered if the variable names should just drop the resource specific prefix since agent endpoint and cloud endpoint are in the same package and could be combined, but i believe we also plan to collapse the different api packages down into a single one which would change all that so we would need to distriguish between endpoints, domains, boundendpoints, etc
| const ( | ||
| // CloudEndpointReasonActive is used when the CloudEndpoint is fully active | ||
| // and ready in the ngrok cloud. | ||
| CloudEndpointReasonActive CloudEndpointConditionReadyReason = "CloudEndpointActive" |
There was a problem hiding this comment.
We can always do this later, but maybe consolidate the conditions between cloud & agent endpoint to just EndpointActive like the agent endpoint does
There was a problem hiding this comment.
You mean to update the string value to just be EndpoitnActive and get rid of this variable in favor of a common EndpointReasonActive variable? I actually had in my todo notes to do the opposite and make the agent endpoint string more specific to follow this pattern.
I'm a bit hesitant to combine them because:
- they are very similar but have some differences and might diverge more in minor ways so i'm weary of trying to dry things up too much when there are only 2
- everything else is a 1-1 pattern so it makes a one off pattern.
I think i need to fix the consistency one way or another though. If you have a strong opinion one way or another I'm happy to do that, otherwise I might update the agent endpoint strings to specify agentendpoint in them to be consistent with this and domains
There was a problem hiding this comment.
I thought they were more similar and just trying to collapse the surface area where possible. If there is enough nuance in the conditions, then +1 with keeping them separate, but either way I think we should shoot for consistency.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #691 +/- ##
==========================================
+ Coverage 48.55% 48.62% +0.07%
==========================================
Files 95 97 +2
Lines 10452 10473 +21
==========================================
+ Hits 5075 5093 +18
- Misses 5024 5032 +8
+ Partials 353 348 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What
refactors conditions consts and helpers to have types for each condition and reason string. This helps us generate docs for each type and prevents footgun issues of using the wrong condition or reason in the wrong situation
How
Breaking Changes
No