Skip to content

Commit

Permalink
dockerdesktop: reset cluster on create, not delete (#236)
Browse files Browse the repository at this point in the history
* dockerdesktop: reset cluster on create, not delete

Fixes #232.

* dockerdesktop: pass d4mClient through to admin instance
  • Loading branch information
nicksieger authored Jun 22, 2022
1 parent 5f366c1 commit 9822a31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
30 changes: 13 additions & 17 deletions pkg/cluster/admin_docker_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
// This is a bit different than the other admins, due to the overlap
//
type dockerDesktopAdmin struct {
os string
host string
os string
host string
client d4mClient
}

func newDockerDesktopAdmin(host string, os string) *dockerDesktopAdmin {
return &dockerDesktopAdmin{os: os, host: host}
func newDockerDesktopAdmin(host string, os string, d4m d4mClient) *dockerDesktopAdmin {
return &dockerDesktopAdmin{os: os, host: host, client: d4m}
}

func (a *dockerDesktopAdmin) EnsureInstalled(ctx context.Context) error { return nil }
Expand All @@ -34,6 +35,11 @@ func (a *dockerDesktopAdmin) Create(ctx context.Context, desired *api.Cluster, r
a.host)
}

err := a.client.ResetCluster(ctx)
if err != nil {
return err
}

return nil
}

Expand All @@ -47,28 +53,18 @@ func (a *dockerDesktopAdmin) Delete(ctx context.Context, config *api.Cluster) er
return fmt.Errorf("docker-desktop cannot be deleted from DOCKER_HOST: %s", a.host)
}

client, err := NewDockerDesktopClient()
if err != nil {
return err
}

err = client.ResetCluster(ctx)
if err != nil {
return err
}

settings, err := client.settings(ctx)
settings, err := a.client.settings(ctx)
if err != nil {
return err
}

changed, err := client.setK8sEnabled(settings, false)
changed, err := a.client.setK8sEnabled(settings, false)
if err != nil {
return err
}
if !changed {
return nil
}

return client.writeSettings(ctx, settings)
return a.client.writeSettings(ctx, settings)
}
2 changes: 1 addition & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *Controller) admin(ctx context.Context, product clusterid.Product) (Admi
dockerClient.DaemonHost())
}

admin = newDockerDesktopAdmin(dockerClient.DaemonHost(), c.os)
admin = newDockerDesktopAdmin(dockerClient.DaemonHost(), c.os, c.dmachine.d4m)
case clusterid.ProductKIND:
admin = newKindAdmin(c.iostreams, dockerClient)
case clusterid.ProductK3D:
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func TestClusterApplyDockerDesktopNoRestart(t *testing.T) {
assert.NoError(t, err)
f.apply(clusterid.ProductDockerDesktop, 0)
assert.Equal(t, 1, f.d4m.settingsWriteCount)
assert.Equal(t, 1, f.d4m.resetCount)
f.apply(clusterid.ProductDockerDesktop, 0)
assert.Equal(t, 1, f.d4m.settingsWriteCount)
}
Expand Down

0 comments on commit 9822a31

Please sign in to comment.