Skip to content

Conversation

@alex-bezek
Copy link
Collaborator

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

  • create specific types
  • move them into the api package
  • creates a reusable generic FindCondition function that helps with each
  • Unfortunately, has lots of casting from our types to strings in the condition test files

Breaking Changes

No

@github-actions github-actions bot added the area/controller Issues dealing with the controller label Oct 22, 2025

// Standard condition reasons
const (
ReasonEndpointActive = "EndpointActive"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We could alias these from the ngrokv1alpha1 package to make the code easier to read. Just a thought

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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
image
image

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
image

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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can always do this later, but maybe consolidate the conditions between cloud & agent endpoint to just EndpointActive like the agent endpoint does

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Base automatically changed from alex/boundendpoints-status to main October 24, 2025 15:18
@jonstacks jonstacks added this to the controller-0.20.0 milestone Oct 27, 2025
@github-actions github-actions bot added the size/XXL Denotes a PR that changes 1000+ lines label Oct 29, 2025
@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 75.64103% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.62%. Comparing base (3b11a4d) to head (097c629).

Files with missing lines Patch % Lines
internal/testutils/ginkgo.go 0.00% 16 Missing ⚠️
internal/controller/ingress/ippolicy_controller.go 23.52% 13 Missing ⚠️
...rnal/controller/agent/agent_endpoint_controller.go 62.50% 3 Missing ⚠️
...al/controller/bindings/boundendpoint_controller.go 50.00% 2 Missing ⚠️
internal/controller/ingress/ippolicy_conditions.go 85.71% 2 Missing ⚠️
...rnal/controller/agent/agent_endpoint_conditions.go 95.23% 1 Missing ⚠️
...ernal/controller/ngrok/cloudendpoint_conditions.go 93.33% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alex-bezek alex-bezek marked this pull request as ready for review October 29, 2025 00:33
@alex-bezek alex-bezek requested a review from a team as a code owner October 29, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/controller Issues dealing with the controller size/XXL Denotes a PR that changes 1000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants