Skip to content

Commit

Permalink
cluster: add HostFromClusterNetwork to minikube (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks authored Nov 17, 2020
1 parent 6846688 commit d1ab88a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
5 changes: 4 additions & 1 deletion pkg/cluster/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
type Admin interface {
EnsureInstalled(ctx context.Context) error
Create(ctx context.Context, desired *api.Cluster, registry *api.Registry) error
LocalRegistryHosting(registry *api.Registry) *localregistry.LocalRegistryHostingV1

// Infers the LocalRegistryHosting that this admin will try to configure.
LocalRegistryHosting(ctx context.Context, desired *api.Cluster, registry *api.Registry) (*localregistry.LocalRegistryHostingV1, error)

Delete(ctx context.Context, config *api.Cluster) error
}
4 changes: 2 additions & 2 deletions pkg/cluster/admin_docker_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (a *dockerDesktopAdmin) Create(ctx context.Context, desired *api.Cluster, r
return fmt.Errorf("docker-desktop Kubernetes clusters are only available on macos and windows")
}

func (a *dockerDesktopAdmin) LocalRegistryHosting(registry *api.Registry) *localregistry.LocalRegistryHostingV1 {
return nil
func (a *dockerDesktopAdmin) LocalRegistryHosting(ctx context.Context, desired *api.Cluster, registry *api.Registry) (*localregistry.LocalRegistryHostingV1, error) {
return nil, nil
}

func (a *dockerDesktopAdmin) Delete(ctx context.Context, config *api.Cluster) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/admin_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (a *kindAdmin) inKindNetwork(registry *api.Registry) bool {
return false
}

func (a *kindAdmin) LocalRegistryHosting(registry *api.Registry) *localregistry.LocalRegistryHostingV1 {
func (a *kindAdmin) LocalRegistryHosting(ctx context.Context, desired *api.Cluster, registry *api.Registry) (*localregistry.LocalRegistryHostingV1, error) {
return &localregistry.LocalRegistryHostingV1{
Host: fmt.Sprintf("localhost:%d", registry.Status.HostPort),
HostFromClusterNetwork: fmt.Sprintf("%s:%d", registry.Name, registry.Status.ContainerPort),
Help: "https://github.com/tilt-dev/ctlptl",
}
}, nil
}

func (a *kindAdmin) Delete(ctx context.Context, config *api.Cluster) error {
Expand Down
19 changes: 15 additions & 4 deletions pkg/cluster/admin_minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,22 @@ func (a *minikubeAdmin) inRegistryNetwork(registry *api.Registry, networkMode co
return false
}

func (a *minikubeAdmin) LocalRegistryHosting(registry *api.Registry) *localregistry.LocalRegistryHostingV1 {
return &localregistry.LocalRegistryHostingV1{
Host: fmt.Sprintf("localhost:%d", registry.Status.HostPort),
Help: "https://github.com/tilt-dev/ctlptl",
func (a *minikubeAdmin) LocalRegistryHosting(ctx context.Context, desired *api.Cluster, registry *api.Registry) (*localregistry.LocalRegistryHostingV1, error) {
container, err := a.dockerClient.ContainerInspect(ctx, desired.Name)
if err != nil {
return nil, errors.Wrap(err, "inspecting minikube cluster")
}
networkMode := container.HostConfig.NetworkMode
networkHost := registry.Status.IPAddress
if networkMode.IsUserDefined() {
networkHost = registry.Name
}

return &localregistry.LocalRegistryHostingV1{
Host: fmt.Sprintf("localhost:%d", registry.Status.HostPort),
HostFromClusterNetwork: fmt.Sprintf("%s:%d", networkHost, registry.Status.ContainerPort),
Help: "https://github.com/tilt-dev/ctlptl",
}, nil
}

func (a *minikubeAdmin) Delete(ctx context.Context, config *api.Cluster) error {
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ func (c *Controller) Apply(ctx context.Context, desired *api.Cluster) (*api.Clus
// Create a configmap on the cluster, so that other tools know that a registry
// has been configured.
func (c *Controller) createRegistryHosting(ctx context.Context, admin Admin, cluster *api.Cluster, reg *api.Registry) error {
hosting := admin.LocalRegistryHosting(reg)
hosting, err := admin.LocalRegistryHosting(ctx, cluster, reg)
if err != nil {
return err
}
if hosting == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ func (a *fakeAdmin) Create(ctx context.Context, config *api.Cluster, registry *a
return nil
}

func (a *fakeAdmin) LocalRegistryHosting(registry *api.Registry) *localregistry.LocalRegistryHostingV1 {
func (a *fakeAdmin) LocalRegistryHosting(ctx context.Context, cluster *api.Cluster, registry *api.Registry) (*localregistry.LocalRegistryHostingV1, error) {
return &localregistry.LocalRegistryHostingV1{
Host: fmt.Sprintf("localhost:%d", registry.Status.HostPort),
Help: "https://github.com/tilt-dev/ctlptl",
}
}, nil
}

func (a *fakeAdmin) Delete(ctx context.Context, config *api.Cluster) error {
Expand Down

0 comments on commit d1ab88a

Please sign in to comment.