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

Change registration to be dynamic rather than static #236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bowei
Copy link
Member

@bowei bowei commented Jan 10, 2025

This allows for resources to be defined outside of the rnode package

bowei added 2 commits January 8, 2025 21:06
This allows for resources to be defined outside of the rnode package
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bowei

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bowei bowei changed the title Pr dynamic registration Change registration to be dynamic rather than static Jan 10, 2025
@bowei bowei requested a review from kl52752 January 10, 2025 17:35
builderFuncs = map[string]newBuilderFunc{}
)

// RegisterBuilder constructor. shortName is the plural lowerCamelCase resource
Copy link
Contributor

Choose a reason for hiding this comment

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

RegisterBuilder is not a constructor. The global variables are already created and this function is adding ("registering") the values so they can be used by rGraph. Can you change a bit the description?

Copy link
Member Author

Choose a reason for hiding this comment

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

The sentence is supposed to be "Register Builder constructor." but this is not allowed by go.. I will clarify by expanding the description.

type newBuilderFunc func(id *cloud.ResourceID) rnode.Builder

var (
builderFuncsLock sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it will be useful ti use RWLock. Write will happened only in init. Then in rGraph we are reading the values from the map so RLock will be more efficient.

alpha "google.golang.org/api/compute/v0.alpha"
beta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
)

func init() { all.RegisterBuilder("backendServices", NewBuilder) }
Copy link
Contributor

Choose a reason for hiding this comment

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

please extract "backendServices" to a const so we can use the value from the package and make sure that no typo will be introduced in NewBuilderByID. Please apply this comment to all cases.

@@ -31,6 +32,8 @@ const (
resourceName = "TcpRoute"
)

func init() { all.RegisterBuilder("tcpRoute", NewBuilder) }
Copy link
Contributor

Choose a reason for hiding this comment

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

should be plural tcpRoute -> tcpRoutes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants