Skip to content

Commit

Permalink
vm: temporary workaround for #764 (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
abiosoft authored Oct 5, 2023
1 parent dfe8579 commit 819ba26
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ func init() {
// dns
startCmd.Flags().IPSliceVarP(&startCmdArgs.Network.DNSResolvers, "dns", "n", nil, "DNS resolvers for the VM")
startCmd.Flags().StringSliceVar(&startCmdArgs.Flags.DNSHosts, "dns-host", nil, "custom DNS names to provide to resolver")

// cgroups v2 workaround
startCmd.Flags().BoolVar(&startCmdArgs.TempCgroupsV2, "cgroups-v2", false, "cgroups v2 workaround for docker-compose")
}

func dnsHostsFromFlag(hosts []string) map[string]string {
Expand Down Expand Up @@ -400,6 +403,10 @@ func prepareConfig(cmd *cobra.Command) {
startCmdArgs.ActivateRuntime = current.ActivateRuntime
}
}
// cgroups v2 temp workaround
if !cmd.Flag("cgroups-v2").Changed {
startCmdArgs.TempCgroupsV2 = current.TempCgroupsV2
}
if util.MacOS() {
if !cmd.Flag("network-driver").Changed {
startCmdArgs.Network.Driver = current.Network.Driver
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type Config struct {

// SSH config generation
SSHConfig bool `yaml:"sshConfig,omitempty"`

// Temporary workaround for cgroups v2.
TempCgroupsV2 bool `yaml:"cgroupsV2,omitempty"`
}

// Kubernetes is kubernetes configuration
Expand Down
5 changes: 5 additions & 0 deletions embedded/defaults/colima.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,8 @@ mounts: []
#
# Default: {}
env: {}

# Enable cgroups v2 as a temporary workaround for https://github.com/abiosoft/colima/issues/764.
# NOTE: this is incompatible with Kubernetes and Ubuntu Layer.
# NOTE: this config will be removed in future versions.
cgroupsV2: false
27 changes: 27 additions & 0 deletions environment/vm/lima/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,33 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) {
Script: `grep -q "^rc_env_allow" /etc/rc.conf || echo 'rc_env_allow="*"' >> /etc/rc.conf`,
})

// cgroups v2 workaround
{
// delete setting if present
l.Provision = append(l.Provision, Provision{
Mode: ProvisionModeSystem,
Script: `(grep -q "^rc_cgroup_mode" /etc/rc.conf && sed -i '/^rc_cgroup_mode/d' /etc/rc.conf && service cgroups restart) || echo 'cgroup v2 config not found'`,
})

// validate workaround is supported
if conf.TempCgroupsV2 {
if conf.Kubernetes.Enabled {
logrus.Warnln("cgroups v2 workaround not compatible with Kubernetes, ignoring...")
conf.TempCgroupsV2 = false
}
if conf.Layer {
logrus.Warnln("cgroups v2 workaround not compatible with Ubuntu layer, ignoring...")
conf.TempCgroupsV2 = false
}
}

if conf.TempCgroupsV2 {
l.Provision = append(l.Provision, Provision{
Mode: ProvisionModeSystem,
Script: `echo 'rc_cgroup_mode="unified"' >> /etc/rc.conf && service cgroups restart`,
})
}
}
}

// network setup
Expand Down

0 comments on commit 819ba26

Please sign in to comment.