Merge pull request #5643 from mortent/NoValidateExistingResources

fix(helm): Only validate new manifests
pull/5759/head
Matthew Fisher 6 years ago committed by GitHub
commit 9fb19967ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -141,7 +141,7 @@ func (c *Client) validator() validation.Schema {
return schema
}
// BuildUnstructured validates for Kubernetes objects and returns unstructured infos.
// BuildUnstructured reads Kubernetes objects and returns unstructured infos.
func (c *Client) BuildUnstructured(namespace string, reader io.Reader) (Result, error) {
var result Result
@ -150,13 +150,26 @@ func (c *Client) BuildUnstructured(namespace string, reader io.Reader) (Result,
ContinueOnError().
NamespaceParam(namespace).
DefaultNamespace().
Schema(c.validator()).
Stream(reader, "").
Flatten().
Do().Infos()
return result, scrubValidationError(err)
}
// Validate reads Kubernetes manifests and validates the content.
func (c *Client) Validate(namespace string, reader io.Reader) error {
_, err := c.NewBuilder().
Unstructured().
ContinueOnError().
NamespaceParam(namespace).
DefaultNamespace().
Schema(c.validator()).
Stream(reader, "").
Flatten().
Do().Infos()
return scrubValidationError(err)
}
// Build validates for Kubernetes objects and returns resource Infos from a io.Reader.
func (c *Client) Build(namespace string, reader io.Reader) (Result, error) {
var result Result

@ -147,8 +147,20 @@ type KubeClient interface {
UpdateWithOptions(namespace string, originalReader, modifiedReader io.Reader, opts kube.UpdateOptions) error
Build(namespace string, reader io.Reader) (kube.Result, error)
// BuildUnstructured reads a stream of manifests from a reader and turns them into
// info objects. Manifests are not validated against the schema, but it will fail if
// any resoures types are not known by the apiserver.
//
// reader must contain a YAML stream (one or more YAML documents separated by "\n---\n").
BuildUnstructured(namespace string, reader io.Reader) (kube.Result, error)
// Validate reads a stream of manifests from a reader and validates them against
// the schema from the apiserver. It returns an error if any of the manifests does not validate.
//
// reader must contain a YAML stream (one or more YAML documents separated by "\n---\n").
Validate(namespace string, reader io.Reader) error
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify).
WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error)
@ -214,6 +226,11 @@ func (p *PrintingKubeClient) BuildUnstructured(ns string, reader io.Reader) (kub
return []*resource.Info{}, nil
}
// Validate implements KubeClient Validate
func (p *PrintingKubeClient) Validate(ns string, reader io.Reader) error {
return nil
}
// WaitAndGetCompletedPodPhase implements KubeClient WaitAndGetCompletedPodPhase.
func (p *PrintingKubeClient) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error) {
_, err := io.Copy(p.Out, reader)

@ -64,6 +64,9 @@ func (k *mockKubeClient) Build(ns string, reader io.Reader) (kube.Result, error)
func (k *mockKubeClient) BuildUnstructured(ns string, reader io.Reader) (kube.Result, error) {
return []*resource.Info{}, nil
}
func (k *mockKubeClient) Validate(ns string, reader io.Reader) error {
return nil
}
func (k *mockKubeClient) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error) {
return v1.PodUnknown, nil
}

@ -436,8 +436,7 @@ func (s *ReleaseServer) execHook(hs []*release.Hook, name, namespace, hook strin
func validateManifest(c environment.KubeClient, ns string, manifest []byte) error {
r := bytes.NewReader(manifest)
_, err := c.BuildUnstructured(ns, r)
return err
return c.Validate(ns, r)
}
func validateReleaseName(releaseName string) error {

@ -650,6 +650,9 @@ func (kc *mockHooksKubeClient) Build(ns string, reader io.Reader) (kube.Result,
func (kc *mockHooksKubeClient) BuildUnstructured(ns string, reader io.Reader) (kube.Result, error) {
return []*resource.Info{}, nil
}
func (kc *mockHooksKubeClient) Validate(ns string, reader io.Reader) error {
return nil
}
func (kc *mockHooksKubeClient) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error) {
return v1.PodUnknown, nil
}

Loading…
Cancel
Save