Exemple #1
0
func packDir(dir string) (string, error) {
	c, err := chart.LoadDir(dir)
	if err != nil {
		return "", fmt.Errorf("Failed to load %s: %s", dir, err)
	}

	return chart.Save(c, ".")
}
Exemple #2
0
func doUpload(filename, cname string, cxt *cli.Context) (string, error) {

	fi, err := os.Stat(filename)
	if err != nil {
		return "", err
	}

	if fi.IsDir() {
		format.Info("Chart is directory")
		c, err := chart.LoadDir(filename)
		if err != nil {
			return "", err
		}
		if cname == "" {
			cname = genName(c.Chartfile().Name)
		}

		// TODO: Is it better to generate the file in temp dir like this, or
		// just put it in the CWD?
		//tdir, err := ioutil.TempDir("", "helm-")
		//if err != nil {
		//format.Warn("Could not create temporary directory. Using .")
		//tdir = "."
		//} else {
		//defer os.RemoveAll(tdir)
		//}
		tdir := "."
		tfile, err := chart.Save(c, tdir)
		if err != nil {
			return "", err
		}
		filename = tfile
	} else if cname == "" {
		n, _, e := parseTarName(filename)
		if e != nil {
			return "", e
		}
		cname = n
	}

	// TODO: Add a version build metadata on the chart.

	if cxt.Bool("dry-run") {
		format.Info("Prepared deploy %q using file %q", cname, filename)
		return "", nil
	}

	c := NewClient(cxt)
	return c.PostChart(filename, cname)
}
Exemple #3
0
func TestReplicatedService(t *testing.T) {
	replicatedService, err := chart.LoadDir("../../../examples/charts/replicatedservice")
	if err != nil {
		t.Fatal(err)
	}
	replicatedServiceContent, err := replicatedService.LoadContent()
	if err != nil {
		t.Fatal(err)
	}
	testExpansion(
		t,
		&expansion.ServiceRequest{
			ChartInvocation: &common.Resource{
				Name: "test_invocation",
				Type: "gs://kubernetes-charts-testing/replicatedservice-1.2.3.tgz",
				Properties: map[string]interface{}{
					"image":          "myimage",
					"container_port": 1234,
					"replicas":       3,
				},
			},
			Chart: replicatedServiceContent,
		},
		&expansion.ServiceResponse{
			Resources: []interface{}{
				map[string]interface{}{
					"name": "test_invocation-rc",
					"properties": map[string]interface{}{
						"apiVersion": "v1",
						"kind":       "ReplicationController",
						"metadata": map[string]interface{}{
							"labels": map[string]interface{}{
								"name": "test_invocation-rc",
							},
							"name":      "test_invocation-rc",
							"namespace": "default",
						},
						"spec": map[string]interface{}{
							"replicas": 3.0,
							"selector": map[string]interface{}{
								"name": "test_invocation",
							},
							"template": map[string]interface{}{
								"metadata": map[string]interface{}{
									"labels": map[string]interface{}{
										"name": "test_invocation",
									},
								},
								"spec": map[string]interface{}{
									"containers": []interface{}{
										map[string]interface{}{
											"env":   []interface{}{},
											"image": "myimage",
											"name":  "test_invocation",
											"ports": []interface{}{
												map[string]interface{}{
													"containerPort": 1234.0,
													"name":          "test_invocation",
												},
											},
										},
									},
								},
							},
						},
					},
					"type": "ReplicationController",
				},
				map[string]interface{}{
					"name": "test_invocation-service",
					"properties": map[string]interface{}{
						"apiVersion": "v1",
						"kind":       "Service",
						"metadata": map[string]interface{}{
							"labels": map[string]interface{}{
								"name": "test_invocation-service",
							},
							"name":      "test_invocation-service",
							"namespace": "default",
						},
						"spec": map[string]interface{}{
							"ports": []interface{}{
								map[string]interface{}{
									"name":       "test_invocation",
									"port":       1234.0,
									"targetPort": 1234.0,
								},
							},
							"selector": map[string]interface{}{
								"name": "test_invocation",
							},
						},
					},
					"type": "Service",
				},
			},
		},
		"", // Error.
	)
}