Skip to content

Commit 22bf286

Browse files
committed
Support Ingress on MacOS, driver docker
1 parent c3c4d04 commit 22bf286

File tree

6 files changed

+71
-26
lines changed

6 files changed

+71
-26
lines changed

cmd/minikube/cmd/tunnel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var tunnelCmd = &cobra.Command{
8686
sshPort := strconv.Itoa(port)
8787
sshKey := filepath.Join(localpath.MiniPath(), "machines", cname, "id_rsa")
8888

89-
kicSSHTunnel := kic.NewSSHTunnel(ctx, sshPort, sshKey, clientset.CoreV1())
89+
kicSSHTunnel := kic.NewSSHTunnel(ctx, sshPort, sshKey, clientset.CoreV1(), clientset.NetworkingV1())
9090
err = kicSSHTunnel.Start()
9191
if err != nil {
9292
exit.Error(reason.SvcTunnelStart, "error starting tunnel", err)

pkg/addons/addons.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,8 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
153153
// to match both ingress and ingress-dns addons
154154
if strings.HasPrefix(name, "ingress") && enable {
155155
if driver.IsKIC(cc.Driver) {
156-
if runtime.GOOS == "windows" {
156+
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
157157
out.Styled(style.Tip, `After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "127.0.0.1"`)
158-
} else if runtime.GOOS != "linux" {
159-
exit.Message(reason.Usage, `Due to networking limitations of driver {{.driver_name}} on {{.os_name}}, {{.addon_name}} addon is not supported.
160-
Alternatively to use this addon you can use a vm-based driver:
161-
162-
'minikube start --vm=true'
163-
164-
To track the update on this work in progress feature please check:
165-
https://github.com/kubernetes/minikube/issues/7332`, out.V{"driver_name": cc.Driver, "os_name": runtime.GOOS, "addon_name": name})
166158
} else if driver.BareMetal(cc.Driver) {
167159
out.WarningT(`Due to networking limitations of driver {{.driver_name}}, {{.addon_name}} addon is not fully supported. Try using a different driver.`,
168160
out.V{"driver_name": cc.Driver, "addon_name": name})

pkg/minikube/out/out.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func Styled(st style.Enum, format string, a ...V) {
118118
func boxedCommon(printFunc func(format string, a ...interface{}), cfg box.Config, title string, format string, a ...V) {
119119
box := box.New(cfg)
120120
if !useColor {
121-
box.Config.Color = ""
121+
box.Config.Color = nil
122122
}
123123
str := Sprintf(style.None, format, a...)
124124
printFunc(box.String(title, strings.TrimSpace(str)))

pkg/minikube/tunnel/kic/ssh_conn.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type sshConn struct {
3636
activeConn bool
3737
}
3838

39-
func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
39+
func createSSHConn(name, sshPort, sshKey string, resourcePorts []int32, resourceIP string, resourceName string) *sshConn {
4040
// extract sshArgs
4141
sshArgs := []string{
4242
// TODO: document the options here
@@ -50,17 +50,17 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
5050

5151
askForSudo := false
5252
var privilegedPorts []int32
53-
for _, port := range svc.Spec.Ports {
53+
for _, port := range resourcePorts {
5454
arg := fmt.Sprintf(
5555
"-L %d:%s:%d",
56-
port.Port,
57-
svc.Spec.ClusterIP,
58-
port.Port,
56+
port,
57+
resourceIP,
58+
port,
5959
)
6060

6161
// check if any port is privileged
62-
if port.Port < 1024 {
63-
privilegedPorts = append(privilegedPorts, port.Port)
62+
if port < 1024 {
63+
privilegedPorts = append(privilegedPorts, port)
6464
askForSudo = true
6565
}
6666

@@ -71,8 +71,8 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
7171
if askForSudo && runtime.GOOS != "windows" {
7272
out.Styled(
7373
style.Warning,
74-
"The service {{.service}} requires privileged ports to be exposed: {{.ports}}",
75-
out.V{"service": svc.Name, "ports": fmt.Sprintf("%v", privilegedPorts)},
74+
"The service/ingress {{.resource}} requires privileged ports to be exposed: {{.ports}}",
75+
out.V{"resource": resourceName, "ports": fmt.Sprintf("%v", privilegedPorts)},
7676
)
7777

7878
out.Styled(style.Permissions, "sudo permission will be asked for it.")
@@ -89,7 +89,7 @@ func createSSHConn(name, sshPort, sshKey string, svc *v1.Service) *sshConn {
8989

9090
return &sshConn{
9191
name: name,
92-
service: svc.Name,
92+
service: resourceName,
9393
cmd: cmd,
9494
activeConn: false,
9595
}

pkg/minikube/tunnel/kic/ssh_tunnel.go

+56-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import (
2323
"time"
2424

2525
v1 "k8s.io/api/core/v1"
26+
v1_networking "k8s.io/api/networking/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
typed_core "k8s.io/client-go/kubernetes/typed/core/v1"
29+
typed_networking "k8s.io/client-go/kubernetes/typed/networking/v1"
2830

2931
"k8s.io/klog/v2"
3032
"k8s.io/minikube/pkg/minikube/tunnel"
@@ -36,19 +38,21 @@ type SSHTunnel struct {
3638
sshPort string
3739
sshKey string
3840
v1Core typed_core.CoreV1Interface
41+
v1Networking typed_networking.NetworkingV1Interface
3942
LoadBalancerEmulator tunnel.LoadBalancerEmulator
4043
conns map[string]*sshConn
4144
connsToStop map[string]*sshConn
4245
}
4346

4447
// NewSSHTunnel ...
45-
func NewSSHTunnel(ctx context.Context, sshPort, sshKey string, v1Core typed_core.CoreV1Interface) *SSHTunnel {
48+
func NewSSHTunnel(ctx context.Context, sshPort, sshKey string, v1Core typed_core.CoreV1Interface, v1Networking typed_networking.NetworkingV1Interface) *SSHTunnel {
4649
return &SSHTunnel{
4750
ctx: ctx,
4851
sshPort: sshPort,
4952
sshKey: sshKey,
5053
v1Core: v1Core,
5154
LoadBalancerEmulator: tunnel.NewLoadBalancerEmulator(v1Core),
55+
v1Networking: v1Networking,
5256
conns: make(map[string]*sshConn),
5357
connsToStop: make(map[string]*sshConn),
5458
}
@@ -73,6 +77,11 @@ func (t *SSHTunnel) Start() error {
7377
klog.Errorf("error listing services: %v", err)
7478
}
7579

80+
ingresses, err := t.v1Networking.Ingresses("").List(context.Background(), metav1.ListOptions{})
81+
if err != nil {
82+
klog.Errorf("error listing ingresses: %v", err)
83+
}
84+
7685
t.markConnectionsToBeStopped()
7786

7887
for _, svc := range services.Items {
@@ -81,6 +90,10 @@ func (t *SSHTunnel) Start() error {
8190
}
8291
}
8392

93+
for _, ingress := range ingresses.Items {
94+
t.startConnectionIngress(ingress)
95+
}
96+
8497
t.stopMarkedConnections()
8598

8699
// TODO: which time to use?
@@ -104,8 +117,14 @@ func (t *SSHTunnel) startConnection(svc v1.Service) {
104117
return
105118
}
106119

120+
resourcePorts := []int32{}
121+
122+
for _, port := range svc.Spec.Ports {
123+
resourcePorts = append(resourcePorts, port.Port)
124+
}
125+
107126
// create new ssh conn
108-
newSSHConn := createSSHConn(uniqName, t.sshPort, t.sshKey, &svc)
127+
newSSHConn := createSSHConn(uniqName, t.sshPort, t.sshKey, resourcePorts, svc.Spec.ClusterIP, svc.Name)
109128
t.conns[newSSHConn.name] = newSSHConn
110129

111130
go func() {
@@ -121,6 +140,31 @@ func (t *SSHTunnel) startConnection(svc v1.Service) {
121140
}
122141
}
123142

143+
func (t *SSHTunnel) startConnectionIngress(ingress v1_networking.Ingress) {
144+
uniqName := sshConnUniqNameIngress(ingress)
145+
existingSSHConn, ok := t.conns[uniqName]
146+
147+
if ok {
148+
// if the svc still exist we remove the conn from the stopping list
149+
delete(t.connsToStop, existingSSHConn.name)
150+
return
151+
}
152+
153+
resourcePorts := []int32{80, 443}
154+
resourceIP := "127.0.0.1"
155+
156+
// create new ssh conn
157+
newSSHConn := createSSHConn(uniqName, t.sshPort, t.sshKey, resourcePorts, resourceIP, ingress.Name)
158+
t.conns[newSSHConn.name] = newSSHConn
159+
160+
go func() {
161+
err := newSSHConn.startAndWait()
162+
if err != nil {
163+
klog.Errorf("error starting ssh tunnel: %v", err)
164+
}
165+
}()
166+
}
167+
124168
func (t *SSHTunnel) stopActiveConnections() {
125169
for _, conn := range t.conns {
126170
err := conn.stop()
@@ -157,3 +201,13 @@ func sshConnUniqName(service v1.Service) string {
157201

158202
return strings.Join(n, "")
159203
}
204+
205+
func sshConnUniqNameIngress(ingress v1_networking.Ingress) string {
206+
n := []string{ingress.Name}
207+
208+
for _, rule := range ingress.Spec.Rules {
209+
n = append(n, rule.Host)
210+
}
211+
212+
return strings.Join(n, "")
213+
}

test/integration/addons_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"os/exec"
3030
"path/filepath"
3131
"reflect"
32-
"runtime"
3332
"strings"
3433
"testing"
3534
"time"
@@ -63,7 +62,7 @@ func TestAddons(t *testing.T) {
6362
}
6463

6564
args := append([]string{"start", "-p", profile, "--wait=true", "--memory=4000", "--alsologtostderr", "--addons=registry", "--addons=metrics-server", "--addons=olm", "--addons=volumesnapshots", "--addons=csi-hostpath-driver"}, StartArgs()...)
66-
if !NoneDriver() && !(runtime.GOOS == "darwin" && KicDriver()) { // none driver and macos docker driver does not support ingress
65+
if !NoneDriver() { // none driver and macos docker driver does not support ingress
6766
args = append(args, "--addons=ingress")
6867
}
6968
if !arm64Platform() {
@@ -143,7 +142,7 @@ func TestAddons(t *testing.T) {
143142
// validateIngressAddon tests the ingress addon by deploying a default nginx pod
144143
func validateIngressAddon(ctx context.Context, t *testing.T, profile string) {
145144
defer PostMortemLogs(t, profile)
146-
if NoneDriver() || (runtime.GOOS == "darwin" && KicDriver()) {
145+
if NoneDriver() {
147146
t.Skipf("skipping: ingress not supported ")
148147
}
149148

0 commit comments

Comments
 (0)