Create creates a new chart in a directory. Inside of dir, this will create a directory based on the name of chartfile.Name. It will then write the Chart.yaml into this directory and create the (empty) appropriate directories. The returned string will point to the newly created directory. It will b
(name, dir string)
| 701 | // error. In such a case, this will attempt to clean up by removing the |
| 702 | // new chart directory. |
| 703 | func Create(name, dir string) (string, error) { |
| 704 | |
| 705 | // Sanity-check the name of a chart so user doesn't create one that causes problems. |
| 706 | if err := validateChartName(name); err != nil { |
| 707 | return "", err |
| 708 | } |
| 709 | |
| 710 | path, err := filepath.Abs(dir) |
| 711 | if err != nil { |
| 712 | return path, err |
| 713 | } |
| 714 | |
| 715 | if fi, err := os.Stat(path); err != nil { |
| 716 | return path, err |
| 717 | } else if !fi.IsDir() { |
| 718 | return path, fmt.Errorf("no such directory %s", path) |
| 719 | } |
| 720 | |
| 721 | cdir := filepath.Join(path, name) |
| 722 | if fi, err := os.Stat(cdir); err == nil && !fi.IsDir() { |
| 723 | return cdir, fmt.Errorf("file %s already exists and is not a directory", cdir) |
| 724 | } |
| 725 | |
| 726 | // Note: If adding a new template below (i.e., to `helm create`) which is disabled by default (similar to hpa and |
| 727 | // ingress below); or making an existing template disabled by default, add the enabling condition in |
| 728 | // `TestHelmCreateChart_CheckDeprecatedWarnings` in `pkg/lint/lint_test.go` to make it run through deprecation checks |
| 729 | // with latest Kubernetes version. |
| 730 | files := []struct { |
| 731 | path string |
| 732 | content []byte |
| 733 | }{ |
| 734 | { |
| 735 | // Chart.yaml |
| 736 | path: filepath.Join(cdir, ChartfileName), |
| 737 | content: fmt.Appendf(nil, defaultChartfile, name), |
| 738 | }, |
| 739 | { |
| 740 | // values.yaml |
| 741 | path: filepath.Join(cdir, ValuesfileName), |
| 742 | content: fmt.Appendf(nil, defaultValues, name), |
| 743 | }, |
| 744 | { |
| 745 | // .helmignore |
| 746 | path: filepath.Join(cdir, IgnorefileName), |
| 747 | content: []byte(defaultIgnore), |
| 748 | }, |
| 749 | { |
| 750 | // ingress.yaml |
| 751 | path: filepath.Join(cdir, IngressFileName), |
| 752 | content: transform(defaultIngress, name), |
| 753 | }, |
| 754 | { |
| 755 | // httproute.yaml |
| 756 | path: filepath.Join(cdir, HTTPRouteFileName), |
| 757 | content: transform(defaultHTTPRoute, name), |
| 758 | }, |
| 759 | { |
| 760 | // deployment.yaml |
searching dependent graphs…