Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
@@ -18,6 +18,7 @@ package rules // import "helm.sh/helm/v3/pkg/lint/rules"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -25,11 +26,12 @@ import (
|
||||
kscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
// This should be set in the Makefile based on the version of client-go being imported.
|
||||
// These constants will be overwritten with LDFLAGS
|
||||
k8sVersionMajor = 1
|
||||
k8sVersionMinor = 20
|
||||
// These constants will be overwritten with LDFLAGS. The version components must be
|
||||
// strings in order for LDFLAGS to set them.
|
||||
k8sVersionMajor = "1"
|
||||
k8sVersionMinor = "20"
|
||||
)
|
||||
|
||||
// deprecatedAPIError indicates than an API is deprecated in Kubernetes
|
||||
@@ -60,7 +62,16 @@ func validateNoDeprecations(resource *K8sYamlStruct) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
if !deprecation.IsDeprecated(runtimeObject, k8sVersionMajor, k8sVersionMinor) {
|
||||
maj, err := strconv.Atoi(k8sVersionMajor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
min, err := strconv.Atoi(k8sVersionMinor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !deprecation.IsDeprecated(runtimeObject, maj, min) {
|
||||
return nil
|
||||
}
|
||||
gvk := fmt.Sprintf("%s %s", resource.APIVersion, resource.Kind)
|
||||
|
||||
@@ -70,6 +70,12 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
// lint ignores import-values
|
||||
// See https://github.com/helm/helm/issues/9658
|
||||
if err := chartutil.ProcessDependencies(chart, values); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cvals, err := chartutil.CoalesceValues(chart, values)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -113,7 +119,7 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
|
||||
|
||||
// NOTE: disabled for now, Refs https://github.com/helm/helm/issues/1463
|
||||
// Check that all the templates have a matching value
|
||||
//linter.RunLinterRule(support.WarningSev, fpath, validateNoMissingValues(templatesPath, valuesToRender, preExecutedTemplate))
|
||||
// linter.RunLinterRule(support.WarningSev, fpath, validateNoMissingValues(templatesPath, valuesToRender, preExecutedTemplate))
|
||||
|
||||
// NOTE: disabled for now, Refs https://github.com/helm/helm/issues/1037
|
||||
// linter.RunLinterRule(support.WarningSev, fpath, validateQuotes(string(preExecutedTemplate)))
|
||||
@@ -146,6 +152,7 @@ func Templates(linter *support.Linter, values map[string]interface{}, namespace
|
||||
linter.RunLinterRule(support.WarningSev, fpath, validateNoDeprecations(yamlStruct))
|
||||
|
||||
linter.RunLinterRule(support.ErrorSev, fpath, validateMatchSelector(yamlStruct, renderedContent))
|
||||
linter.RunLinterRule(support.ErrorSev, fpath, validateListAnnotations(yamlStruct, renderedContent))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,6 +300,28 @@ func validateMatchSelector(yamlStruct *K8sYamlStruct, manifest string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func validateListAnnotations(yamlStruct *K8sYamlStruct, manifest string) error {
|
||||
if yamlStruct.Kind == "List" {
|
||||
m := struct {
|
||||
Items []struct {
|
||||
Metadata struct {
|
||||
Annotations map[string]string
|
||||
}
|
||||
}
|
||||
}{}
|
||||
|
||||
if err := yaml.Unmarshal([]byte(manifest), &m); err != nil {
|
||||
return validateYamlContent(err)
|
||||
}
|
||||
|
||||
for _, i := range m.Items {
|
||||
if _, ok := i.Metadata.Annotations["helm.sh/resource-policy"]; ok {
|
||||
return errors.New("Annotation 'helm.sh/resource-policy' within List objects are ignored")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// K8sYamlStruct stubs a Kubernetes YAML file.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user