Commit 8fe99f1e authored by Christopher Harm's avatar Christopher Harm

Fixing minikube ingress configurations

parent 24c4809a
Pipeline #92369 passed with stages
in 1 minute and 10 seconds
......@@ -20,7 +20,6 @@ import (
"runtime"
"git.psu.edu/k8s/devtool/config"
"git.psu.edu/k8s/devtool/environment"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
......@@ -78,15 +77,7 @@ func init() {
func openBrowser(config config.Config) error {
color.Blue("Launching the Application")
var host string
if minikubeProvider() {
output := environment.RunAndGetOutputRequired("minikube", "ip")
host = output[0]
} else if kindProvider() {
host = "localhost"
}
url := fmt.Sprintf("http://%s%s", host, config.OpenUrlPath)
url := fmt.Sprintf("http://kubernetes.local%s", config.OpenUrlPath)
fmt.Printf("Opening Browser: %s\n", url)
err := open(url)
......
......@@ -22,6 +22,7 @@ import (
"log"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"time"
......@@ -178,7 +179,7 @@ func start() {
}
defer os.Remove(file.Name())
pkger.Include("/templates/kind-config.yaml")
_ = pkger.Include("/templates/kind-config.yaml")
kindConfigTemplate, err := readPkgedFile("/templates/kind-config.yaml")
if err != nil {
color.New(color.FgRed).Printf("Error reading kind template file: %v\n", err)
......@@ -246,9 +247,13 @@ func start() {
if minikubeProvider() {
environment.RunRequired(true, "minikube", "addons", "enable", "ingress")
applyMinikubeIngressConfig()
}
setupHostsFile()
err := setupHostsFile()
if err != nil {
color.New(color.FgRed).Printf("Failed to setup hosts file: %v\n", err)
}
}
......@@ -450,7 +455,7 @@ func checkIfNginxIngressInstalled() {
}
defer os.Remove(file.Name())
pkger.Include("/templates/nginx-ingress-values.yaml")
_ = pkger.Include("/templates/nginx-ingress-values.yaml")
nginxConfig, err := readPkgedFile("/templates/nginx-ingress-values.yaml")
if err != nil {
color.New(color.FgRed).Printf("Error reading nginx ingress values file: %v", err)
......@@ -472,6 +477,31 @@ func checkIfNginxIngressInstalled() {
}
}
func applyMinikubeIngressConfig() {
color.Blue("Applying minikube ingress configuration.")
file, err := ioutil.TempFile("/tmp", "devtool")
if err != nil {
log.Fatal(err)
}
defer os.Remove(file.Name())
_ = pkger.Include("/templates/minikube-ingress-cm.yaml")
nginxConfig, err := readPkgedFile("/templates/minikube-ingress-cm.yaml")
if err != nil {
color.New(color.FgRed).Printf("Error reading nginx ingress values file: %v", err)
return
}
_, err = file.WriteString(nginxConfig)
if err != nil {
color.New(color.FgRed).Printf("Failed to write nginx values file: %v", err)
}
environment.RunRequired(true, "kubectl", "apply", "-f", file.Name())
}
func helmReleaseInstalled(releaseName string) bool {
var helmReleases []string
if helmVersion2() {
......@@ -519,20 +549,27 @@ func setupHostsFile() error {
var ip string
if minikubeProvider() {
output := environment.RunAndGetOutputRequired("minikube", "ip")
ip = output[0]
output := environment.RunAndGetOutputRequired("minikube", "service", "swagger-ui", "--url")
url := output[0]
urlPattern := regexp.MustCompile(`^http:\/\/([\w.-]+):([\d]+)$`)
urlParts := urlPattern.FindStringSubmatch(url)
ip = urlParts[1]
} else if kindProvider() {
ip = "127.0.0.1"
}
color.New(color.FgGreen).Printf("Cluster Ingress is at: 'http://%s'\n", ip)
if !hostsfile.Has(ip, "kubernetes.local") {
if hostsfile.HasHostname("kubernetes.local") {
color.Red("host ip address has changed. Please clean up your /etc/hosts file")
return fmt.Errorf("host ip address has changed. Please clean up your /etc/hosts file")
color.Red("ACTION REQUIRED: host ip address has changed. Please clean up your /etc/hosts file")
color.New(color.FgRed).Printf("\tKubernetes entry: \"%s kubernetes.local\"\n", ip)
}
color.Red("ACTION REQUIRED: Please modify your /etc/hosts file!")
color.New(color.FgRed).Printf("\tRun: 'echo \"%s kubernetes.local\" | sudo tee -a /etc/hosts'\n", ip)
} else {
color.Green("/etc/hosts file is configured correctly.")
}
return nil
......
This diff is collapsed.
apiVersion: v1
kind: ConfigMap
data:
enable-opentracing: "true"
zipkin-collector-host: zipkin.default.svc.cluster.local
hsts: "false"
map-hash-bucket-size: "128"
metadata:
name: nginx-load-balancer-conf
namespace: kube-system
......@@ -16,5 +16,4 @@ controller:
useHostPort: true
config:
enable-opentracing: "true"
zipkin-collector-host: "oc-collector.monitoring"
use-forwarded-headers: "true"
zipkin-collector-host: "zipkin.default.svc.cluster.local"
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment