Ejemplo n.º 1
0
// Install uses kubernetes client to install tiller
//
// Returns the string output received from the operation, and an error if the
// command failed.
//
// If verbose is true, this will print the manifest to stdout.
func Install(namespace, image string, verbose bool) error {
	kc := kube.New(nil)

	if namespace == "" {
		ns, _, err := kc.DefaultNamespace()
		if err != nil {
			return err
		}
		namespace = ns
	}

	var b bytes.Buffer

	// Add main install YAML
	istpl := template.New("install").Funcs(sprig.TxtFuncMap())

	cfg := struct {
		Namespace, Image string
	}{namespace, image}

	if err := template.Must(istpl.Parse(InstallYAML)).Execute(&b, cfg); err != nil {
		return err
	}

	if verbose {
		fmt.Println(b.String())
	}

	return kc.Create(namespace, &b)
}
Ejemplo n.º 2
0
// Install uses kubernetes client to install tiller
//
// Returns the string output received from the operation, and an error if the
// command failed.
//
// If verbose is true, this will print the manifest to stdout.
func Install(namespace, image string, verbose bool) error {
	kc := kube.New(nil)

	if namespace == "" {
		ns, _, err := kc.DefaultNamespace()
		if err != nil {
			return err
		}
		namespace = ns
	}

	c, err := kc.Client()
	if err != nil {
		return err
	}

	ns := generateNamespace(namespace)
	if _, err := c.Namespaces().Create(ns); err != nil {
		if !errors.IsAlreadyExists(err) {
			return err
		}
	}

	if image == "" {
		// strip git sha off version
		tag := strings.Split(version.Version, "+")[0]
		image = fmt.Sprintf("%s:%s", defaultImage, tag)
	}

	rc := generateDeployment(image)

	_, err = c.Deployments(namespace).Create(rc)
	return err
}
Ejemplo n.º 3
0
func start(c *cobra.Command, args []string) {
	clientset, err := kube.New(nil).ClientSet()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Cannot initialize Kubernetes connection: %s", err)
	}

	switch store {
	case storageMemory:
		env.Releases = storage.Init(driver.NewMemory())
	case storageConfigMap:
		env.Releases = storage.Init(driver.NewConfigMaps(clientset.Core().ConfigMaps(namespace())))
	}

	lstn, err := net.Listen("tcp", grpcAddr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Server died: %s\n", err)
		os.Exit(1)
	}

	fmt.Printf("Tiller is listening on %s\n", grpcAddr)
	fmt.Printf("Probes server is listening on %s\n", probeAddr)
	fmt.Printf("Storage driver is %s\n", env.Releases.Name())

	if enableTracing {
		startTracing(traceAddr)
	}

	srvErrCh := make(chan error)
	probeErrCh := make(chan error)
	go func() {
		svc := tiller.NewReleaseServer(env, clientset)
		services.RegisterReleaseServiceServer(rootServer, svc)
		if err := rootServer.Serve(lstn); err != nil {
			srvErrCh <- err
		}
	}()

	go func() {
		mux := newProbesMux()
		if err := http.ListenAndServe(probeAddr, mux); err != nil {
			probeErrCh <- err
		}
	}()

	select {
	case err := <-srvErrCh:
		fmt.Fprintf(os.Stderr, "Server died: %s\n", err)
		os.Exit(1)
	case err := <-probeErrCh:
		fmt.Fprintf(os.Stderr, "Probes server died: %s\n", err)
	}
}
Ejemplo n.º 4
0
// New returns an environment initialized with the defaults.
func New() *Environment {
	e := engine.New()
	var ey EngineYard = map[string]Engine{
		// Currently, the only template engine we support is the GoTpl one. But
		// we can easily add some here.
		GoTplEngine: e,
	}

	return &Environment{
		EngineYard: ey,
		Releases:   storage.Init(driver.NewMemory()),
		KubeClient: kube.New(nil),
	}
}
Ejemplo n.º 5
0
func newTillerPortForwarder(namespace string) (*kube.Tunnel, error) {
	kc := kube.New(nil)
	client, err := kc.Client()
	if err != nil {
		return nil, err
	}

	podName, err := getTillerPodName(client, namespace)
	if err != nil {
		return nil, err
	}
	const tillerPort = 44134
	return kc.ForwardPort(namespace, podName, tillerPort)
}
Ejemplo n.º 6
0
// New returns an environment initialized with the defaults.
func New() *Environment {
	e := engine.New()
	var ey EngineYard = map[string]Engine{
		// Currently, the only template engine we support is the GoTpl one. But
		// we can easily add some here.
		GoTplEngine: e,
	}
	return &Environment{
		Namespace:  DefaultNamespace,
		EngineYard: ey,
		Releases:   storage.NewMemory(),
		KubeClient: kube.New(nil), //&PrintingKubeClient{Out: os.Stdout},
	}
}
Ejemplo n.º 7
0
func getTillerPodName(namespace string) (string, error) {
	client, err := kube.New(nil).Client()
	if err != nil {
		return "", err
	}

	// TODO use a const for labels
	selector := labels.Set{"app": "helm", "name": "tiller"}.AsSelector()
	options := api.ListOptions{LabelSelector: selector}
	pods, err := client.Pods(namespace).List(options)
	if err != nil {
		return "", err
	}
	if len(pods.Items) < 1 {
		return "", fmt.Errorf("I could not find tiller")
	}
	return pods.Items[0].ObjectMeta.GetName(), nil
}
Ejemplo n.º 8
0
func newTillerPortForwarder(namespace string) (*kube.Tunnel, error) {
	kc := kube.New(nil)

	if namespace == "" {
		ns, _, err := kc.DefaultNamespace()
		if err != nil {
			return nil, err
		}
		namespace = ns
	}

	podName, err := getTillerPodName(namespace)
	if err != nil {
		return nil, err
	}
	// FIXME use a constain that is accessible on init
	const tillerPort = 44134
	return kc.ForwardPort(namespace, podName, tillerPort)
}