Add more capabilities to the detault set used by helm template

- These are the capabilities as of k8s 1.14
- They are generated because getting them at runtime uses so much
  memory it causes CI errors
Signed-off-by: 's avatarMatt Farina <matt@mattfarina.com>
parent 6c88a429
......@@ -141,6 +141,10 @@ docker-test-style: check-docker
protoc:
$(MAKE) -C _proto/ all
.PHONY: generate
generate:
$(GO) generate ./...
.PHONY: docs
docs: build
@scripts/update-docs.sh
......
......@@ -27,7 +27,7 @@ helm template [flags] CHART
-x, --execute stringArray Only execute the given templates
-h, --help help for template
--is-upgrade Set .Release.IsUpgrade instead of .Release.IsInstall
--kube-version string Kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9")
--kube-version string Kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.14")
-n, --name string Release name (default "release-name")
--name-template string Specify template used to name the release
--namespace string Namespace to install the release into
......@@ -55,4 +55,4 @@ helm template [flags] CHART
* [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 16-May-2019
###### Auto generated by spf13/cobra on 17-Jun-2019
......@@ -12,6 +12,7 @@ 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.
*/
//go:generate go run generator/capabilities_default_versions_generate.go
package chartutil
......@@ -24,14 +25,15 @@ import (
)
var (
// DefaultVersionSet is the default version set, which includes only Core V1 ("v1").
DefaultVersionSet = NewVersionSet("v1")
// DefaultVersionSet is the default version set in included in Kubernetes for workloads
// Default versions as of Kubernetes 1.14
DefaultVersionSet = NewVersionSet(defaultVersions()...)
// DefaultKubeVersion is the default kubernetes version
DefaultKubeVersion = &version.Info{
Major: "1",
Minor: "9",
GitVersion: "v1.9.0",
Minor: "14",
GitVersion: "v1.14.0",
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
......
......@@ -38,9 +38,6 @@ func TestDefaultVersionSet(t *testing.T) {
if !DefaultVersionSet.Has("v1") {
t.Error("Expected core v1 version set")
}
if d := len(DefaultVersionSet); d != 1 {
t.Errorf("Expected only one version, got %d", d)
}
}
func TestCapabilities(t *testing.T) {
......@@ -51,4 +48,8 @@ func TestCapabilities(t *testing.T) {
if !cap.APIVersions.Has("v1") {
t.Error("APIVersions should have v1")
}
if !cap.APIVersions.Has("apps/v1/Deployment") {
t.Error("APIVersions should have apps/v1/Deployment")
}
}
This diff is collapsed.
/*
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.
*/
// Generates the default versions to use with capabilities. This cannot be loaded
// dynamically as it uses enough memory to cause out of memory issues in CI.
//
// +build ignore
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"sort"
"k8s.io/client-go/kubernetes/scheme"
)
const licenseHeader = `/*
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.
*/`
func main() {
v := getVersions()
o := createOutput(v)
err := ioutil.WriteFile("capabilities_versions_generated.go", o, 0644)
if err != nil {
fmt.Printf("writing output: %s", err)
os.Exit(1)
}
}
func createOutput(v []string) []byte {
var out bytes.Buffer
fmt.Fprintln(&out, licenseHeader)
fmt.Fprintln(&out, "// Code generated by capabilities_default_versions_generate.go; DO NOT EDIT.")
fmt.Fprint(&out, "package chartutil\n\n")
fmt.Fprintln(&out, "func defaultVersions() []string {")
fmt.Fprintln(&out, "\treturn []string{")
for _, v := range v {
fmt.Fprintf(&out, "\t\t\"%s\",\n", v)
}
fmt.Fprintln(&out, "\t}")
fmt.Fprintln(&out, "}")
return out.Bytes()
}
func getVersions() []string {
var s []string
var gv string
var gvk string
// Check is used so that we only add an item once to the return
check := make(map[string]struct{})
// Client go has a default scheme set with everything in it
// This includes over 500 group versions and group versioned kinds
for k := range scheme.Scheme.AllKnownTypes() {
gv = path.Join(k.Group, k.Version)
gvk = path.Join(k.Group, k.Version, k.Kind)
if _, ok := check[gv]; !ok {
check[gv] = struct{}{}
s = append(s, gv)
}
if _, ok := check[gvk]; !ok {
check[gvk] = struct{}{}
s = append(s, gvk)
}
}
// Put the names in a consistent order
sort.Strings(s)
return s
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment