-
Notifications
You must be signed in to change notification settings - Fork 255
Add Config to Disable Hosts File Modification #4938
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
base: main
Are you sure you want to change the base?
Conversation
|
Hi @tricktron. Thanks for your PR. I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
/retest-required |
|
@praveenkumar Thanks for running the tests. I see many timeout failures unrelated to my change. Is this normal and can I rerun the tests or do only maintainers have the right to rerun tests? |
|
/retest |
1244205 to
33f1a93
Compare
WalkthroughAdds a new public config key ModifyHostsFile (default true), surfaces it via client.modifyHostsFile into ServicePostStartConfig, conditions DNS post-start hosts-file updates on that flag across Darwin/Linux/Windows, updates some file-permission literals to 0o-prefixed octals, and extends tests for the new setting. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Client as Machine Client
participant Config as Config Store
participant Start as Start Flow
participant Svc as Services (DNS)
participant OS as OS-specific DNS
User->>Client: crc start
Client->>Config: get("modify-hosts-file")
Config-->>Client: bool
Client->>Start: ServicePostStartConfig{ModifyHostsFile=bool, ...}
Start->>Svc: runPostStart(config)
Svc->>OS: runPostStartForOS(config)
alt ModifyHostsFile == true
OS->>OS: addOpenShiftHosts()
OS-->>Svc: success/error
else ModifyHostsFile == false
OS-->>Svc: log "Skipping hosts file modification"
end
Svc-->>Start: return
Start-->>User: start complete
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used🧬 Code graph analysis (5)pkg/crc/services/dns/dns_darwin.go (1)
pkg/crc/machine/start.go (3)
pkg/crc/services/dns/dns_linux.go (2)
pkg/crc/services/dns/dns_windows.go (1)
pkg/crc/config/settings_test.go (1)
🔇 Additional comments (15)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
pkg/crc/config/settings.go (1)
133-135: Help text: make OS-agnostic to avoid misleading Windows users.Current text mentions “/etc/hosts”, which is Unix-specific. Prefer “system hosts file”.
Apply this diff:
- cfg.AddSetting(ModifyHostsFile, true, ValidateBool, SuccessfullyApplied, - "Allow CRC to modify the /etc/hosts file (true/false, default: true)") + cfg.AddSetting(ModifyHostsFile, true, ValidateBool, SuccessfullyApplied, + "Allow CRC to modify the system hosts file (true/false, default: true)")pkg/crc/services/dns/dns_darwin.go (1)
36-39: Optional: log when skipping hosts modification for visibility.A brief info log helps users correlate behavior with config.
Apply this diff:
- if serviceConfig.ModifyHostsFile { - if err := addOpenShiftHosts(serviceConfig); err != nil { - return err - } - } + if serviceConfig.ModifyHostsFile { + if err := addOpenShiftHosts(serviceConfig); err != nil { + return err + } + } else { + logging.Infof("Skipping hosts file modification on macOS (modify-hosts-file=false)") + }pkg/crc/machine/start.go (1)
506-513: Improve error message when DNS-from-host check fails with modify-hosts-file=false.Make the failure actionable by hinting at manual DNS/hosts setup when the flag is disabled.
You can adjust the message like this (snippet for context):
if err := dns.CheckCRCLocalDNSReachableFromHost(servicePostStartConfig); err != nil { if !client.useVSock() { msg := "Failed to query DNS from host" if !servicePostStartConfig.ModifyHostsFile { msg += " (modify-hosts-file=false). Ensure your system DNS/hosts entries resolve the CRC domains." } return nil, errors.Wrap(err, msg) } logging.Warn(fmt.Sprintf("Failed to query DNS from host: %v", err)) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
pkg/crc/config/settings.go(2 hunks)pkg/crc/config/settings_test.go(2 hunks)pkg/crc/machine/client.go(1 hunks)pkg/crc/machine/start.go(1 hunks)pkg/crc/services/dns/dns_darwin.go(1 hunks)pkg/crc/services/dns/dns_linux.go(1 hunks)pkg/crc/services/dns/dns_windows.go(1 hunks)pkg/crc/services/services.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (8)
pkg/crc/services/services.go (4)
pkg/crc/ssh/ssh.go (1)
Runner(16-18)pkg/crc/machine/bundle/metadata.go (1)
CrcBundleInfo(27-38)pkg/crc/config/settings.go (2)
NetworkMode(23-23)ModifyHostsFile(31-31)pkg/crc/network/types.go (1)
Mode(39-39)
pkg/crc/services/dns/dns_darwin.go (1)
pkg/crc/config/settings.go (1)
ModifyHostsFile(31-31)
pkg/crc/services/dns/dns_windows.go (1)
pkg/crc/config/settings.go (1)
ModifyHostsFile(31-31)
pkg/crc/config/settings_test.go (1)
pkg/crc/config/settings.go (1)
ModifyHostsFile(31-31)
pkg/crc/services/dns/dns_linux.go (1)
pkg/crc/config/settings.go (1)
ModifyHostsFile(31-31)
pkg/crc/machine/client.go (1)
pkg/crc/config/settings.go (1)
ModifyHostsFile(31-31)
pkg/crc/config/settings.go (2)
pkg/crc/config/validations.go (1)
ValidateBool(19-25)pkg/crc/config/callbacks.go (1)
SuccessfullyApplied(36-38)
pkg/crc/machine/start.go (2)
pkg/crc/config/settings.go (2)
NetworkMode(23-23)ModifyHostsFile(31-31)pkg/crc/preflight/labels.go (1)
NetworkMode(13-13)
🔇 Additional comments (8)
pkg/crc/config/settings.go (1)
31-31: LGTM: new setting key introduced cleanly.pkg/crc/services/dns/dns_linux.go (1)
10-14: LGTM: gating host file changes behind the new flag.pkg/crc/machine/client.go (1)
67-69: LGTM: simple accessor for the new setting.pkg/crc/services/dns/dns_windows.go (1)
15-19: LGTM: respects modify-hosts-file on Windows.pkg/crc/config/settings_test.go (2)
254-256: LGTM: default value covered in matrix.
337-339: LGTM: provided (false) value covered in matrix.pkg/crc/machine/start.go (1)
484-487: LGTM: value threaded into ServicePostStartConfig.pkg/crc/services/services.go (1)
10-15: LGTM: config plumbed via ServicePostStartConfig — no unkeyed struct literals found. Call sites in pkg/crc/machine/start.go and pkg/crc/services/dns/dns_test.go use keyed initializers.
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.
Suggest minor changes to ensure this is recorded as part of log
| if serviceConfig.ModifyHostsFile { | ||
| if err := addOpenShiftHosts(serviceConfig); err != nil { | ||
| return err | ||
| } |
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.
- }
+ } else {
+ logging.Infof("Skipping hosts file modification")
+ }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 of course applies to all the platforms (also dns_linux.go and dns_windows.go).
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.
@gbraad Thank you for your time and the review. I applied your suggestions and also the other two nitpicks by coderabbitai.
33f1a93 to
4bac765
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This change introduces a new configuration setting 'modify-hosts-file' that allows users to disable CRC's automatic modification of the /etc/hosts file. The setting defaults to true to maintain backward compatibility with existing installations.
4bac765 to
6b59ec8
Compare
|
@tricktron: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Description
This change introduces a new configuration setting
modify-hosts-filethat allows users to disable CRC's automatic modification of the /etc/hosts file. The setting defaults to true to maintain backward compatibility with existing installations.When set to false, CRC will skip adding OpenShift hostnames to the system's hosts file during cluster startup. This is particularly useful for systems like NixOS where the hosts file is managed declaratively and cannot be modified by applications, or for users who prefer to manage DNS resolution through other means.
The implementation adds the configuration option to all platform-specific DNS modules (Linux, macOS, Windows) and includes the setting in the service configuration passed to DNS setup routines.
Type of change
test, version modification, documentation, etc.)
Proposed changes
Testing
I tested this e2e on my NixOS machine by manually setting the needed host file entries:
api.crc.testing, canary-openshift-ingress-canary.apps-crc.testing, ...and with the new configmodify-hosts-file = false.Contribution Checklist
Summary by CodeRabbit