Skip to content

Commit

Permalink
Merge pull request #149 from Abirdcfly/log
Browse files Browse the repository at this point in the history
fix: use right debug log level
  • Loading branch information
bjwswang authored Jul 21, 2023
2 parents 7dbc9a9 + 7c49699 commit 350b0e2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion controllers/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (r *ComponentReconciler) UpdateComponent(ctx context.Context, logger logr.L
if v, ok := instance.Labels[corev1alpha1.ComponentRepositoryLabel]; !ok || v != repoName {
// add component.repository=<repository-name> to labels
instance.Labels[corev1alpha1.ComponentRepositoryLabel] = repoName
logger.V(4).Info("Component repository label added", "Label", corev1alpha1.ComponentRepositoryLabel)
logger.V(1).Info("Component repository label added", "Label", corev1alpha1.ComponentRepositoryLabel)
err := r.Client.Update(ctx, instance)
if err != nil {
logger.Error(err, "Failed to add component repository label")
Expand Down
8 changes: 4 additions & 4 deletions controllers/componentplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ type ComponentPlanReconciler struct {
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
func (r *ComponentPlanReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(4).Info("Reconciling ComponentPlan")
logger.V(1).Info("Reconciling ComponentPlan")

// Fetch the ComponentPlan instance
plan := &corev1alpha1.ComponentPlan{}
err := r.Get(ctx, req.NamespacedName, plan)
if err != nil {
// There's no need to requeue if the resource no longer exists.
// Otherwise, we'll be requeued implicitly because we return an error.
logger.V(4).Info("Failed to get ComponentPlan")
logger.V(1).Info("Failed to get ComponentPlan")
return reconcile.Result{}, utils.IgnoreNotFound(err)
}
logger = logger.WithValues("Generation", plan.GetGeneration(), "ObservedGeneration", plan.Status.ObservedGeneration)
logger.V(4).Info("Get ComponentPlan instance")
logger.V(1).Info("Get ComponentPlan instance")

// Get watched component
component := &corev1alpha1.Component{}
Expand All @@ -104,7 +104,7 @@ func (r *ComponentPlanReconciler) Reconcile(ctx context.Context, req ctrl.Reques
logger.Info("Failed to get Component.Status.RepositoryRef, wait 1 minute to retry", "obj", klog.KObj(component))
return reconcile.Result{RequeueAfter: time.Minute}, nil
}
logger.V(4).Info("Get Component instance", "Component", klog.KObj(component))
logger.V(1).Info("Get Component instance", "Component", klog.KObj(component))

if plan.Labels[corev1alpha1.ComponentPlanReleaseNameLabel] != plan.Spec.Name {
if plan.GetLabels() == nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *RepositoryReconciler) UpdateRepository(ctx context.Context, logger logr

instanceDeepCopy.Finalizers = utils.AddString(instanceDeepCopy.Finalizers, corev1alpha1.Finalizer)
if l != len(instanceDeepCopy.Finalizers) {
logger.V(4).Info("Add Finalizer for repository", "Finalizer", corev1alpha1.Finalizer)
logger.V(1).Info("Add Finalizer for repository", "Finalizer", corev1alpha1.Finalizer)
err := r.Client.Update(ctx, instanceDeepCopy)
if err != nil {
logger.Error(err, "")
Expand All @@ -134,7 +134,7 @@ func (r *RepositoryReconciler) UpdateRepository(ctx context.Context, logger logr
}

if changed, history := utils.AddOrSwapString(instanceDeepCopy.Status.URLHistory, instanceDeepCopy.Spec.URL); changed {
logger.V(4).Info("Add URL for repository", "URL", instance.Spec.URL)
logger.V(1).Info("Add URL for repository", "URL", instance.Spec.URL)
instanceDeepCopy.Status.URLHistory = history
instanceDeepCopy.Status.ConditionedStatus = v1alpha1.ConditionedStatus{
Conditions: []v1alpha1.Condition{cond},
Expand Down
18 changes: 9 additions & 9 deletions controllers/subscription_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type SubscriptionReconciler struct {
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(4).Info("Reconciling Subscription")
logger.V(1).Info("Reconciling Subscription")

// Fetch the Subscription instance
sub := &corev1alpha1.Subscription{}
Expand All @@ -82,7 +82,7 @@ func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request
logger.Error(err, "Failed to get Subscription")
return reconcile.Result{}, utils.IgnoreNotFound(err)
}
logger.V(4).Info("Get Subscription instance")
logger.V(1).Info("Get Subscription instance")

// Get watched component
component := &corev1alpha1.Component{}
Expand All @@ -91,7 +91,7 @@ func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request
logger.Error(err, "Failed to get Component", "Component.Namespace", sub.Spec.ComponentRef.Namespace, "Component.Name", sub.Spec.ComponentRef.Name)
return reconcile.Result{}, utils.IgnoreNotFound(err)
}
logger.V(4).Info("Get Component instance", "Component.Namespace", component.Namespace, "Component.Name", component.Name)
logger.V(1).Info("Get Component instance", "Component.Namespace", component.Namespace, "Component.Name", component.Name)

// Update spec.repositoryRef
if sub.Spec.RepositoryRef == nil || sub.Spec.RepositoryRef.Name == "" {
Expand All @@ -109,7 +109,7 @@ func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request
logger.Error(err, "Failed to patch subscription.spec.RepositoryRef", "Repository.Namespace", newSub.Spec.RepositoryRef.Namespace, "Repository.Name", newSub.Spec.RepositoryRef.Name)
return ctrl.Result{Requeue: true}, r.PatchCondition(ctx, sub, corev1alpha1.SubscriptionReconcileError(corev1alpha1.SubscriptionTypeReady, err))
}
logger.V(4).Info("Patch subscription.Spec.RepositoryRef")
logger.V(1).Info("Patch subscription.Spec.RepositoryRef")
return ctrl.Result{Requeue: true}, nil
}

Expand All @@ -118,7 +118,7 @@ func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request
logger.Error(err, "Failed to update subscription status repositoryHealth", "RepositoryNamespace", sub.Spec.RepositoryRef.Namespace, "RepositoryName", sub.Spec.RepositoryRef.Name)
return ctrl.Result{Requeue: true}, r.PatchCondition(ctx, sub, corev1alpha1.SubscriptionReconcileError(corev1alpha1.SubscriptionTypeReady, err))
}
logger.V(4).Info("patch subscription status repositoryHealth")
logger.V(1).Info("patch subscription status repositoryHealth")

// compare component latest version with installed
var latestVersionFetch, latestVersionInstalled corev1alpha1.ComponentVersion
Expand All @@ -129,11 +129,11 @@ func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request
logger.Info(msg)
return ctrl.Result{}, r.PatchCondition(ctx, sub, corev1alpha1.SubscriptionReconcileSuccess(corev1alpha1.SubscriptionTypeReady).WithMessage(msg))
}
logger.V(4).Info("get component latest fetch version")
logger.V(1).Info("get component latest fetch version")
if plans := sub.Status.Installed; len(plans) > 0 {
latestVersionInstalled = plans[0].InstalledVersion
}
logger.V(4).Info("get component latest installed version")
logger.V(1).Info("get component latest installed version")
if latestVersionFetch.Equal(&latestVersionInstalled) {
msg := "component latest version is the same as installed, skip"
logger.Info(msg)
Expand All @@ -148,14 +148,14 @@ func (r *SubscriptionReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{Requeue: true, RequeueAfter: 3 * time.Second}, r.PatchCondition(ctx, sub, corev1alpha1.SubscriptionReconcileError(corev1alpha1.SubscriptionTypePlanSynce, err))
}
r.Recorder.Eventf(sub, v1.EventTypeNormal, "Success", "componentPlan %s create successfully", componentPlanName)
logger.V(4).Info("create component plan")
logger.V(1).Info("create component plan")

// update status.Installed
if err = r.UpdateStatusInstalled(ctx, logger, sub, latestVersionFetch); err != nil {
logger.Error(err, "Failed to update subscription status installed")
return ctrl.Result{Requeue: true, RequeueAfter: 3 * time.Second}, r.PatchCondition(ctx, sub, corev1alpha1.SubscriptionReconcileError(corev1alpha1.SubscriptionTypeReady, err))
}
logger.V(4).Info("update subscription status installed")
logger.V(1).Info("update subscription status installed")
return ctrl.Result{}, r.PatchCondition(ctx, sub, corev1alpha1.SubscriptionAvailable())
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type HelmWrapper struct {
func NewHelmWarpper(getter genericclioptions.RESTClientGetter, namespace string, logger logr.Logger) (*HelmWrapper, error) {
cfg := new(action.Configuration)
if err := cfg.Init(getter, namespace, os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {
logger.V(4).Info(fmt.Sprintf(format, v...))
logger.V(1).Info(fmt.Sprintf(format, v...))
}); err != nil {
return nil, err
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func (h *HelmWrapper) install(ctx context.Context, logger logr.Logger, cli clien
i.InsecureSkipTLSverify = repo.Spec.Insecure
i.PassCredentialsAll = false // TODO do we need add this args to override?
i.PostRenderer = newPostRenderer(repo.Spec.ImageOverride, cpl.Spec.Override.Images)
log.V(4).Info(fmt.Sprintf("Original chart version: %q", i.Version))
log.V(1).Info(fmt.Sprintf("Original chart version: %q", i.Version))

i.ReleaseName = cpl.GetReleaseName()
chartRequested, vals, err := h.prepare(ctx, cli, log, i.ChartPathOptions, cpl, chartName)
Expand Down Expand Up @@ -199,7 +199,7 @@ func (h *HelmWrapper) chartDownload(chartName string, logger logr.Logger, i acti
buf := new(strings.Builder)
defer func() {
for _, l := range strings.Split(buf.String(), "\n") {
logger.V(4).Info(l, "chartName", chartName)
logger.V(1).Info(l, "chartName", chartName)
}
}()
dl := downloader.ChartDownloader{
Expand Down Expand Up @@ -268,7 +268,7 @@ func (h *HelmWrapper) prepare(ctx context.Context, cli client.Client, logger log
if err != nil {
return nil, nil, err
}
logger.V(4).Info(fmt.Sprintf("CHART PATH: %s", cp))
logger.V(1).Info(fmt.Sprintf("CHART PATH: %s", cp))

p := getter.All(settings)
valueOpts := &values.Options{}
Expand All @@ -278,15 +278,15 @@ func (h *HelmWrapper) prepare(ctx context.Context, cli client.Client, logger log
return nil, nil, err
}
valueOpts.ValueFiles = append(valueOpts.ValueFiles, fileName)
logger.V(4).Info(fmt.Sprintf("Add Override.ValuesFrom From: %s", fileName))
logger.V(1).Info(fmt.Sprintf("Add Override.ValuesFrom From: %s", fileName))
}
if o := cpl.Spec.Override; o.Values != nil {
fileName, err := utils.ParseValues(o.GetValueFileDir(helmpath.CachePath(""), cpl.Namespace, cpl.Name), o.Values)
if err != nil {
return nil, nil, err
}
valueOpts.ValueFiles = append(valueOpts.ValueFiles, fileName)
logger.V(4).Info(fmt.Sprintf("Add Override.Values From: %s", fileName))
logger.V(1).Info(fmt.Sprintf("Add Override.Values From: %s", fileName))
}
if set := cpl.Spec.Override.Set; len(set) != 0 {
valueOpts.Values = cpl.Spec.Override.Set
Expand All @@ -310,7 +310,7 @@ func (h *HelmWrapper) prepare(ctx context.Context, cli client.Client, logger log
}

if chartRequested.Metadata.Deprecated {
logger.V(4).Info("This chart is deprecated")
logger.V(1).Info("This chart is deprecated")
}

if req := chartRequested.Metadata.Dependencies; req != nil {
Expand All @@ -328,7 +328,7 @@ func (h *HelmWrapper) prepare(ctx context.Context, cli client.Client, logger log
}
printLog := func() {
for _, l := range strings.Split(buf.String(), "\n") {
logger.V(4).Info(l)
logger.V(1).Info(l)
}
}
if err := man.Update(); err != nil {
Expand Down

0 comments on commit 350b0e2

Please sign in to comment.