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

vm: multiple minor fixes #442

Merged
merged 4 commits into from
Oct 13, 2022
Merged
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
13 changes: 9 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c colimaApp) Start(conf config.Config) error {

log.Println("done")

if err := generateSSHConfig(); err != nil {
if err := generateSSHConfig(conf.SSHConfig); err != nil {
log.Trace("error generating ssh_config: %w", err)
}
return nil
Expand Down Expand Up @@ -162,7 +162,7 @@ func (c colimaApp) Stop(force bool) error {

log.Println("done")

if err := generateSSHConfig(); err != nil {
if err := generateSSHConfig(false); err != nil {
log.Trace("error generating ssh_config: %w", err)
}
return nil
Expand Down Expand Up @@ -209,7 +209,7 @@ func (c colimaApp) Delete() error {

log.Println("done")

if err := generateSSHConfig(); err != nil {
if err := generateSSHConfig(false); err != nil {
log.Trace("error generating ssh_config: %w", err)
}
return nil
Expand Down Expand Up @@ -430,7 +430,7 @@ func (c colimaApp) Active() bool {
return c.guest.Running(context.Background())
}

func generateSSHConfig() error {
func generateSSHConfig(modifySSHConfig bool) error {
instances, err := limautil.Instances()
if err != nil {
return fmt.Errorf("error retrieving instances: %w", err)
Expand Down Expand Up @@ -463,6 +463,11 @@ func generateSSHConfig() error {
return fmt.Errorf("error writing ssh_config file: %w", err)
}

if !modifySSHConfig {
// ~/.ssh/config modification disabled
return nil
}

includeLine := "Include " + sshFileColima

sshFileSystem := filepath.Join(util.HomeDir(), ".ssh", "config")
Expand Down
9 changes: 9 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func init() {
// ssh agent
startCmd.Flags().BoolVarP(&startCmdArgs.ForwardAgent, "ssh-agent", "s", false, "forward SSH agent to the VM")

// ssh config generation
startCmd.Flags().BoolVar(&startCmdArgs.SSHConfig, "ssh-config", true, "generate SSH config in ~/.ssh/config")

// k8s
startCmd.Flags().BoolVarP(&startCmdArgs.Kubernetes.Enabled, "kubernetes", "k", false, "start with Kubernetes")
startCmd.Flags().BoolVar(&startCmdArgs.Flags.LegacyKubernetes, "with-kubernetes", false, "start with Kubernetes")
Expand Down Expand Up @@ -225,6 +228,9 @@ func prepareConfig(cmd *cobra.Command) {
if !cmd.Flag("kubernetes").Changed {
startCmdArgs.Kubernetes.Enabled = current.Kubernetes.Enabled
}
if !cmd.Flag("kubernetes-version").Changed {
startCmdArgs.Kubernetes.Version = current.Kubernetes.Version
}
if !cmd.Flag("runtime").Changed {
startCmdArgs.Runtime = current.Runtime
}
Expand All @@ -246,6 +252,9 @@ func prepareConfig(cmd *cobra.Command) {
if !cmd.Flag("ssh-agent").Changed {
startCmdArgs.ForwardAgent = current.ForwardAgent
}
if !cmd.Flag("ssh-config").Changed {
startCmdArgs.SSHConfig = current.SSHConfig
}
if !cmd.Flag("dns").Changed {
startCmdArgs.Network.DNS = current.Network.DNS
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type Config struct {

// provision scripts
Provision []Provision `yaml:"provision,omitempty"`

// SSH config generation
SSHConfig bool `yaml:"sshConfig,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 @@ -133,6 +133,11 @@ layer: false
# Default: []
provision: []

# Modify ~/.ssh/config automatically to include a SSH config for the virtual machine.
# SSH config will still be generated in ~/.colima/ssh_config regardless.
# Default: true
sshConfig: true

# Configure volume mounts for the virtual machine.
# Colima mounts user's home directory by default to provide a familiar
# user experience.
Expand Down
2 changes: 1 addition & 1 deletion environment/container/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const (
Name = "kubernetes"
DefaultVersion = "v1.25.0+k3s1"
DefaultVersion = "v1.25.2+k3s1"

configKey = "kubernetes_config"
)
Expand Down
2 changes: 1 addition & 1 deletion environment/vm/lima/lima.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (l limaVM) Running(ctx context.Context) bool {
func (l limaVM) Stop(ctx context.Context, force bool) error {
log := l.Logger(ctx)
a := l.Init(ctx)
if !l.Running(ctx) {
if !l.Running(ctx) && !force {
log.Println("not running")
return nil
}
Expand Down