fix(helm): Allow custom resources in hooks (#4986)

Currently the code that handles hooks uses a builder that creates the versioned types rather than unstructured. This results in an error whenever a custom resource is used in the hook as the type will not be registered in the scheme used in Helm. This changes this to use a builder that created unstructured resources and only converts to the versioned type when needed.

Signed-off-by: Morten Torkildsen <mortent@google.com>
pull/4989/head
Morten Torkildsen 6 years ago committed by Matthew Fisher
parent e2a0e7fa54
commit 55a338579a

@ -179,7 +179,11 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
vk := gvk.Version + "/" + gvk.Kind vk := gvk.Version + "/" + gvk.Kind
internalObj, err := asInternal(info) internalObj, err := asInternal(info)
if err != nil { if err != nil {
// If the problem is just that the resource is not registered, don't print any
// error. This is normal for custom resources.
if !runtime.IsNotRegisteredError(err) {
c.Log("Warning: conversion to internal type failed: %v", err) c.Log("Warning: conversion to internal type failed: %v", err)
}
// Add the unstructured object in this situation. It will still get listed, just // Add the unstructured object in this situation. It will still get listed, just
// with less information. // with less information.
objs[vk] = append(objs[vk], info.Object) objs[vk] = append(objs[vk], info.Object)
@ -358,7 +362,7 @@ func (c *Client) watchTimeout(t time.Duration) ResourceActorFunc {
// //
// Handling for other kinds will be added as necessary. // Handling for other kinds will be added as necessary.
func (c *Client) WatchUntilReady(namespace string, reader io.Reader, timeout int64, shouldWait bool) error { func (c *Client) WatchUntilReady(namespace string, reader io.Reader, timeout int64, shouldWait bool) error {
infos, err := c.Build(namespace, reader) infos, err := c.BuildUnstructured(namespace, reader)
if err != nil { if err != nil {
return err return err
} }
@ -605,12 +609,13 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
// //
// This operates on an event returned from a watcher. // This operates on an event returned from a watcher.
func (c *Client) waitForJob(e watch.Event, name string) (bool, error) { func (c *Client) waitForJob(e watch.Event, name string) (bool, error) {
o, ok := e.Object.(*batch.Job) job := &batch.Job{}
if !ok { err := legacyscheme.Scheme.Convert(e.Object, job, nil)
return true, fmt.Errorf("Expected %s to be a *batch.Job, got %T", name, e.Object) if err != nil {
return true, err
} }
for _, c := range o.Status.Conditions { for _, c := range job.Status.Conditions {
if c.Type == batch.JobComplete && c.Status == v1.ConditionTrue { if c.Type == batch.JobComplete && c.Status == v1.ConditionTrue {
return true, nil return true, nil
} else if c.Type == batch.JobFailed && c.Status == v1.ConditionTrue { } else if c.Type == batch.JobFailed && c.Status == v1.ConditionTrue {
@ -618,7 +623,7 @@ func (c *Client) waitForJob(e watch.Event, name string) (bool, error) {
} }
} }
c.Log("%s: Jobs active: %d, jobs failed: %d, jobs succeeded: %d", name, o.Status.Active, o.Status.Failed, o.Status.Succeeded) c.Log("%s: Jobs active: %d, jobs failed: %d, jobs succeeded: %d", name, job.Status.Active, job.Status.Failed, job.Status.Succeeded)
return false, nil return false, nil
} }

Loading…
Cancel
Save