fix: turned warnings into fatal errors, fixed spelling, clear cache once

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
pull/6332/head
Matt Butcher 6 years ago
parent 0e7e618e2c
commit cf620a4914
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -30,6 +30,7 @@ import (
"github.com/Masterminds/sprig" "github.com/Masterminds/sprig"
"github.com/pkg/errors" "github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/cli-runtime/pkg/resource"
"helm.sh/helm/pkg/chart" "helm.sh/helm/pkg/chart"
"helm.sh/helm/pkg/chartutil" "helm.sh/helm/pkg/chartutil"
@ -104,19 +105,15 @@ func NewInstall(cfg *Configuration) *Install {
} }
func (i *Install) installCRDs(crds []*chart.File) error { func (i *Install) installCRDs(crds []*chart.File) error {
// We do these one at a time in the order they were read. // We do these one file at a time in the order they were read.
totalItems := []*resource.Info{}
for _, obj := range crds { for _, obj := range crds {
// Read in the resources // Read in the resources
res, err := i.cfg.KubeClient.Build(bytes.NewBuffer(obj.Data)) res, err := i.cfg.KubeClient.Build(bytes.NewBuffer(obj.Data))
if err != nil { if err != nil {
// We bail out immediately
return errors.Wrapf(err, "failed to install CRD %s", obj.Name) return errors.Wrapf(err, "failed to install CRD %s", obj.Name)
} }
// On dry run, bail here
if i.DryRun {
i.cfg.Log("WARNING: This chart or one of its subcharts contains CRDs. Rendering may fail or contain inaccuracies.")
continue
}
// Send them to Kube // Send them to Kube
if _, err := i.cfg.KubeClient.Create(res); err != nil { if _, err := i.cfg.KubeClient.Create(res); err != nil {
// If the error is CRD already exists, continue. // If the error is CRD already exists, continue.
@ -127,23 +124,22 @@ func (i *Install) installCRDs(crds []*chart.File) error {
} }
return errors.Wrapf(err, "failed to instal CRD %s", obj.Name) return errors.Wrapf(err, "failed to instal CRD %s", obj.Name)
} }
totalItems = append(totalItems, res...)
// Invalidate the local cache.
if discoveryClient, err := i.cfg.RESTClientGetter.ToDiscoveryClient(); err != nil {
// On error, we don't want to bail out, since this is unlikely
// to impact the majority of charts.
i.cfg.Log("Could not clear the discovery cache: %s", err)
} else {
i.cfg.Log("Clearing discovery cache")
discoveryClient.Invalidate()
// Give time for the CRD to be recognized.
if err := i.cfg.KubeClient.Wait(res, 60*time.Second); err != nil {
i.cfg.Log("Error waiting for CRD. Continuing blindly. %s", err)
}
// Make sure to force a rebuild of the cache.
discoveryClient.ServerGroups()
}
} }
// Invalidate the local cache, since it will not have the new CRDs
// present.
discoveryClient, err := i.cfg.RESTClientGetter.ToDiscoveryClient()
if err != nil {
return err
}
i.cfg.Log("Clearing discovery cache")
discoveryClient.Invalidate()
// Give time for the CRD to be recognized.
if err := i.cfg.KubeClient.Wait(totalItems, 60*time.Second); err != nil {
return err
}
// Make sure to force a rebuild of the cache.
discoveryClient.ServerGroups()
return nil return nil
} }
@ -158,7 +154,10 @@ func (i *Install) Run(chrt *chart.Chart, vals map[string]interface{}) (*release.
// Pre-install anything in the crd/ directory. We do this before Helm // Pre-install anything in the crd/ directory. We do this before Helm
// contacts the upstream server and builds the capabilities object. // contacts the upstream server and builds the capabilities object.
if crds := chrt.CRDs(); !i.ClientOnly && !i.SkipCRDs && len(crds) > 0 { if crds := chrt.CRDs(); !i.ClientOnly && !i.SkipCRDs && len(crds) > 0 {
if err := i.installCRDs(crds); err != nil { // On dry run, bail here
if i.DryRun {
i.cfg.Log("WARNING: This chart or one of its subcharts contains CRDs. Rendering may fail or contain inaccuracies.")
} else if err := i.installCRDs(crds); err != nil {
return nil, err return nil, err
} }
} }

@ -58,6 +58,7 @@ func New(getter genericclioptions.RESTClientGetter) *Client {
if getter == nil { if getter == nil {
getter = genericclioptions.NewConfigFlags(true) getter = genericclioptions.NewConfigFlags(true)
} }
// Add CRDs to the scheme. They are missing by default.
if err := apiextv1beta1.AddToScheme(scheme.Scheme); err != nil { if err := apiextv1beta1.AddToScheme(scheme.Scheme); err != nil {
// This should never happen. // This should never happen.
panic(err) panic(err)

@ -280,7 +280,7 @@ func (w *waiter) crdReady(crd apiextv1beta1.CustomResourceDefinition) bool {
case apiextv1beta1.NamesAccepted: case apiextv1beta1.NamesAccepted:
if cond.Status == apiextv1beta1.ConditionFalse { if cond.Status == apiextv1beta1.ConditionFalse {
// This indicates a naming conflict, but it's probably not the // This indicates a naming conflict, but it's probably not the
// job of this function to faile because of that. Instead, // job of this function to fail because of that. Instead,
// we treat it as a success, since the process should be able to // we treat it as a success, since the process should be able to
// continue. // continue.
return true return true

Loading…
Cancel
Save