From d94707db861df3fe5b4747810d07ee16b3dd0a05 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 8 Jan 2019 13:37:55 -0800 Subject: [PATCH] ref(*): remove helmVersion chart constraint * Remove helmVersion constraint from charts * Guard compile time set variables behind `internal/` * Allow configuration of UserAgent for HTTPGetter Signed-off-by: Adam Reese --- Makefile | 8 +-- cmd/helm/version.go | 6 +- docs/chart_best_practices/conventions.md | 18 ----- docs/chart_template_guide/builtin_objects.md | 1 - docs/charts.md | 3 +- internal/version/version.go | 56 +++++++++++++++ pkg/action/action.go | 21 ++---- pkg/action/install.go | 12 +--- pkg/chart/metadata.go | 3 - pkg/chartutil/capabilities.go | 6 -- pkg/chartutil/values_test.go | 5 -- pkg/downloader/chart_downloader.go | 4 +- pkg/getter/httpgetter.go | 38 +++++----- pkg/getter/httpgetter_test.go | 4 +- .../testdata/albatross/templates/svc.yaml | 1 - pkg/repo/chartrepo.go | 1 + pkg/tiller/release_install.go | 2 +- pkg/tiller/release_server.go | 72 ++++++++----------- pkg/tiller/release_server_test.go | 16 +---- pkg/tiller/release_uninstall.go | 4 +- pkg/tiller/release_update.go | 2 +- pkg/version/version.go | 35 --------- pkg/version/version_test.go | 45 ------------ 23 files changed, 133 insertions(+), 230 deletions(-) create mode 100644 internal/version/version.go delete mode 100644 pkg/version/version_test.go diff --git a/Makefile b/Makefile index ff074becb..7ab2e485b 100644 --- a/Makefile +++ b/Makefile @@ -31,15 +31,15 @@ BINARY_VERSION ?= ${GIT_TAG} # Only set Version if building a tag or VERSION is set ifneq ($(BINARY_VERSION),) - LDFLAGS += -X k8s.io/helm/pkg/version.version=${BINARY_VERSION} + LDFLAGS += -X k8s.io/helm/internal/version.version=${BINARY_VERSION} endif # Clear the "unreleased" string in BuildMetadata ifneq ($(GIT_TAG),) - LDFLAGS += -X k8s.io/helm/pkg/version.metadata= + LDFLAGS += -X k8s.io/helm/internal/version.metadata= endif -LDFLAGS += -X k8s.io/helm/pkg/version.gitCommit=${GIT_COMMIT} -LDFLAGS += -X k8s.io/helm/pkg/version.gitTreeState=${GIT_DIRTY} +LDFLAGS += -X k8s.io/helm/internal/version.gitCommit=${GIT_COMMIT} +LDFLAGS += -X k8s.io/helm/internal/version.gitTreeState=${GIT_DIRTY} .PHONY: all all: build diff --git a/cmd/helm/version.go b/cmd/helm/version.go index 4b895bf06..9bf2761a1 100644 --- a/cmd/helm/version.go +++ b/cmd/helm/version.go @@ -24,7 +24,7 @@ import ( "github.com/spf13/cobra" "k8s.io/helm/cmd/helm/require" - "k8s.io/helm/pkg/version" + "k8s.io/helm/internal/version" ) const versionDesc = ` @@ -71,14 +71,14 @@ func (o *versionOptions) run(out io.Writer) error { if err != nil { return err } - return tt.Execute(out, version.GetBuildInfo()) + return tt.Execute(out, version.Get()) } fmt.Fprintln(out, formatVersion(o.short)) return nil } func formatVersion(short bool) string { - v := version.GetBuildInfo() + v := version.Get() if short { return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7]) } diff --git a/docs/chart_best_practices/conventions.md b/docs/chart_best_practices/conventions.md index 55624a558..c295725b1 100644 --- a/docs/chart_best_practices/conventions.md +++ b/docs/chart_best_practices/conventions.md @@ -37,21 +37,3 @@ There are a few small conventions followed for using the words Helm and helm. - The term 'chart' does not need to be capitalized, as it is not a proper noun. When in doubt, use _Helm_ (with an uppercase 'H'). - -## Restricting Helm by Version - -A `Chart.yaml` file can specify a `helmVersion` SemVer constraint: - -```yaml -name: mychart -version: 0.2.0 -helmVersion: ">=2.4.0" -``` - -This constraint should be set when templates use a new feature that was not -supported in older versions of Helm. While this parameter will accept sophisticated -SemVer rules, the best practice is to default to the form `>=2.4.0`, where `2.4.0` -is the version that introduced the new feature used in the chart. - -This feature was introduced in Helm 2.4.0, so any version of Helm older than -2.4.0 will simply ignore this field. diff --git a/docs/chart_template_guide/builtin_objects.md b/docs/chart_template_guide/builtin_objects.md index c24fd4b08..570ea73ce 100644 --- a/docs/chart_template_guide/builtin_objects.md +++ b/docs/chart_template_guide/builtin_objects.md @@ -20,7 +20,6 @@ In the previous section, we use `{{.Release.Name}}` to insert the name of a rele - `Capabilities.APIVersions` is a set of versions. - `Capabilities.APIVersions.Has $version` indicates whether a version (`batch/v1`) is enabled on the cluster. - `Capabilities.KubeVersion` provides a way to look up the Kubernetes version. It has the following values: `Major`, `Minor`, `GitVersion`, `GitCommit`, `GitTreeState`, `BuildDate`, `GoVersion`, `Compiler`, and `Platform`. - - `Capabilities.HelmVersion` provides a way to look up the Helm version. It has the following values: `SemVer`, `GitCommit`, and `GitTreeState`. - `Template`: Contains information about the current template that is being executed - `Name`: A namespaced filepath to the current template (e.g. `mychart/templates/mytemplate.yaml`) - `BasePath`: The namespaced path to the templates directory of the current chart (e.g. `mychart/templates`). diff --git a/docs/charts.md b/docs/charts.md index 6c5263c1e..8481d503e 100644 --- a/docs/charts.md +++ b/docs/charts.md @@ -587,8 +587,7 @@ sensitive_. `{{.Files.GetString name}}` functions. You can also access the contents of the file as `[]byte` using `{{.Files.GetBytes}}` - `Capabilities`: A map-like object that contains information about the versions - of Kubernetes (`{{.Capabilities.KubeVersion}}`, Helm - (`{{.Capabilities.HelmVersion}}`, and the supported Kubernetes + of Kubernetes (`{{.Capabilities.KubeVersion}}` and the supported Kubernetes API versions (`{{.Capabilities.APIVersions.Has "batch/v1"`) **NOTE:** Any unknown Chart.yaml fields will be dropped. They will not diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 000000000..9f790a022 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,56 @@ +/* +Copyright The Helm Authors. + +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 version // import "k8s.io/helm/internal/version" + +import ( + hversion "k8s.io/helm/pkg/version" +) + +var ( + // version is the current version of the Helm. + // Update this whenever making a new release. + // The version is of the format Major.Minor.Patch[-Prerelease][+BuildMetadata] + // + // Increment major number for new feature additions and behavioral changes. + // Increment minor number for bug fixes and performance enhancements. + // Increment patch number for critical fixes to existing releases. + version = "v3.0" + + // metadata is extra build time data + metadata = "unreleased" + // gitCommit is the git sha1 + gitCommit = "" + // gitTreeState is the state of the git tree + gitTreeState = "" +) + +// GetVersion returns the semver string of the version +func GetVersion() string { + if metadata == "" { + return version + } + return version + "+" + metadata +} + +// GetBuildInfo returns build info +func Get() hversion.BuildInfo { + return hversion.BuildInfo{ + Version: GetVersion(), + GitCommit: gitCommit, + GitTreeState: gitTreeState, + } +} diff --git a/pkg/action/action.go b/pkg/action/action.go index ad417cc08..7e05ac1b2 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -19,14 +19,12 @@ package action import ( "time" - "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/discovery" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/storage" "k8s.io/helm/pkg/tiller/environment" - "k8s.io/helm/pkg/version" ) // Timestamper is a function capable of producing a timestamp.Timestamper. @@ -45,24 +43,17 @@ type Configuration struct { // KubeClient is a Kubernetes API client. KubeClient environment.KubeClient + Capabilities *chartutil.Capabilities + Log func(string, ...interface{}) } // capabilities builds a Capabilities from discovery information. -func (c *Configuration) capabilities() (*chartutil.Capabilities, error) { - sv, err := c.Discovery.ServerVersion() - if err != nil { - return nil, err - } - vs, err := GetVersionSet(c.Discovery) - if err != nil { - return nil, errors.Wrap(err, "could not get apiVersions from Kubernetes") +func (c *Configuration) capabilities() *chartutil.Capabilities { + if c.Capabilities == nil { + return chartutil.DefaultCapabilities } - return &chartutil.Capabilities{ - APIVersions: vs, - KubeVersion: sv, - HelmVersion: version.GetBuildInfo(), - }, nil + return c.Capabilities } // Now generates a timestamp diff --git a/pkg/action/install.go b/pkg/action/install.go index 2d8a46b4d..e2ddee64a 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -26,6 +26,7 @@ import ( "time" "github.com/pkg/errors" + "k8s.io/helm/pkg/chart" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/engine" @@ -78,10 +79,7 @@ func (i *Install) Run(chrt *chart.Chart, rawValues map[string]interface{}) (*rel return nil, err } - caps, err := i.cfg.capabilities() - if err != nil { - return nil, err - } + caps := i.cfg.capabilities() options := chartutil.ReleaseOptions{ Name: i.ReleaseName, @@ -260,12 +258,6 @@ func (i *Install) replaceRelease(rel *release.Release) error { func (i *Install) renderResources(ch *chart.Chart, values chartutil.Values, vs chartutil.VersionSet) ([]*release.Hook, *bytes.Buffer, string, error) { hooks := []*release.Hook{} buf := bytes.NewBuffer(nil) - // Guard to make sure Helm is at the right version to handle this chart. - sver := version.GetVersion() - if ch.Metadata.HelmVersion != "" && - !version.IsCompatibleRange(ch.Metadata.HelmVersion, sver) { - return hooks, buf, "", errors.Errorf("chart incompatible with Helm %s", sver) - } if ch.Metadata.KubeVersion != "" { cap, _ := values["Capabilities"].(*chartutil.Capabilities) diff --git a/pkg/chart/metadata.go b/pkg/chart/metadata.go index a89e371f2..8541aa965 100644 --- a/pkg/chart/metadata.go +++ b/pkg/chart/metadata.go @@ -57,9 +57,6 @@ type Metadata struct { AppVersion string `json:"appVersion,omitempty"` // Whether or not this chart is deprecated Deprecated bool `json:"deprecated,omitempty"` - // HelmVersion is a SemVer constraints on what version of Helm is required. - // See SemVer ranges here: https://github.com/Masterminds/semver#basic-comparisons - HelmVersion string `json:"helmVersion,omitempty"` // Annotations are additional mappings uninterpreted by Helm, // made available for inspection by other applications. Annotations map[string]string `json:"annotations,omitempty"` diff --git a/pkg/chartutil/capabilities.go b/pkg/chartutil/capabilities.go index 55bdcb653..9fedb2941 100644 --- a/pkg/chartutil/capabilities.go +++ b/pkg/chartutil/capabilities.go @@ -21,8 +21,6 @@ import ( "k8s.io/apimachinery/pkg/version" "k8s.io/client-go/kubernetes/scheme" - - tversion "k8s.io/helm/pkg/version" ) var ( @@ -52,10 +50,6 @@ type Capabilities struct { APIVersions VersionSet // KubeVerison is the Kubernetes version KubeVersion *version.Info - // HelmVersion is the Helm version - // - // This always comes from pkg/version.BuildInfo(). - HelmVersion tversion.BuildInfo } // VersionSet is a set of Kubernetes API versions. diff --git a/pkg/chartutil/values_test.go b/pkg/chartutil/values_test.go index 837c5056b..f397009fc 100644 --- a/pkg/chartutil/values_test.go +++ b/pkg/chartutil/values_test.go @@ -26,7 +26,6 @@ import ( kversion "k8s.io/apimachinery/pkg/version" "k8s.io/helm/pkg/chart" - "k8s.io/helm/pkg/version" ) func TestReadValues(t *testing.T) { @@ -107,7 +106,6 @@ func TestToRenderValues(t *testing.T) { caps := &Capabilities{ APIVersions: DefaultVersionSet, - HelmVersion: version.GetBuildInfo(), KubeVersion: &kversion.Info{Major: "1"}, } @@ -136,9 +134,6 @@ func TestToRenderValues(t *testing.T) { if !res["Capabilities"].(*Capabilities).APIVersions.Has("v1") { t.Error("Expected Capabilities to have v1 as an API") } - if res["Capabilities"].(*Capabilities).HelmVersion.Version == "" { - t.Error("Expected Capabilities to have a Helm version") - } if res["Capabilities"].(*Capabilities).KubeVersion.Major != "1" { t.Error("Expected Capabilities to have a Kube version") } diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index e72f69da4..c390a157e 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -153,7 +153,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, ge } // ResolveChartVersionAndGetRepo is the same as the ResolveChartVersion method, but returns the chart repositoryy. -func (c *ChartDownloader) ResolveChartVersionAndGetRepo(ref, version string) (*url.URL, *repo.ChartRepository, *getter.HttpGetter, error) { +func (c *ChartDownloader) ResolveChartVersionAndGetRepo(ref, version string) (*url.URL, *repo.ChartRepository, *getter.HTTPGetter, error) { u, err := url.Parse(ref) if err != nil { return nil, nil, nil, errors.Errorf("invalid chart URL format: %s", ref) @@ -164,6 +164,7 @@ func (c *ChartDownloader) ResolveChartVersionAndGetRepo(ref, version string) (*u return u, nil, nil, err } + // TODO add user-agent g, err := getter.NewHTTPGetter(ref, "", "", "") if err != nil { return u, nil, nil, err @@ -246,6 +247,7 @@ func (c *ChartDownloader) ResolveChartVersionAndGetRepo(ref, version string) (*u repoURL.Path = strings.TrimSuffix(repoURL.Path, "/") + "/" u = repoURL.ResolveReference(u) u.RawQuery = q.Encode() + // TODO add user-agent g, err := getter.NewHTTPGetter(rc.URL, "", "", "") if err != nil { return repoURL, r, nil, err diff --git a/pkg/getter/httpgetter.go b/pkg/getter/httpgetter.go index ebeb81c8a..84a7d94a6 100644 --- a/pkg/getter/httpgetter.go +++ b/pkg/getter/httpgetter.go @@ -19,35 +19,38 @@ import ( "bytes" "io" "net/http" - "strings" "github.com/pkg/errors" "k8s.io/helm/pkg/tlsutil" "k8s.io/helm/pkg/urlutil" - "k8s.io/helm/pkg/version" ) -//HttpGetter is the efault HTTP(/S) backend handler -// TODO: change the name to HTTPGetter in Helm 3 -type HttpGetter struct { //nolint - client *http.Client - username string - password string +// HTTPGetter is the efault HTTP(/S) backend handler +type HTTPGetter struct { + client *http.Client + username string + password string + userAgent string } -//SetCredentials sets the credentials for the getter -func (g *HttpGetter) SetCredentials(username, password string) { +// SetCredentials sets the credentials for the getter +func (g *HTTPGetter) SetCredentials(username, password string) { g.username = username g.password = password } +// SetUserAgent sets the HTTP User-Agent for the getter +func (g *HTTPGetter) SetUserAgent(userAgent string) { + g.userAgent = userAgent +} + //Get performs a Get from repo.Getter and returns the body. -func (g *HttpGetter) Get(href string) (*bytes.Buffer, error) { +func (g *HTTPGetter) Get(href string) (*bytes.Buffer, error) { return g.get(href) } -func (g *HttpGetter) get(href string) (*bytes.Buffer, error) { +func (g *HTTPGetter) get(href string) (*bytes.Buffer, error) { buf := bytes.NewBuffer(nil) // Set a helm specific user agent so that a repo server and metrics can @@ -56,7 +59,10 @@ func (g *HttpGetter) get(href string) (*bytes.Buffer, error) { if err != nil { return buf, err } - req.Header.Set("User-Agent", "Helm/"+strings.TrimPrefix(version.GetVersion(), "v")) + // req.Header.Set("User-Agent", "Helm/"+strings.TrimPrefix(version.GetVersion(), "v")) + if g.userAgent != "" { + req.Header.Set("User-Agent", g.userAgent) + } if g.username != "" && g.password != "" { req.SetBasicAuth(g.username, g.password) @@ -80,9 +86,9 @@ func newHTTPGetter(URL, CertFile, KeyFile, CAFile string) (Getter, error) { return NewHTTPGetter(URL, CertFile, KeyFile, CAFile) } -// NewHTTPGetter constructs a valid http/https client as HttpGetter -func NewHTTPGetter(URL, CertFile, KeyFile, CAFile string) (*HttpGetter, error) { - var client HttpGetter +// NewHTTPGetter constructs a valid http/https client as HTTPGetter +func NewHTTPGetter(URL, CertFile, KeyFile, CAFile string) (*HTTPGetter, error) { + var client HTTPGetter if CertFile != "" && KeyFile != "" { tlsConf, err := tlsutil.NewClientTLS(CertFile, KeyFile, CAFile) if err != nil { diff --git a/pkg/getter/httpgetter_test.go b/pkg/getter/httpgetter_test.go index 2b8d1a4e9..90bd0612b 100644 --- a/pkg/getter/httpgetter_test.go +++ b/pkg/getter/httpgetter_test.go @@ -27,7 +27,7 @@ func TestHTTPGetter(t *testing.T) { t.Fatal(err) } - if hg, ok := g.(*HttpGetter); !ok { + if hg, ok := g.(*HTTPGetter); !ok { t.Fatal("Expected newHTTPGetter to produce an httpGetter") } else if hg.client != http.DefaultClient { t.Fatal("Expected newHTTPGetter to return a default HTTP client.") @@ -42,7 +42,7 @@ func TestHTTPGetter(t *testing.T) { t.Fatal(err) } - if _, ok := g.(*HttpGetter); !ok { + if _, ok := g.(*HTTPGetter); !ok { t.Fatal("Expected newHTTPGetter to produce an httpGetter") } } diff --git a/pkg/lint/rules/testdata/albatross/templates/svc.yaml b/pkg/lint/rules/testdata/albatross/templates/svc.yaml index bf1c1761c..0e2e1b72b 100644 --- a/pkg/lint/rules/testdata/albatross/templates/svc.yaml +++ b/pkg/lint/rules/testdata/albatross/templates/svc.yaml @@ -9,7 +9,6 @@ metadata: release: {{ .Release.Name | quote }} chart: "{{.Chart.Name}}-{{.Chart.Version}}" kubeVersion: {{ .Capabilities.KubeVersion.Major }} - helmVersion: {{ .Capabilities.HelmVersion }} spec: ports: - port: {{default 80 .Values.httpPort | quote}} diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index e211729b0..a2ec3f819 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -120,6 +120,7 @@ func (r *ChartRepository) DownloadIndexFile(cachePath string) error { parsedURL.Path = strings.TrimSuffix(parsedURL.Path, "/") + "/index.yaml" indexURL = parsedURL.String() + // TODO add user-agent g, err := getter.NewHTTPGetter(indexURL, r.Config.CertFile, r.Config.KeyFile, r.Config.CAFile) if err != nil { return err diff --git a/pkg/tiller/release_install.go b/pkg/tiller/release_install.go index e6fd82ff3..8cfe8a074 100644 --- a/pkg/tiller/release_install.go +++ b/pkg/tiller/release_install.go @@ -68,7 +68,7 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas return nil, err } - caps, err := capabilities(s.discovery) + caps, err := newCapabilities(s.discovery) if err != nil { return nil, err } diff --git a/pkg/tiller/release_server.go b/pkg/tiller/release_server.go index d64803861..4134443fc 100644 --- a/pkg/tiller/release_server.go +++ b/pkg/tiller/release_server.go @@ -165,53 +165,9 @@ func (s *ReleaseServer) uniqName(start string, reuse bool) (string, error) { } return "", errors.Errorf("a release named %s already exists.\nRun: helm ls --all %s; to check the status of the release\nOr run: helm del --purge %s; to delete it", start, start, start) - -} - -// capabilities builds a Capabilities from discovery information. -func capabilities(disc discovery.DiscoveryInterface) (*chartutil.Capabilities, error) { - sv, err := disc.ServerVersion() - if err != nil { - return nil, err - } - vs, err := GetVersionSet(disc) - if err != nil { - return nil, errors.Wrap(err, "could not get apiVersions from Kubernetes") - } - return &chartutil.Capabilities{ - APIVersions: vs, - KubeVersion: sv, - HelmVersion: version.GetBuildInfo(), - }, nil -} - -// GetVersionSet retrieves a set of available k8s API versions -func GetVersionSet(client discovery.ServerGroupsInterface) (chartutil.VersionSet, error) { - groups, err := client.ServerGroups() - if err != nil { - return chartutil.DefaultVersionSet, err - } - - // FIXME: The Kubernetes test fixture for cli appears to always return nil - // for calls to Discovery().ServerGroups(). So in this case, we return - // the default API list. This is also a safe value to return in any other - // odd-ball case. - if groups.Size() == 0 { - return chartutil.DefaultVersionSet, nil - } - - versions := metav1.ExtractGroupVersions(groups) - return chartutil.NewVersionSet(versions...), nil } func (s *ReleaseServer) renderResources(ch *chart.Chart, values chartutil.Values, vs chartutil.VersionSet) ([]*release.Hook, *bytes.Buffer, string, error) { - // Guard to make sure Helm is at the right version to handle this chart. - sver := version.GetVersion() - if ch.Metadata.HelmVersion != "" && - !version.IsCompatibleRange(ch.Metadata.HelmVersion, sver) { - return nil, nil, "", errors.Errorf("chart incompatible with Helm %s", sver) - } - if ch.Metadata.KubeVersion != "" { cap, _ := values["Capabilities"].(*chartutil.Capabilities) gitVersion := cap.KubeVersion.String() @@ -383,3 +339,31 @@ func hookHasDeletePolicy(h *release.Hook, policy string) bool { } return false } + +func newCapabilities(dc discovery.DiscoveryInterface) (*chartutil.Capabilities, error) { + kubeVersion, err := dc.ServerVersion() + if err != nil { + return nil, err + } + + apiVersions, err := GetVersionSet(dc) + if err != nil { + return nil, errors.Wrap(err, "could not get apiVersions from Kubernetes") + } + + return &chartutil.Capabilities{ + KubeVersion: kubeVersion, + APIVersions: apiVersions, + }, nil +} + +// GetVersionSet retrieves a set of available k8s API versions +func GetVersionSet(dc discovery.ServerGroupsInterface) (chartutil.VersionSet, error) { + groups, err := dc.ServerGroups() + if groups.Size() > 0 { + versions := metav1.ExtractGroupVersions(groups) + return chartutil.NewVersionSet(versions...), err + } + return chartutil.DefaultVersionSet, err + +} diff --git a/pkg/tiller/release_server_test.go b/pkg/tiller/release_server_test.go index 0c8de78b6..12bb8b113 100644 --- a/pkg/tiller/release_server_test.go +++ b/pkg/tiller/release_server_test.go @@ -28,7 +28,7 @@ import ( "github.com/ghodss/yaml" "github.com/pkg/errors" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/cli-runtime/pkg/genericclioptions/resource" "k8s.io/client-go/kubernetes/fake" @@ -303,20 +303,6 @@ func TestValidName(t *testing.T) { } } -func TestGetVersionSet(t *testing.T) { - rs := rsFixture(t) - vs, err := GetVersionSet(rs.discovery) - if err != nil { - t.Error(err) - } - if !vs.Has("v1") { - t.Errorf("Expected supported versions to at least include v1.") - } - if vs.Has("nosuchversion/v1") { - t.Error("Non-existent version is reported found.") - } -} - func TestUniqName(t *testing.T) { rs := rsFixture(t) diff --git a/pkg/tiller/release_uninstall.go b/pkg/tiller/release_uninstall.go index 568741738..dea552c8f 100644 --- a/pkg/tiller/release_uninstall.go +++ b/pkg/tiller/release_uninstall.go @@ -126,13 +126,13 @@ func (s *ReleaseServer) purgeReleases(rels ...*release.Release) error { // deleteRelease deletes the release and returns manifests that were kept in the deletion process func (s *ReleaseServer) deleteRelease(rel *release.Release) (kept string, errs []error) { - vs, err := GetVersionSet(s.discovery) + caps, err := newCapabilities(s.discovery) if err != nil { return rel.Manifest, []error{errors.Wrap(err, "could not get apiVersions from Kubernetes")} } manifests := relutil.SplitManifests(rel.Manifest) - _, files, err := SortManifests(manifests, vs, UninstallOrder) + _, files, err := SortManifests(manifests, caps.APIVersions, UninstallOrder) if err != nil { // We could instead just delete everything in no particular order. // FIXME: One way to delete at this point would be to try a label-based diff --git a/pkg/tiller/release_update.go b/pkg/tiller/release_update.go index 622de5da0..35acd4526 100644 --- a/pkg/tiller/release_update.go +++ b/pkg/tiller/release_update.go @@ -103,7 +103,7 @@ func (s *ReleaseServer) prepareUpdate(req *hapi.UpdateReleaseRequest) (*release. IsUpgrade: true, } - caps, err := capabilities(s.discovery) + caps, err := newCapabilities(s.discovery) if err != nil { return nil, nil, err } diff --git a/pkg/version/version.go b/pkg/version/version.go index 296a97741..fba8b86fd 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -16,32 +16,6 @@ limitations under the License. package version // import "k8s.io/helm/pkg/version" -var ( - // version is the current version of the Helm. - // Update this whenever making a new release. - // The version is of the format Major.Minor.Patch[-Prerelease][+BuildMetadata] - // - // Increment major number for new feature additions and behavioral changes. - // Increment minor number for bug fixes and performance enhancements. - // Increment patch number for critical fixes to existing releases. - version = "v3.0" - - // metadata is extra build time data - metadata = "unreleased" - // gitCommit is the git sha1 - gitCommit = "" - // gitTreeState is the state of the git tree - gitTreeState = "" -) - -// GetVersion returns the semver string of the version -func GetVersion() string { - if metadata == "" { - return version - } - return version + "+" + metadata -} - // BuildInfo describes the compile time information. type BuildInfo struct { // Version is the current semver. @@ -51,12 +25,3 @@ type BuildInfo struct { // GitTreeState is the state of the git tree GitTreeState string `json:"git_tree_state,omitempty"` } - -// GetBuildInfo returns build info -func GetBuildInfo() BuildInfo { - return BuildInfo{ - Version: GetVersion(), - GitCommit: gitCommit, - GitTreeState: gitTreeState, - } -} diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go deleted file mode 100644 index a42bb6b64..000000000 --- a/pkg/version/version_test.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright The Helm Authors. - -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 version represents the current version of the project. -package version // import "k8s.io/helm/pkg/version" - -import "testing" - -func TestBuildInfo(t *testing.T) { - tests := []struct { - version string - buildMetadata string - gitCommit string - gitTreeState string - expected BuildInfo - }{ - {"", "", "", "", BuildInfo{Version: "", GitCommit: "", GitTreeState: ""}}, - {"v1.0.0", "", "", "", BuildInfo{Version: "v1.0.0", GitCommit: "", GitTreeState: ""}}, - {"v1.0.0", "79d5c5f7", "", "", BuildInfo{Version: "v1.0.0+79d5c5f7", GitCommit: "", GitTreeState: ""}}, - {"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "", BuildInfo{Version: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: ""}}, - {"v1.0.0", "79d5c5f7", "0d399baec2acda578a217d1aec8d7d707c71e44d", "clean", BuildInfo{Version: "v1.0.0+79d5c5f7", GitCommit: "0d399baec2acda578a217d1aec8d7d707c71e44d", GitTreeState: "clean"}}, - } - for _, tt := range tests { - version = tt.version - metadata = tt.buildMetadata - gitCommit = tt.gitCommit - gitTreeState = tt.gitTreeState - if GetBuildInfo() != tt.expected { - t.Errorf("expected Version(%s), GitCommit(%s) and GitTreeState(%s) to be %v", tt.expected, tt.gitCommit, tt.gitTreeState, GetBuildInfo()) - } - } -}