Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/crc/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
ProxyCAFile = "proxy-ca-file"
ConsentTelemetry = "consent-telemetry"
EnableClusterMonitoring = "enable-cluster-monitoring"
ModifyHostsFile = "modify-hosts-file"
KubeAdminPassword = "kubeadmin-password"
DeveloperPassword = "developer-password"
Preset = "preset"
Expand Down Expand Up @@ -129,6 +130,9 @@ func RegisterSettings(cfg *Config) {
cfg.AddSetting(EnableClusterMonitoring, false, ValidateBool, SuccessfullyApplied,
"Enable cluster monitoring Operator (true/false, default: false)")

cfg.AddSetting(ModifyHostsFile, true, ValidateBool, SuccessfullyApplied,
"Allow CRC to modify the system hosts file (true/false, default: true)")

// Telemeter Configuration
cfg.AddSetting(ConsentTelemetry, "", validateYesNo, SuccessfullyApplied,
"Consent to collection of anonymous usage data (yes/no)")
Expand Down
6 changes: 6 additions & 0 deletions pkg/crc/config/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ var configDefaultValuesTestArguments = []struct {
{
EnableClusterMonitoring, false,
},
{
ModifyHostsFile, true,
},
{
ConsentTelemetry, "",
},
Expand Down Expand Up @@ -331,6 +334,9 @@ var configProvidedValuesTestArguments = []struct {
{
EnableClusterMonitoring, true,
},
{
ModifyHostsFile, false,
},
{
ConsentTelemetry, "yes",
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/crc/machine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (client *client) networkMode() network.Mode {
return crcConfig.GetNetworkMode(client.config)
}

func (client *client) modifyHostsFile() bool {
return client.config.Get(crcConfig.ModifyHostsFile).AsBool()
}

func (client *client) monitoringEnabled() bool {
return client.config.Get(crcConfig.EnableClusterMonitoring).AsBool()
}
23 changes: 14 additions & 9 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
SSHRunner: sshRunner,
IP: instanceIP,
// TODO: should be more finegrained
BundleMetadata: *vm.bundle,
NetworkMode: client.networkMode(),
BundleMetadata: *vm.bundle,
NetworkMode: client.networkMode(),
ModifyHostsFile: client.modifyHostsFile(),
}

// Run the DNS server inside the VM
Expand All @@ -506,7 +507,11 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
logging.Info("Check DNS query from host...")
if err := dns.CheckCRCLocalDNSReachableFromHost(servicePostStartConfig); err != nil {
if !client.useVSock() {
return nil, errors.Wrap(err, "Failed to query DNS from host")
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))
}
Expand Down Expand Up @@ -694,7 +699,7 @@ func createHost(machineConfig config.MachineConfig, preset crcPreset.Preset) err
if err := cluster.GenerateUserPassword(constants.GetKubeAdminPasswordPath(), "kubeadmin"); err != nil {
return errors.Wrap(err, "Error generating new kubeadmin password")
}
if err = os.WriteFile(constants.GetDeveloperPasswordPath(), []byte(constants.DefaultDeveloperPassword), 0600); err != nil {
if err = os.WriteFile(constants.GetDeveloperPasswordPath(), []byte(constants.DefaultDeveloperPassword), 0o600); err != nil {
return errors.Wrap(err, "Error writing developer password")
}
}
Expand Down Expand Up @@ -748,7 +753,7 @@ func enableEmergencyLogin(sshRunner *crcssh.Runner) error {
for i := range b {
b[i] = charset[rand.Intn(len(charset))] //nolint
}
if err := os.WriteFile(constants.PasswdFilePath, b, 0600); err != nil {
if err := os.WriteFile(constants.PasswdFilePath, b, 0o600); err != nil {
return err
}
logging.Infof("Emergency login password for core user is stored to %s", constants.PasswdFilePath)
Expand All @@ -775,7 +780,7 @@ func updateSSHKeyPair(sshRunner *crcssh.Runner) error {
}

logging.Info("Updating authorized keys...")
err = sshRunner.CopyData(publicKey, "/home/core/.ssh/authorized_keys", 0644)
err = sshRunner.CopyData(publicKey, "/home/core/.ssh/authorized_keys", 0o644)
if err != nil {
return err
}
Expand Down Expand Up @@ -874,10 +879,10 @@ func startMicroshift(ctx context.Context, sshRunner *crcssh.Runner, ocConfig oc.
if _, _, err := sshRunner.RunPrivileged("Starting microshift service", "systemctl", "start", "microshift"); err != nil {
return err
}
if err := sshRunner.CopyFileFromVM(fmt.Sprintf("/var/lib/microshift/resources/kubeadmin/api%s/kubeconfig", constants.ClusterDomain), constants.KubeconfigFilePath, 0600); err != nil {
if err := sshRunner.CopyFileFromVM(fmt.Sprintf("/var/lib/microshift/resources/kubeadmin/api%s/kubeconfig", constants.ClusterDomain), constants.KubeconfigFilePath, 0o600); err != nil {
return err
}
if err := sshRunner.CopyFile(constants.KubeconfigFilePath, "/opt/kubeconfig", 0644); err != nil {
if err := sshRunner.CopyFile(constants.KubeconfigFilePath, "/opt/kubeconfig", 0o644); err != nil {
return err
}

Expand All @@ -895,5 +900,5 @@ func ensurePullSecretPresentInVM(sshRunner *crcssh.Runner, pullSec cluster.PullS
if err != nil {
return err
}
return sshRunner.CopyDataPrivileged([]byte(content), "/etc/crio/openshift-pull-secret", 0600)
return sshRunner.CopyDataPrivileged([]byte(content), "/etc/crio/openshift-pull-secret", 0o600)
}
8 changes: 6 additions & 2 deletions pkg/crc/services/dns/dns_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ type resolverFileValues struct {

func runPostStartForOS(serviceConfig services.ServicePostStartConfig) error {
// Update /etc/hosts file for host
if err := addOpenShiftHosts(serviceConfig); err != nil {
return err
if serviceConfig.ModifyHostsFile {
if err := addOpenShiftHosts(serviceConfig); err != nil {
return err
}
Copy link
Contributor

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")
+ }

Copy link
Contributor

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).

Copy link
Author

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.

} else {
logging.Infof("Skipping hosts file modification")
}

if serviceConfig.NetworkMode == network.UserNetworkingMode {
Expand Down
9 changes: 8 additions & 1 deletion pkg/crc/services/dns/dns_linux.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package dns

import (
"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/crc-org/crc/v2/pkg/crc/services"
)

func runPostStartForOS(serviceConfig services.ServicePostStartConfig) error {
// We might need to set the firewall here to forward
// Update /etc/hosts file for host
return addOpenShiftHosts(serviceConfig)
if serviceConfig.ModifyHostsFile {
return addOpenShiftHosts(serviceConfig)
} else {
logging.Infof("Skipping hosts file modification")
}

return nil
}
10 changes: 9 additions & 1 deletion pkg/crc/services/dns/dns_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dns
import (
"fmt"

"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/crc-org/crc/v2/pkg/crc/network"
"github.com/crc-org/crc/v2/pkg/crc/services"
)
Expand All @@ -11,5 +12,12 @@ func runPostStartForOS(serviceConfig services.ServicePostStartConfig) error {
if serviceConfig.NetworkMode != network.UserNetworkingMode {
return fmt.Errorf("only user-mode networking is supported on Windows")
}
return addOpenShiftHosts(serviceConfig)

if serviceConfig.ModifyHostsFile {
return addOpenShiftHosts(serviceConfig)
} else {
logging.Infof("Skipping hosts file modification")
}

return nil
}
11 changes: 6 additions & 5 deletions pkg/crc/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

type ServicePostStartConfig struct {
Name string
SSHRunner *ssh.Runner
BundleMetadata bundle.CrcBundleInfo
IP string
NetworkMode network.Mode
Name string
SSHRunner *ssh.Runner
BundleMetadata bundle.CrcBundleInfo
IP string
NetworkMode network.Mode
ModifyHostsFile bool
}