diff --git a/internal/cmd/agent/controller/bundledeployment_controller.go b/internal/cmd/agent/controller/bundledeployment_controller.go index 8c5b618b2d..6691578176 100644 --- a/internal/cmd/agent/controller/bundledeployment_controller.go +++ b/internal/cmd/agent/controller/bundledeployment_controller.go @@ -54,7 +54,8 @@ type BundleDeploymentReconciler struct { // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.15.0/pkg/reconcile func (r *BundleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - _ = log.FromContext(ctx).WithName("bundledeployment") + logger := log.FromContext(ctx).WithName("bundledeployment") + ctx = log.IntoContext(ctx, logger) // get latest BundleDeployment from cluster bd := &fleetv1.BundleDeployment{} @@ -73,6 +74,7 @@ func (r *BundleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req var updateErr error bd, updateErr = updateCondition(ctx, r.Client, bd, &status, err, condition.Cond(fleetv1.BundleDeploymentConditionDeployed)) if err != nil { + logger.V(1).Error(err, "Failed to deploy bundle", "status", status) return ctrl.Result{ // Defaults Requeue: false, @@ -80,6 +82,7 @@ func (r *BundleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req }, err } if updateErr != nil { + logger.V(1).Error(updateErr, "Failed to update bundledeployment status", "step", "deploy", "status", status) return ctrl.Result{}, updateErr } @@ -95,11 +98,13 @@ func (r *BundleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, err } if updateErr != nil { + logger.V(1).Error(updateErr, "Failed to update bundledeployment status", "step", "monitor", "status", status) return ctrl.Result{}, updateErr } - _, err = r.DriftDetect.Refresh(req.String(), bd) + _, err = r.DriftDetect.Refresh(logger, req.String(), bd) if err != nil { + logger.V(1).Error(err, "Failed to refresh drift detection", "step", "drift") return ctrl.Result{}, err } diff --git a/internal/cmd/agent/deployer/cleanup/cleanup.go b/internal/cmd/agent/deployer/cleanup/cleanup.go index dc6cb92c59..3c4488697f 100644 --- a/internal/cmd/agent/deployer/cleanup/cleanup.go +++ b/internal/cmd/agent/deployer/cleanup/cleanup.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/sirupsen/logrus" + "github.com/go-logr/logr" "github.com/rancher/fleet/internal/helmdeployer" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" @@ -17,6 +17,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" ) type Cleanup struct { @@ -48,9 +49,10 @@ func (c *Cleanup) CleanupReleases(ctx context.Context, key string, bd *fleet.Bun } func (c *Cleanup) garbageCollect(ctx context.Context) { + logger := log.FromContext(ctx).WithName("garbageCollect") for { - if err := c.cleanup(ctx); err != nil { - logrus.Errorf("failed to cleanup orphaned releases: %v", err) + if err := c.cleanup(ctx, logger); err != nil { + logger.Error(err, "failed to cleanup orphaned releases") } select { case <-ctx.Done(): @@ -60,7 +62,7 @@ func (c *Cleanup) garbageCollect(ctx context.Context) { } } -func (c *Cleanup) cleanup(ctx context.Context) error { +func (c *Cleanup) cleanup(ctx context.Context, logger logr.Logger) error { deployed, err := c.helmDeployer.ListDeployments() if err != nil { return err @@ -71,7 +73,7 @@ func (c *Cleanup) cleanup(ctx context.Context) error { err := c.client.Get(ctx, types.NamespacedName{Namespace: c.fleetNamespace, Name: deployed.BundleID}, bundleDeployment) if apierror.IsNotFound(err) { // found a helm secret, but no bundle deployment, so uninstall the release - logrus.Infof("Deleting orphan bundle ID %s, release %s", deployed.BundleID, deployed.ReleaseName) + logger.Info("Deleting orphan bundle ID, helm uninstall", "bundleID", deployed.BundleID, "release", deployed.ReleaseName) if err := c.helmDeployer.Delete(ctx, deployed.BundleID, deployed.ReleaseName); err != nil { return err } @@ -84,7 +86,7 @@ func (c *Cleanup) cleanup(ctx context.Context) error { key := releaseKey(c.defaultNamespace, bundleDeployment) if key != deployed.ReleaseName { // found helm secret and bundle deployment for BundleID, but release name doesn't match, so delete the release - logrus.Infof("Deleting unknown bundle ID %s, release %s, expecting release %s", deployed.BundleID, deployed.ReleaseName, key) + logger.Info("Deleting unknown bundle ID, helm uninstall", "bundleID", deployed.BundleID, "release", deployed.ReleaseName, "expectedRelease", key) if err := c.helmDeployer.Delete(ctx, deployed.BundleID, deployed.ReleaseName); err != nil { return err } diff --git a/internal/cmd/agent/deployer/deployer.go b/internal/cmd/agent/deployer/deployer.go index eb9ea4d8b0..bb4fcb5f97 100644 --- a/internal/cmd/agent/deployer/deployer.go +++ b/internal/cmd/agent/deployer/deployer.go @@ -7,8 +7,6 @@ import ( "regexp" "strings" - "github.com/sirupsen/logrus" - "github.com/rancher/fleet/internal/helmdeployer" "github.com/rancher/fleet/internal/manifest" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" @@ -19,13 +17,14 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" ) type Deployer struct { client client.Client upstreamClient client.Reader lookup *manifest.Lookup - deployer *helmdeployer.Helm + helm *helmdeployer.Helm } func NewDeployer(localClient client.Client, upstreamClient client.Reader, lookup *manifest.Lookup, deployer *helmdeployer.Helm) *Deployer { @@ -33,24 +32,26 @@ func NewDeployer(localClient client.Client, upstreamClient client.Reader, lookup client: localClient, upstreamClient: upstreamClient, lookup: lookup, - deployer: deployer, + helm: deployer, } } func (d *Deployer) DeployBundle(ctx context.Context, bd *fleet.BundleDeployment) (fleet.BundleDeploymentStatus, error) { + logger := log.FromContext(ctx).WithName("DeployBundle").WithValues("deploymentID", bd.Spec.DeploymentID, "appliedDeploymentID", bd.Status.AppliedDeploymentID) + status := *bd.Status.DeepCopy() if bd.Spec.Paused { // nothing to do - logrus.Debugf("Bundle %s/%s is paused", bd.Namespace, bd.Name) + logger.V(1).Info("Bundle paused") return status, nil } if err := d.checkDependency(ctx, bd); err != nil { - logrus.Debugf("Bundle %s/%s has a dependency that is not ready: %v", bd.Namespace, bd.Name, err) + logger.V(1).Info("Bundle has a dependency that is not ready: %v", err) return status, err } - logrus.Infof("Deploying bundle %s/%s", bd.Namespace, bd.Name) + logger.Info("Deploying bundle") release, err := d.helmdeploy(ctx, bd) if err != nil { // When an error from DeployBundle is returned it causes DeployBundle @@ -88,7 +89,7 @@ func (d *Deployer) DeployBundle(ctx context.Context, bd *fleet.BundleDeployment) // This loads the manifest and the contents from the upstream cluster. func (d *Deployer) helmdeploy(ctx context.Context, bd *fleet.BundleDeployment) (string, error) { if bd.Spec.DeploymentID == bd.Status.AppliedDeploymentID { - if ok, err := d.deployer.EnsureInstalled(bd.Name, bd.Status.Release); err != nil { + if ok, err := d.helm.EnsureInstalled(bd.Name, bd.Status.Release); err != nil { return "", err } else if ok { return bd.Status.Release, nil @@ -101,7 +102,7 @@ func (d *Deployer) helmdeploy(ctx context.Context, bd *fleet.BundleDeployment) ( } manifest.Commit = bd.Labels["fleet.cattle.io/commit"] - resource, err := d.deployer.Deploy(ctx, bd.Name, manifest, bd.Spec.Options) + resource, err := d.helm.Deploy(ctx, bd.Name, manifest, bd.Spec.Options) if err != nil { return "", err } diff --git a/internal/cmd/agent/deployer/driftdetect/driftdetect.go b/internal/cmd/agent/deployer/driftdetect/driftdetect.go index efc59f1203..3f4f8e1154 100644 --- a/internal/cmd/agent/deployer/driftdetect/driftdetect.go +++ b/internal/cmd/agent/deployer/driftdetect/driftdetect.go @@ -1,11 +1,11 @@ package driftdetect import ( + "github.com/go-logr/logr" "github.com/rancher/fleet/internal/cmd/agent/deployer/plan" "github.com/rancher/fleet/internal/cmd/agent/trigger" "github.com/rancher/fleet/internal/helmdeployer" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" - "github.com/sirupsen/logrus" "github.com/rancher/wrangler/v2/pkg/apply" @@ -42,12 +42,13 @@ func New( } } -func (m *DriftDetect) Refresh(key string, bd *fleet.BundleDeployment) (*fleet.BundleDeployment, error) { +func (m *DriftDetect) Refresh(logger logr.Logger, key string, bd *fleet.BundleDeployment) (*fleet.BundleDeployment, error) { + logger = logger.WithName("DriftDetect") if bd == nil || bd.Spec.Paused { return bd, m.trigger.Clear(key) } - logrus.Debugf("Triggering for bundledeployment '%s'", key) + logger.V(1).Info("Refreshing drift detection") resources, err := m.allResources(bd) if err != nil { @@ -58,11 +59,15 @@ func (m *DriftDetect) Refresh(key string, bd *fleet.BundleDeployment) (*fleet.Bu return bd, nil } - logrus.Debugf("Adding OnChange for bundledeployment's '%s' resource list", key) + logger.V(1).Info("Adding OnChange for bundledeployment's resource list") return bd, m.trigger.OnChange(key, resources.DefaultNamespace, func() { // enqueue bundledeployment if any resource changes //h.bdController.EnqueueAfter(bd.Namespace, bd.Name, 0) // TODO(manno): we can't enqueue directly, update status instead + // TODO + // TODO + // TODO + // TODO }, resources.Objects...) } diff --git a/internal/cmd/agent/deployer/monitor/monitor.go b/internal/cmd/agent/deployer/monitor/monitor.go index 81a8ed2a28..7aea6fbd39 100644 --- a/internal/cmd/agent/deployer/monitor/monitor.go +++ b/internal/cmd/agent/deployer/monitor/monitor.go @@ -6,8 +6,6 @@ import ( "fmt" "strings" - "github.com/sirupsen/logrus" - "github.com/rancher/fleet/internal/helmdeployer" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" @@ -20,6 +18,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" ) type Monitor struct { @@ -39,6 +38,7 @@ type Monitor struct { } func (ma *Monitor) MonitorBundle(ctx context.Context, bd *fleet.BundleDeployment) (fleet.BundleDeploymentStatus, error) { + logger := log.FromContext(ctx).WithName("MonitorBundle") status := *bd.Status.DeepCopy() if bd.Spec.DeploymentID != status.AppliedDeploymentID { return status, nil @@ -77,7 +77,7 @@ func (ma *Monitor) MonitorBundle(ctx context.Context, bd *fleet.BundleDeployment // TODO(manno): this should be a return value or a status update ...but how to delay? //h.bdController.EnqueueAfter(bd.Namespace, bd.Name, durations.MonitorBundleDelay) if shouldRedeploy(bd) { - logrus.Infof("Redeploying %s", bd.Name) + logger.Info("Redeploying") status.AppliedDeploymentID = "" if isAgent(bd) { if err := ma.cleanupOldAgent(ctx, status.ModifiedStatus); err != nil { @@ -89,7 +89,7 @@ func (ma *Monitor) MonitorBundle(ctx context.Context, bd *fleet.BundleDeployment status.SyncGeneration = &bd.Spec.Options.ForceSyncGeneration if readyError != nil { - logrus.Errorf("bundle %s: %v", bd.Name, readyError) + logger.Error(readyError, "Status not ready") } removePrivateFields(&status) @@ -123,6 +123,7 @@ func isAgent(bd *fleet.BundleDeployment) bool { } func (ma *Monitor) cleanupOldAgent(ctx context.Context, modifiedStatuses []fleet.ModifiedStatus) error { + logger := log.FromContext(ctx).WithName("cleanupOldAgent") var errs []error for _, modified := range modifiedStatuses { if modified.Delete { @@ -133,7 +134,7 @@ func (ma *Monitor) cleanupOldAgent(ctx context.Context, modifiedStatuses []fleet continue } - logrus.Infof("Removing old agent resource %s/%s, %s", modified.Namespace, modified.Name, gvk) + logger.Info("Removing old agent resource", "namespace", modified.Namespace, "name", modified.Name, "gvk", gvk) err = ma.LocalDynamicClient.Resource(mapping.Resource).Namespace(modified.Namespace).Delete(ctx, modified.Name, metav1.DeleteOptions{}) if err != nil { errs = append(errs, fmt.Errorf("deleting %s/%s for %s for agent cleanup: %w", modified.Namespace, modified.Name, gvk, err)) diff --git a/internal/cmd/agent/deployer/monitor/updatestatus.go b/internal/cmd/agent/deployer/monitor/updatestatus.go index 6a36caa354..bc15292047 100644 --- a/internal/cmd/agent/deployer/monitor/updatestatus.go +++ b/internal/cmd/agent/deployer/monitor/updatestatus.go @@ -5,8 +5,9 @@ import ( "fmt" "sort" + "github.com/go-logr/logr" "github.com/pkg/errors" - "github.com/sirupsen/logrus" + "sigs.k8s.io/controller-runtime/pkg/log" "github.com/rancher/fleet/internal/cmd/agent/deployer/plan" "github.com/rancher/fleet/internal/helmdeployer" @@ -25,6 +26,7 @@ import ( // updateBundleDeploymentStatus updates the status with information from the // helm release history and an apply dry run. func (m *Monitor) updateBundleDeploymentStatus(ctx context.Context, bd *fleet.BundleDeployment) error { + logger := log.FromContext(ctx).WithName("updateBundleDeploymentStatus") resources, err := m.Deployer.Resources(bd.Name, bd.Status.Release) if err != nil { return err @@ -49,7 +51,7 @@ func (m *Monitor) updateBundleDeploymentStatus(ctx context.Context, bd *fleet.Bu return err } - bd.Status.NonReadyStatus = nonReady(plan, bd.Spec.Options.IgnoreOptions) + bd.Status.NonReadyStatus = nonReady(logger, plan, bd.Spec.Options.IgnoreOptions) bd.Status.ModifiedStatus = modified(plan, resourcesPreviousRelease) bd.Status.Ready = false bd.Status.NonModified = false @@ -97,7 +99,7 @@ func (m *Monitor) updateBundleDeploymentStatus(ctx context.Context, bd *fleet.Bu return nil } -func nonReady(plan apply.Plan, ignoreOptions fleet.IgnoreOptions) (result []fleet.NonReadyStatus) { +func nonReady(logger logr.Logger, plan apply.Plan, ignoreOptions fleet.IgnoreOptions) (result []fleet.NonReadyStatus) { defer func() { sort.Slice(result, func(i, j int) bool { return result[i].UID < result[j].UID @@ -111,7 +113,7 @@ func nonReady(plan apply.Plan, ignoreOptions fleet.IgnoreOptions) (result []flee if u, ok := obj.(*unstructured.Unstructured); ok { if ignoreOptions.Conditions != nil { if err := excludeIgnoredConditions(u, ignoreOptions); err != nil { - logrus.Errorf("failed to ignore conditions: %v", err) + logger.Error(err, "failed to ignore conditions") } } diff --git a/internal/cmd/controller/start.go b/internal/cmd/controller/start.go index 9f62bad74b..8a653f491a 100644 --- a/internal/cmd/controller/start.go +++ b/internal/cmd/controller/start.go @@ -8,9 +8,20 @@ import ( "github.com/rancher/wrangler/v2/pkg/kubeconfig" "github.com/rancher/wrangler/v2/pkg/ratelimit" + + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" ) func start(ctx context.Context, systemNamespace string, kubeconfigFile string, disableGitops bool, disableBootstrap bool) error { + // provide a logger in the context to be compatible with controller-runtime + zopts := zap.Options{ + Development: true, + } + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zopts))) + ctx = log.IntoContext(ctx, ctrl.Log) + cfg := kubeconfig.GetNonInteractiveClientConfig(kubeconfigFile) clientConfig, err := cfg.ClientConfig() if err != nil { diff --git a/internal/helmdeployer/deployer.go b/internal/helmdeployer/deployer.go index 5be5be3b14..6ca9adfde8 100644 --- a/internal/helmdeployer/deployer.go +++ b/internal/helmdeployer/deployer.go @@ -8,10 +8,10 @@ import ( "strings" "time" + "github.com/go-logr/logr" "github.com/pkg/errors" "github.com/rancher/fleet/internal/config" "github.com/rancher/fleet/internal/helmdeployer/helmcache" - "github.com/sirupsen/logrus" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" @@ -38,6 +38,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/cli-runtime/pkg/genericclioptions" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" ) const ( @@ -87,7 +88,7 @@ type Resources struct { } type DeployedBundle struct { - // BundleID is the bundle.Name + // BundleID is the bundledeployment.Name BundleID string // ReleaseName is actually in the form "namespace/release name" ReleaseName string @@ -190,6 +191,7 @@ func (p *postRender) Run(renderedManifests *bytes.Buffer) (modifiedManifests *by return bytes.NewBuffer(data), err } +// Deploy deploys an unpacked content resource with helm. bundleID is the name of the bundledeployment. func (h *Helm) Deploy(ctx context.Context, bundleID string, manifest *manifest.Manifest, options fleet.BundleDeploymentOptions) (*Resources, error) { if options.Helm == nil { options.Helm = &fleet.HelmOptions{} @@ -243,7 +245,7 @@ func (h *Helm) Deploy(ctx context.Context, bundleID string, manifest *manifest.M // RemoveExternalChanges does a helm rollback to remove changes made outside of fleet. // It removes the helm history entry if the rollback fails. func (h *Helm) RemoveExternalChanges(ctx context.Context, bd *fleet.BundleDeployment) error { - logrus.Infof("Drift correction: rollback BundleDeployment %s", bd.Name) + log.FromContext(ctx).WithName("RemoveExternalChanges").Info("Drift correction: rollback") _, defaultNamespace, releaseName := h.getOpts(bd.Name, bd.Spec.Options) cfg, err := h.getCfg(ctx, defaultNamespace, bd.Spec.Options.ServiceAccount) @@ -348,7 +350,9 @@ func (h *Helm) getCfg(ctx context.Context, namespace, serviceAccountName string) return cfg, err } +// install runs helm install or upgrade and supports dry running the action. Will run helm rollback in case of a failed upgrade. func (h *Helm) install(ctx context.Context, bundleID string, manifest *manifest.Manifest, chart *chart.Chart, options fleet.BundleDeploymentOptions, dryRun bool) (*release.Release, error) { + logger := log.FromContext(ctx).WithName("HelmDeployer").WithName("install").WithValues("commit", manifest.Commit, "dryRun", dryRun) timeout, defaultNamespace, releaseName := h.getOpts(bundleID, options) values, err := h.getValues(ctx, options, defaultNamespace) @@ -367,6 +371,7 @@ func (h *Helm) install(ctx context.Context, bundleID string, manifest *manifest. } if uninstall { + logger.Info("Uninstalling helm release first") if err := h.delete(ctx, bundleID, options, dryRun); err != nil { return nil, err } @@ -422,7 +427,7 @@ func (h *Helm) install(ctx context.Context, bundleID string, manifest *manifest. u.Wait = true } if !dryRun { - logrus.Infof("Helm: Installing %s", bundleID) + logger.Info("Installing helm release") } return u.Run(chart, values) } @@ -446,17 +451,17 @@ func (h *Helm) install(ctx context.Context, bundleID string, manifest *manifest. u.Wait = true } if !dryRun { - logrus.Infof("Helm: Upgrading %s", bundleID) + logger.Info("Upgrading helm release") } rel, err := u.Run(releaseName, chart, values) if err != nil && err.Error() == HelmUpgradeInterruptedError { - logrus.Infof("Helm error: %s for %s. Doing a rollback", HelmUpgradeInterruptedError, bundleID) + logger.Info("Helm doing a rollback", "error", HelmUpgradeInterruptedError) r := action.NewRollback(&cfg) err = r.Run(releaseName) if err != nil { return nil, err } - logrus.Debugf("Helm: retrying upgrade for %s after rollback", bundleID) + logger.V(1).Info("Retrying upgrade after rollback") return u.Run(releaseName, chart, values) } @@ -675,6 +680,7 @@ func (h *Helm) Delete(ctx context.Context, bundleID, releaseName string) error { } func (h *Helm) deleteByRelease(ctx context.Context, bundleID, releaseName string, keepResources bool) error { + logger := log.FromContext(ctx).WithName("deleteByRelease").WithValues("releaseName", releaseName, "keepResources", keepResources) releaseNamespace, releaseName := kv.Split(releaseName, "/") rels, err := h.globalCfg.Releases.List(func(r *release.Release) bool { return r.Namespace == releaseNamespace && @@ -706,12 +712,12 @@ func (h *Helm) deleteByRelease(ctx context.Context, bundleID, releaseName string if strings.HasPrefix(bundleID, "fleet-agent") { // Never uninstall the fleet-agent, just "forget" it - return deleteHistory(cfg, bundleID) + return deleteHistory(cfg, logger, bundleID) } if keepResources { // don't delete resources, just delete the helm release secrets - return deleteHistory(cfg, bundleID) + return deleteHistory(cfg, logger, bundleID) } u := action.NewUninstall(&cfg) @@ -720,6 +726,7 @@ func (h *Helm) deleteByRelease(ctx context.Context, bundleID, releaseName string } func (h *Helm) delete(ctx context.Context, bundleID string, options fleet.BundleDeploymentOptions, dryRun bool) error { + logger := log.FromContext(ctx).WithName("HelmDeployer").WithName("delete").WithValues("dryRun", dryRun) timeout, _, releaseName := h.getOpts(bundleID, options) r, err := h.globalCfg.Releases.Last(releaseName) @@ -752,7 +759,7 @@ func (h *Helm) delete(ctx context.Context, bundleID string, options fleet.Bundle if strings.HasPrefix(bundleID, "fleet-agent") { // Never uninstall the fleet-agent, just "forget" it - return deleteHistory(cfg, bundleID) + return deleteHistory(cfg, logger, bundleID) } u := action.NewUninstall(&cfg) @@ -760,21 +767,25 @@ func (h *Helm) delete(ctx context.Context, bundleID string, options fleet.Bundle u.Timeout = timeout if !dryRun { - logrus.Infof("Helm: Uninstalling %s", bundleID) + logger.Info("Helm: Uninstalling") } _, err = u.Run(releaseName) return err } func (h *Helm) createCfg(ctx context.Context, namespace string) (action.Configuration, error) { + logger := log.FromContext(ctx).WithName("helmSDK") + info := func(format string, v ...interface{}) { + logger.V(1).Info(fmt.Sprintf(format, v...)) + } kc := kube.New(h.getter) - kc.Log = logrus.Infof + kc.Log = info clientSet, err := kc.Factory.KubernetesClientSet() if err != nil { return action.Configuration{}, err } driver := driver.NewSecrets(helmcache.NewSecretClient(h.client, clientSet, namespace)) - driver.Log = logrus.Infof + driver.Log = info store := storage.Init(driver) store.MaxHistory = MaxHelmHistory @@ -782,11 +793,11 @@ func (h *Helm) createCfg(ctx context.Context, namespace string) (action.Configur RESTClientGetter: h.getter, Releases: store, KubeClient: kc, - Log: logrus.Infof, + Log: info, }, nil } -func deleteHistory(cfg action.Configuration, bundleID string) error { +func deleteHistory(cfg action.Configuration, logger logr.Logger, bundleID string) error { releases, err := cfg.Releases.List(func(r *release.Release) bool { return r.Name == bundleID && r.Chart.Metadata.Annotations[BundleIDAnnotation] == bundleID }) @@ -794,7 +805,7 @@ func deleteHistory(cfg action.Configuration, bundleID string) error { return err } for _, release := range releases { - logrus.Infof("Helm: Deleting release %s %d", release.Name, release.Version) + logger.Info("Helm: Deleting release", "releaseVersion", release.Version) if _, err := cfg.Releases.Delete(release.Name, release.Version); err != nil { return err }