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

feat: derpmap field in config #1823

Merged
merged 1 commit into from
Oct 17, 2024
Merged

feat: derpmap field in config #1823

merged 1 commit into from
Oct 17, 2024

Conversation

gdraganic
Copy link
Contributor

@gdraganic gdraganic commented Mar 12, 2024

  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

Currently DERP map can be set only from URLs or local yaml config paths. This PR adds a simple and optional DERPMap config field which allows setting initial DERP map which is useful when using headscale programatically.

Summary by CodeRabbit

  • New Features
    • Enhanced configuration capabilities with the addition of a DERPMap field in the DERP configuration.
    • Improved logic in the DERP map retrieval process to prevent runtime errors by excluding nil values.

Copy link
Contributor

coderabbitai bot commented Aug 31, 2024

Walkthrough

The changes introduce a new field, DERPMap, to the DERPConfig struct in hscontrol/types/config.go, allowing for enhanced configuration related to DERP mappings. Additionally, the GetDERPMap function in hscontrol/derp/derp.go is modified to include a conditional check for a non-nil cfg.DERPMap, ensuring that only valid DERP maps are appended to the derpMaps slice.

Changes

Files Change Summary
hscontrol/derp/derp.go Modified GetDERPMap to check if cfg.DERPMap is not nil before appending to derpMaps.
hscontrol/types/config.go Added a new field DERPMap *tailcfg.DERPMap to the DERPConfig struct.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DERPConfig
    participant DERPMapHandler

    Client->>DERPConfig: Request DERP Map
    DERPConfig->>DERPMapHandler: Check if DERPMap is not nil
    alt DERPMap is not nil
        DERPMapHandler->>DERPConfig: Append DERPMap to derpMaps
    else DERPMap is nil
        DERPMapHandler->>DERPConfig: Skip appending
    end
    DERPConfig->>Client: Return derpMaps
Loading

🐇 "In the meadow, changes bloom,
New maps to chase away the gloom.
With checks in place, we hop with glee,
Configs now dance, wild and free!
A DERP for all, a joy to see!" 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1193a50 and f91c820.

Files selected for processing (2)
  • hscontrol/derp/derp.go (1 hunks)
  • hscontrol/types/config.go (1 hunks)

Comment on lines +85 to +87
if cfg.DERPMap != nil {
derpMaps = append(derpMaps, cfg.DERPMap)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Conditional check added to prevent nil dereferencing.

The addition of the conditional check at lines 85-87 is a good practice to ensure that only non-nil DERPMap instances are appended to the derpMaps slice. This change helps in preventing potential runtime errors due to nil dereferencing.

However, it's recommended to add unit tests to verify that this new logic correctly handles scenarios where cfg.DERPMap might be nil or non-nil.

Would you like me to help by writing some unit tests for this new logic?

@@ -179,6 +179,7 @@ type DERPConfig struct {
STUNAddr string
URLs []url.URL
Paths []string
DERPMap *tailcfg.DERPMap
Copy link
Contributor

Choose a reason for hiding this comment

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

New field DERPMap added to DERPConfig struct.

The addition of the DERPMap field at line 182 enhances the configuration capabilities of the DERPConfig struct by allowing direct assignment of a DERP map. This change is beneficial for programmatically setting the DERP map, providing more flexibility compared to the previous methods.

It's recommended to update the project's documentation to include information about this new field and its usage.

Consider updating the documentation to reflect this new configuration option.

@Tpuljak
Copy link

Tpuljak commented Oct 16, 2024

@kradalby bumping this. Are there any blockers for merging this and including it in the following releases?

@kradalby
Copy link
Collaborator

Hi sorry, I've missed this, you can already load DERP config via file, so another method seems excessive, I don't think we will include this.

@Tpuljak
Copy link

Tpuljak commented Oct 16, 2024

@kradalby I understand it can be loaded from a file, but that's a bit awkward when using headscale programmatically (as a lib). It would require the application to first write a file and then load it. Additionally, it provides more overhead if the configuration has to be updated after it was already written.

From the looks of it, the PR wouldn't undermine loading the map from file, it simply allows users to add an initial derp map as an argument of the config.

@kradalby
Copy link
Collaborator

When you say lib, do you mean as part of a go program? because in that case you can just import it and override yourself.

I still dont think we will include this, sorry.

@Tpuljak
Copy link

Tpuljak commented Oct 16, 2024

When you say lib, do you mean as part of a go program? because in that case you can just import it and override yourself.

This is how we set the initial config in Daytona and then use it to initialize the server here. It would be great if we could just add DERPMap to the initial cfg as well.

@kradalby
Copy link
Collaborator

Ok fair, sorry, in my head I thought it would expose it to users via the config, as long as we dont let users set it via config.yaml, it is ok.

@kradalby kradalby closed this Oct 16, 2024
@kradalby kradalby reopened this Oct 16, 2024
@Tpuljak
Copy link

Tpuljak commented Oct 16, 2024

Ok fair, sorry, in my head I thought it would expose it to users via the config, as long as we dont let users set it via config.yaml, it is ok.

Thanks!

@kradalby kradalby merged commit 45c9585 into juanfont:main Oct 17, 2024
121 checks passed
hopleus pushed a commit to hopleus/headscale that referenced this pull request Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants