Skip to content

Commit

Permalink
Merge pull request #818 from aaron-prindle/heapster-addon
Browse files Browse the repository at this point in the history
Added heapster to set of addons
  • Loading branch information
aaron-prindle committed Nov 21, 2016
2 parents dd5bd7b + 3fe4ef3 commit 41998bd
Show file tree
Hide file tree
Showing 20 changed files with 600 additions and 118 deletions.
6 changes: 6 additions & 0 deletions cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ var settings = []Setting{
validations: []setFn{IsValidAddon},
callbacks: []setFn{EnableOrDisableAddon},
},
{
name: "heapster",
set: SetBool,
validations: []setFn{IsValidAddon},
callbacks: []setFn{EnableOrDisableAddon},
},
}

var ConfigCmd = &cobra.Command{
Expand Down
117 changes: 117 additions & 0 deletions cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import (
"fmt"
"os"
"text/template"
"time"

"github.com/docker/machine/libmachine"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/util"
)

var (
namespace string
https bool
addonsURLMode bool
addonsURLFormat string
addonsURLTemplate *template.Template
)

const defaultAddonsFormatTemplate = "http://{{.IP}}:{{.Port}}"

var addonsOpenCmd = &cobra.Command{
Use: "open ADDON_NAME",
Short: "Opens the addon w/ADDON_NAME within minikube (example: minikube addons open dashboard). For a list of available addons use: minikube addons list ",
Long: "Opens the addon w/ADDON_NAME within minikube (example: minikube addons open dashboard). For a list of available addons use: minikube addons list ",
PreRun: func(cmd *cobra.Command, args []string) {
t, err := template.New("addonsURL").Parse(addonsURLFormat)
if err != nil {
fmt.Fprintln(os.Stderr, "The value passed to --format is invalid:\n\n", err)
os.Exit(1)
}
addonsURLTemplate = t
},
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "usage: minikube addons open ADDON_NAME")
os.Exit(1)
}
addonName := args[0]
api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
defer api.Close()

cluster.EnsureMinikubeRunningOrExit(api, 1)
addon, ok := assets.Addons[addonName] // validate addon input
if !ok {
fmt.Fprintln(os.Stderr, fmt.Sprintf(`addon '%s' is not a valid addon packaged with minikube.
To see the list of available addons run:
minikube addons list`, addonName))
os.Exit(1)
}
ok, err := addon.IsEnabled()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
if !ok {
fmt.Fprintln(os.Stderr, fmt.Sprintf(`addon '%s' is currently not enabled.
To enable this addon run:
minikube addons enable %s`, addonName, addonName))
os.Exit(1)
}

namespace := "kube-system"
key := "kubernetes.io/minikube-addons-endpoint"
if err := util.RetryAfter(20,
func() error {
_, err := cluster.GetServiceListByLabel(namespace, key, addonName)
if err != nil {
return err
}
return nil
}, 6*time.Second); err != nil {
fmt.Fprintf(os.Stderr, "Could not find endpoint for addon %s: %s\n", addonName, err)
os.Exit(1)
}
serviceList, err := cluster.GetServiceListByLabel(namespace, key, addonName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting service with namespace :%s and labels %s:%s: %s", namespace, key, addonName, err)
os.Exit(1)
}
for i := range serviceList.Items {
service := serviceList.Items[i].ObjectMeta.Name
cluster.WaitAndMaybeOpenService(api, namespace, service, addonsURLTemplate, addonsURLMode, https)

}
},
}

func init() {
AddonsCmd.AddCommand(addonsOpenCmd)
addonsOpenCmd.Flags().BoolVar(&addonsURLMode, "url", false, "Display the kubernetes addons URL in the CLI instead of opening it in the default browser")
addonsOpenCmd.Flags().BoolVar(&https, "https", false, "Open the addons URL with https instead of http")

addonsOpenCmd.PersistentFlags().StringVar(&addonsURLFormat, "format", defaultAddonsFormatTemplate, "Format to output addons URL in. This format will be applied to each url individually and they will be printed one at a time.")
AddonsCmd.AddCommand(addonsOpenCmd)
}
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var dashboardCmd = &cobra.Command{
namespace := "kube-system"
service := "kubernetes-dashboard"

if err := commonutil.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil {
if err := commonutil.RetryAfter(20, func() error { return cluster.CheckService(namespace, service) }, 6*time.Second); err != nil {
fmt.Fprintf(os.Stderr, "Could not find finalized endpoint being pointed to by %s: %s\n", service, err)
os.Exit(1)
}
Expand Down
64 changes: 2 additions & 62 deletions cmd/minikube/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ package cmd
import (
"fmt"
"os"
"strings"
"text/template"
"time"

"github.com/docker/machine/libmachine"
"github.com/pkg/browser"
"github.com/pkg/errors"
"github.com/spf13/cobra"
kubeapi "k8s.io/kubernetes/pkg/api"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/util"
)

var (
Expand All @@ -46,7 +41,7 @@ var serviceCmd = &cobra.Command{
Use: "service [flags] SERVICE",
Short: "Gets the kubernetes URL(s) for the specified service in your local cluster",
Long: `Gets the kubernetes URL(s) for the specified service in your local cluster. In the case of multiple URLs they will be printed one at a time`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PreRun: func(cmd *cobra.Command, args []string) {
t, err := template.New("serviceURL").Parse(serviceURLFormat)
if err != nil {
fmt.Fprintln(os.Stderr, "The value passed to --format is invalid:\n\n", err)
Expand All @@ -71,28 +66,7 @@ var serviceCmd = &cobra.Command{
service, namespace))
os.Exit(1)
}
if err := util.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil {
fmt.Fprintf(os.Stderr, "Could not find finalized endpoint being pointed to by %s: %s\n", service, err)
os.Exit(1)
}

urls, err := cluster.GetServiceURLsForService(api, namespace, service, serviceURLTemplate)
if err != nil {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, "Check that minikube is running and that you have specified the correct namespace (-n flag).")
os.Exit(1)
}
for _, url := range urls {
if https {
url = strings.Replace(url, "http", "https", 1)
}
if serviceURLMode || !strings.HasPrefix(url, "http") {
fmt.Fprintln(os.Stdout, url)
} else {
fmt.Fprintln(os.Stdout, "Opening kubernetes service "+namespace+"/"+service+" in default browser...")
browser.OpenURL(url)
}
}
cluster.WaitAndMaybeOpenService(api, namespace, service, serviceURLTemplate, serviceURLMode, https)
},
}

Expand All @@ -119,37 +93,3 @@ func validateService(namespace string, service string) error {
}
return nil
}

// CheckService waits for the specified service to be ready by returning an error until the service is up
// The check is done by polling the endpoint associated with the service and when the endpoint exists, returning no error->service-online
func CheckService(namespace string, service string) error {
client, err := cluster.GetKubernetesClient()
if err != nil {
return &util.RetriableError{Err: err}
}
endpoints := client.Endpoints(namespace)
if err != nil {
return &util.RetriableError{Err: err}
}
endpoint, err := endpoints.Get(service)
if err != nil {
return &util.RetriableError{Err: err}
}
return CheckEndpointReady(endpoint)
}

const notReadyMsg = "Waiting, endpoint for service is not ready yet...\n"

func CheckEndpointReady(endpoint *kubeapi.Endpoints) error {
if len(endpoint.Subsets) == 0 {
fmt.Fprintf(os.Stderr, notReadyMsg)
return &util.RetriableError{Err: errors.New("Endpoint for service is not ready yet")}
}
for _, subset := range endpoint.Subsets {
if len(subset.Addresses) == 0 {
fmt.Fprintf(os.Stderr, notReadyMsg)
return &util.RetriableError{Err: errors.New("No endpoints for service are ready yet")}
}
}
return nil
}
55 changes: 0 additions & 55 deletions cmd/minikube/cmd/service_test.go

This file was deleted.

1 change: 1 addition & 0 deletions deploy/addons/addon-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ metadata:
labels:
component: kube-addon-manager
version: v5.1
kubernetes.io/minikube-addons: addon-manager
spec:
hostNetwork: true
containers:
Expand Down
1 change: 1 addition & 0 deletions deploy/addons/dashboard-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ metadata:
app: kubernetes-dashboard
version: v1.4.2
kubernetes.io/cluster-service: "true"
kubernetes.io/minikube-addons: dashboard
spec:
replicas: 1
selector:
Expand Down
2 changes: 2 additions & 0 deletions deploy/addons/dashboard-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ metadata:
labels:
app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
kubernetes.io/minikube-addons: dashboard
kubernetes.io/minikube-addons-endpoint: dashboard
spec:
type: NodePort
ports:
Expand Down
18 changes: 18 additions & 0 deletions deploy/addons/grafana-svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
labels:
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: monitoring-grafana
kubernetes.io/minikube-addons: heapster
kubernetes.io/minikube-addons-endpoint: heapster
name: monitoring-grafana
namespace: kube-system
spec:
type: NodePort
ports:
- port: 80
targetPort: 3000
selector:
kubernetes.io/cluster-service: "true"
name: influxGrafana
38 changes: 38 additions & 0 deletions deploy/addons/heapster-rc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: ReplicationController
metadata:
labels:
kubernetes.io/cluster-service: 'true'
k8s-app: heapster
name: heapster
kubernetes.io/minikube-addons: heapster
name: heapster
namespace: kube-system
spec:
replicas: 1
selector:
kubernetes.io/cluster-service: "true"
k8s-app: heapster
template:
metadata:
labels:
kubernetes.io/cluster-service: 'true'
k8s-app: heapster
spec:
containers:
- name: heapster
image: gcr.io/google_containers/heapster:v1.2.0
imagePullPolicy: IfNotPresent
command:
- /heapster
- --source=kubernetes
- --sink=influxdb:http://monitoring-influxdb:8086
- --metric_resolution=60s
volumeMounts:
- name: ssl-certs
mountPath: /etc/ssl/certs
readOnly: true
volumes:
- name: ssl-certs
hostPath:
path: /etc/ssl/certs
16 changes: 16 additions & 0 deletions deploy/addons/heapster-svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
labels:
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: heapster
kubernetes.io/minikube-addons: heapster
name: heapster
namespace: kube-system
spec:
ports:
- port: 80
targetPort: 8082
selector:
kubernetes.io/cluster-service: "true"
k8s-app: heapster
Loading

0 comments on commit 41998bd

Please sign in to comment.