diff --git a/controllers/pkg/reconcilers/approval/reconciler.go b/controllers/pkg/reconcilers/approval/reconciler.go index 1e0bcda8..6f78ec51 100644 --- a/controllers/pkg/reconcilers/approval/reconciler.go +++ b/controllers/pkg/reconcilers/approval/reconciler.go @@ -32,7 +32,6 @@ import ( "k8s.io/client-go/tools/record" porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" - "github.com/go-logr/logr" porchclient "github.com/nephio-project/nephio/controllers/pkg/porch/client" porchconds "github.com/nephio-project/nephio/controllers/pkg/porch/condition" porchutil "github.com/nephio-project/nephio/controllers/pkg/porch/util" @@ -84,20 +83,18 @@ type reconciler struct { porchClient client.Client porchRESTClient rest.Interface recorder record.EventRecorder - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx).WithValues("req", req) - r.l.Info("reconcile approval") + log := log.FromContext(ctx).WithValues("req", req) + log.Info("reconcile approval") pr := &porchv1alpha1.PackageRevision{} if err := r.Get(ctx, req.NamespacedName, pr); err != nil { // There's no need to requeue if we no longer exist. Otherwise we'll be // requeued implicitly because we return an error. if resource.IgnoreNotFound(err) != nil { - r.l.Error(err, "cannot get resource") + log.Error(err, "cannot get resource") return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), "cannot get resource") } return ctrl.Result{}, nil diff --git a/controllers/pkg/reconcilers/bootstrap-packages/reconciler.go b/controllers/pkg/reconcilers/bootstrap-packages/reconciler.go index d80d4486..1fbbfe79 100644 --- a/controllers/pkg/reconcilers/bootstrap-packages/reconciler.go +++ b/controllers/pkg/reconcilers/bootstrap-packages/reconciler.go @@ -26,7 +26,6 @@ import ( porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" porchconfigv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porchconfig/v1alpha1" - "github.com/go-logr/logr" "github.com/nephio-project/nephio/controllers/pkg/cluster" ctrlconfig "github.com/nephio-project/nephio/controllers/pkg/reconcilers/config" reconcilerinterface "github.com/nephio-project/nephio/controllers/pkg/reconcilers/reconciler-interface" @@ -89,19 +88,17 @@ func (r *reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, c a type reconciler struct { client.Client porchClient client.Client - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx) + log := log.FromContext(ctx) cr := &porchv1alpha1.PackageRevision{} if err := r.Get(ctx, req.NamespacedName, cr); err != nil { // There's no need to requeue if we no longer exist. Otherwise we'll be // requeued implicitly because we return an error. if resource.IgnoreNotFound(err) != nil { msg := "cannot get resource" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), msg) } return ctrl.Result{}, nil @@ -112,15 +109,15 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu stagingPR, err := r.IsStagingPackageRevision(ctx, cr) if err != nil { msg := "cannot list repositories" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(err, msg) } if stagingPR && porchv1alpha1.LifecycleIsPublished(cr.Spec.Lifecycle) { - r.l.Info("reconcile package revision") + log.Info("reconcile package revision") resources, namespacePresent, err := r.getResources(ctx, req) if err != nil { msg := "cannot get resources" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(err, msg) } // we expect the clusterName to be applied to all resources in the @@ -129,7 +126,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if len(resources) > 0 { clusterName, ok := resources[0].GetAnnotations()[clusterNameKey] if !ok { - r.l.Info("clusterName not found", + log.Info("clusterName not found", "resource", fmt.Sprintf("%s.%s.%s", resources[0].GetAPIVersion(), resources[0].GetKind(), resources[0].GetName()), "annotations", resources[0].GetAnnotations()) return ctrl.Result{}, nil @@ -138,7 +135,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu secrets := &corev1.SecretList{} if err := r.List(ctx, secrets); err != nil { msg := "cannot list secrets" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(err, msg) } found := false @@ -151,11 +148,11 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu clusterClient, ready, err := clusterClient.GetClusterClient(ctx) if err != nil { msg := "cannot get clusterClient" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{RequeueAfter: 30 * time.Second}, errors.Wrap(err, msg) } if !ready { - r.l.Info("cluster not ready") + log.Info("cluster not ready") return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } if !namespacePresent { @@ -163,22 +160,22 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err = clusterClient.Get(ctx, types.NamespacedName{Name: configsyncNamespace}, ns); err != nil { if resource.IgnoreNotFound(err) != nil { msg := fmt.Sprintf("cannot get namespace: %s", configsyncNamespace) - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{RequeueAfter: 30 * time.Second}, errors.Wrap(err, msg) } msg := fmt.Sprintf("namespace: %s, does not exist, retry...", configsyncNamespace) - r.l.Info(msg) + log.Info(msg) return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } } // install resources for _, resource := range resources { resource := resource // required to prevent gosec warning: G601 (CWE-118): Implicit memory aliasing in for loop - r.l.Info("install manifest", "resource", + log.Info("install manifest", "resource", fmt.Sprintf("%s.%s.%s", resource.GetAPIVersion(), resource.GetKind(), resource.GetName())) if err := clusterClient.Apply(ctx, &resource); err != nil { msg := fmt.Sprintf("cannot apply resource to cluster: resourceName: %s", resource.GetName()) - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(err, msg) } } @@ -187,7 +184,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if !found { // the cluster client was not found, we retry - r.l.Info("cluster client not found, retry...") + log.Info("cluster client not found, retry...") return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } } @@ -219,11 +216,11 @@ func (r *reconciler) IsStagingPackageRevision(ctx context.Context, cr *porchv1al func (r *reconciler) getResources(ctx context.Context, req ctrl.Request) ([]unstructured.Unstructured, bool, error) { prr := &porchv1alpha1.PackageRevisionResources{} if err := r.porchClient.Get(ctx, req.NamespacedName, prr); err != nil { - r.l.Error(err, "cannot get package revision resourcelist", "key", req.NamespacedName) + log.FromContext(ctx).Error(err, "cannot get package revision resourcelist", "key", req.NamespacedName) return nil, false, err } - return r.getResourcesPRR(prr.Spec.Resources) + return r.getResourcesPRR(ctx, prr.Spec.Resources) } func includeFile(path string, match []string) bool { @@ -236,7 +233,7 @@ func includeFile(path string, match []string) bool { return false } -func (r *reconciler) getResourcesPRR(resources map[string]string) ([]unstructured.Unstructured, bool, error) { +func (r *reconciler) getResourcesPRR(ctx context.Context, resources map[string]string) ([]unstructured.Unstructured, bool, error) { inputs := []kio.Reader{} for path, data := range resources { if includeFile(path, []string{"*.yaml", "*.yml", "Kptfile"}) { @@ -267,7 +264,7 @@ func (r *reconciler) getResourcesPRR(resources map[string]string) ([]unstructure } u := unstructured.Unstructured{} if err := yaml.Unmarshal([]byte(n.MustString()), &u); err != nil { - r.l.Error(err, "cannot unmarshal data", "data", n.MustString()) + log.FromContext(ctx).Error(err, "cannot unmarshal data", "data", n.MustString()) // we don't fail continue } diff --git a/controllers/pkg/reconcilers/bootstrap-packages/reconciler_test.go b/controllers/pkg/reconcilers/bootstrap-packages/reconciler_test.go index 1129ce54..9554b1be 100644 --- a/controllers/pkg/reconcilers/bootstrap-packages/reconciler_test.go +++ b/controllers/pkg/reconcilers/bootstrap-packages/reconciler_test.go @@ -17,6 +17,7 @@ limitations under the License. package bootstrappackages import ( + "context" "fmt" "testing" @@ -75,7 +76,7 @@ spec: for name, tc := range cases { t.Run(name, func(t *testing.T) { r := reconciler{} - us, _, err := r.getResourcesPRR(tc.resources) + us, _, err := r.getResourcesPRR(context.Background(), tc.resources) if tc.expectedErr { assert.Error(t, err) diff --git a/controllers/pkg/reconcilers/bootstrap-secret/reconciler.go b/controllers/pkg/reconcilers/bootstrap-secret/reconciler.go index 0f371a26..bcda3605 100644 --- a/controllers/pkg/reconcilers/bootstrap-secret/reconciler.go +++ b/controllers/pkg/reconcilers/bootstrap-secret/reconciler.go @@ -22,7 +22,6 @@ import ( "strings" "time" - "github.com/go-logr/logr" "github.com/nephio-project/nephio/controllers/pkg/cluster" reconcilerinterface "github.com/nephio-project/nephio/controllers/pkg/reconcilers/reconciler-interface" "github.com/nephio-project/nephio/controllers/pkg/resource" @@ -66,19 +65,17 @@ func (r *reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, c a type reconciler struct { client.Client - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx) + log := log.FromContext(ctx) cr := &corev1.Secret{} if err := r.Get(ctx, req.NamespacedName, cr); err != nil { // if the resource no longer exists the reconcile loop is done if resource.IgnoreNotFound(err) != nil { msg := "cannot get resource" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), msg) } return reconcile.Result{}, nil @@ -96,13 +93,13 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if cr.GetAnnotations()[nephioAppKey] == configsyncApp && cr.GetAnnotations()[clusterNameKey] != "" && cr.GetAnnotations()[clusterNameKey] != "mgmt" { - r.l.Info("reconcile secret") + log.Info("reconcile secret") clusterName := cr.GetAnnotations()[clusterNameKey] secrets := &corev1.SecretList{} if err := r.List(ctx, secrets); err != nil { msg := "cannot list secrets" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(err, msg) } found := false @@ -115,11 +112,11 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu clusterClient, ready, err := clusterClient.GetClusterClient(ctx) if err != nil { msg := "cannot get clusterClient" - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{RequeueAfter: 30 * time.Second}, errors.Wrap(err, msg) } if !ready { - r.l.Info("cluster not ready") + log.Info("cluster not ready") return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } // check if namespace exists, if not retry @@ -127,11 +124,11 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if err = clusterClient.Get(ctx, types.NamespacedName{Name: configsyncNamespace}, ns); err != nil { if resource.IgnoreNotFound(err) != nil { msg := fmt.Sprintf("cannot get namespace: %s", configsyncNamespace) - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{RequeueAfter: 30 * time.Second}, errors.Wrap(err, msg) } msg := fmt.Sprintf("namespace: %s, does not exist, retry...", configsyncNamespace) - r.l.Info(msg) + log.Info(msg) return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } @@ -145,10 +142,10 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu }) newcr.ResourceVersion = "" newcr.UID = "" - r.l.Info("secret info", "secret", newcr.Annotations) + log.Info("secret info", "secret", newcr.Annotations) if err := clusterClient.Apply(ctx, newcr); err != nil { msg := fmt.Sprintf("cannot apply secret to cluster %s", clusterName) - r.l.Error(err, msg) + log.Error(err, msg) return ctrl.Result{}, errors.Wrap(err, msg) } } @@ -156,7 +153,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if !found { // the cluster client was not found, we retry - r.l.Info("cluster client not found, retry...") + log.Info("cluster client not found, retry...") return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } } diff --git a/controllers/pkg/reconcilers/generic-specializer/reconciler.go b/controllers/pkg/reconcilers/generic-specializer/reconciler.go index d8f1ea6a..6519d364 100644 --- a/controllers/pkg/reconcilers/generic-specializer/reconciler.go +++ b/controllers/pkg/reconcilers/generic-specializer/reconciler.go @@ -25,7 +25,6 @@ import ( "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" kptv1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1" porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" - "github.com/go-logr/logr" infrav1alpha1 "github.com/nephio-project/api/infra/v1alpha1" porchcondition "github.com/nephio-project/nephio/controllers/pkg/porch/condition" porchutil "github.com/nephio-project/nephio/controllers/pkg/porch/util" @@ -89,20 +88,18 @@ type reconciler struct { vlanClientProxy clientproxy.Proxy[*vlanv1alpha1.VLANIndex, *vlanv1alpha1.VLANClaim] porchClient client.Client recorder record.EventRecorder - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx).WithValues("req", req) - r.l.Info("reconcile genericspecializer") + log := log.FromContext(ctx).WithValues("req", req) + log.Info("reconcile genericspecializer") pr := &porchv1alpha1.PackageRevision{} if err := r.Get(ctx, req.NamespacedName, pr); err != nil { // There's no need to requeue if we no longer exist. Otherwise we'll be // requeued implicitly because we return an error. if resource.IgnoreNotFound(err) != nil { - r.l.Error(err, "cannot get resource") + log.Error(err, "cannot get resource") return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), "cannot get resource") } return ctrl.Result{}, nil @@ -146,14 +143,14 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu prr := &porchv1alpha1.PackageRevisionResources{} if err := r.porchClient.Get(ctx, req.NamespacedName, prr); err != nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", fmt.Sprintf("cannot get package revision resources: %s", err.Error())) - r.l.Error(err, "cannot get package revision resources") + log.Error(err, "cannot get package revision resources") return ctrl.Result{}, errors.Wrap(err, "cannot get package revision resources") } // get resourceList from resources rl, err := kptrl.GetResourceList(prr.Spec.Resources) if err != nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", fmt.Sprintf("cannot get resourceList: %s", err.Error())) - r.l.Error(err, "cannot get resourceList") + log.Error(err, "cannot get resourceList") return ctrl.Result{}, errors.Wrap(err, "cannot get resourceList") } @@ -162,40 +159,40 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu _, err = ipamkrmfn.Process(rl) if err != nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", fmt.Sprintf("ipam function: %s", err.Error())) - r.l.Error(err, "ipam function run failed") + log.Error(err, "ipam function run failed") return ctrl.Result{}, nil } - r.l.Info("ipam specializer fn run successful") + log.Info("ipam specializer fn run successful") } if porchcondition.HasSpecificTypeConditions(pr.Status.Conditions, kptfilelibv1.GetConditionType(&vlanFor)) { // run the function SDK _, err = vlankrmfn.Process(rl) if err != nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", fmt.Sprintf("vlan function: %s", err.Error())) - r.l.Error(err, "vlan function run failed") + log.Error(err, "vlan function run failed") return ctrl.Result{}, nil } - r.l.Info("vlan specializer fn run successful") + log.Info("vlan specializer fn run successful") } if porchcondition.HasSpecificTypeConditions(pr.Status.Conditions, kptfilelibv1.GetConditionType(&configInjectFor)) { // run the function SDK _, err = configInjectkrmfn.Process(rl) if err != nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", fmt.Sprintf("configInject function: %s", err.Error())) - r.l.Error(err, "configInject function run failed") + log.Error(err, "configInject function run failed") return ctrl.Result{}, nil } - r.l.Info("configInject specializer fn run successful") + log.Info("configInject specializer fn run successful") } workloadClusterObjs := rl.Items.Where(fn.IsGroupVersionKind(infrav1alpha1.WorkloadClusterGroupVersionKind)) - clusterName := r.getClusterName(workloadClusterObjs) + clusterName := r.getClusterName(ctx, workloadClusterObjs) // We want to process the functions to refresh the claims // but if the package is in publish state the updates cannot be done // so we stop here if porchv1alpha1.LifecycleIsPublished(pr.Spec.Lifecycle) { r.recorder.Event(pr, corev1.EventTypeNormal, "CannotRefreshClaims", "package is published, no update possible") - r.l.Info("package is published, no updates possible", + log.Info("package is published, no updates possible", "repo", pr.Spec.RepositoryName, "package", pr.Spec.PackageName, "rev", pr.Spec.Revision, @@ -212,34 +209,34 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // Debug alloc, err := kubeobject.NewFromKubeObject[ipamv1alpha1.IPClaim](o) if err != nil { - r.l.Error(err, "cannot get extended kubeobject") + log.Error(err, "cannot get extended kubeobject") continue } ipAlloc, err := alloc.GetGoStruct() if err != nil { - r.l.Error(err, "cannot get gostruct from kubeobject") + log.Error(err, "cannot get gostruct from kubeobject") continue } - r.l.Info("generic specializer ip allocation", "clusterName", clusterName, "status", ipAlloc.Status) + log.Info("generic specializer ip allocation", "clusterName", clusterName, "status", ipAlloc.Status) } if o.GetAPIVersion() == vlanFor.APIVersion && o.GetKind() == vlanFor.Kind { prr.Spec.Resources[o.GetAnnotation(kioutil.PathAnnotation)] = o.String() // Debug alloc, err := kubeobject.NewFromKubeObject[vlanv1alpha1.VLANClaim](o) if err != nil { - r.l.Error(err, "cannot get extended kubeobject") + log.Error(err, "cannot get extended kubeobject") continue } vlanAlloc, err := alloc.GetGoStruct() if err != nil { - r.l.Error(err, "cannot get gostruct from kubeobject") + log.Error(err, "cannot get gostruct from kubeobject") continue } - r.l.Info("generic specializer vlan allocation", "clusterName", clusterName, "status", vlanAlloc.Status) + log.Info("generic specializer vlan allocation", "clusterName", clusterName, "status", vlanAlloc.Status) } if o.GetAPIVersion() == configInjectFor.APIVersion && o.GetKind() == configInjectFor.Kind { prr.Spec.Resources[o.GetAnnotation(kioutil.PathAnnotation)] = o.String() - r.l.Info("generic specializer config injector", "clusterName", clusterName, "resourceName", fmt.Sprintf("%s/%s", configInjectFor.Kind, o.GetName())) + log.Info("generic specializer config injector", "clusterName", clusterName, "resourceName", fmt.Sprintf("%s/%s", configInjectFor.Kind, o.GetName())) } for own := range configInjectf.GetConfig().Owns { if o.GetAPIVersion() == own.APIVersion && o.GetKind() == own.Kind { @@ -253,33 +250,33 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } else { prr.Spec.Resources[o.GetAnnotation(kioutil.PathAnnotation)] = o.String() } - r.l.Info("generic specializer", "kind", own.Kind, "pathAnnotation", o.GetAnnotation(kioutil.PathAnnotation)) - r.l.Info("generic specializer config injector", "clusterName", clusterName, "resourceName", fmt.Sprintf("%s/%s", own.Kind, o.GetName())) - r.l.Info("generic specializer config injector", "object", o.String()) + log.Info("generic specializer", "kind", own.Kind, "pathAnnotation", o.GetAnnotation(kioutil.PathAnnotation)) + log.Info("generic specializer config injector", "clusterName", clusterName, "resourceName", fmt.Sprintf("%s/%s", own.Kind, o.GetName())) + log.Info("generic specializer config injector", "object", o.String()) } } if o.GetAPIVersion() == "kpt.dev/v1" && o.GetKind() == "Kptfile" { - r.l.Info("generic specializer", "pathAnnotation", o.GetAnnotation(kioutil.PathAnnotation), "kptfile", o.String()) + log.Info("generic specializer", "pathAnnotation", o.GetAnnotation(kioutil.PathAnnotation), "kptfile", o.String()) prr.Spec.Resources[o.GetAnnotation(kioutil.PathAnnotation)] = o.String() // debug - r.l.Info("generic specializer object kptfile", "packageName", pr.Spec.PackageName, "repository", pr.Spec.RepositoryName, "kptfile", o) + log.Info("generic specializer object kptfile", "packageName", pr.Spec.PackageName, "repository", pr.Spec.RepositoryName, "kptfile", o) kptf, err := kubeobject.NewFromKubeObject[kptv1.KptFile](o) if err != nil { - r.l.Error(err, "cannot get extended kubeobject") + log.Error(err, "cannot get extended kubeobject") continue } kptfile, err := kptf.GetGoStruct() if err != nil { - r.l.Error(err, "cannot get gostruct from kubeobject") + log.Error(err, "cannot get gostruct from kubeobject") continue } for _, c := range kptfile.Status.Conditions { if strings.HasPrefix(c.Type, kptfilelibv1.GetConditionType(&vlanFor)+".") || strings.HasPrefix(c.Type, kptfilelibv1.GetConditionType(&ipamFor)+".") || strings.HasPrefix(c.Type, kptfilelibv1.GetConditionType(&configInjectFor)+".") { - r.l.Info("generic specializer conditions", "packageName", pr.Spec.PackageName, "repository", pr.Spec.RepositoryName, "status", c.Status, "condition", c.Type, "message", c.Message) + log.Info("generic specializer conditions", "packageName", pr.Spec.PackageName, "repository", pr.Spec.RepositoryName, "status", c.Status, "condition", c.Type, "message", c.Message) } } } @@ -288,35 +285,35 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu kptfile := rl.Items.GetRootKptfile() if kptfile == nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", "mandatory Kptfile is missing") - r.l.Error(err, "mandatory Kptfile is missing from the package") + log.Error(err, "mandatory Kptfile is missing from the package") return ctrl.Result{}, nil } - r.l.Info("generic specializer root kptfile", "packageName", pr.Spec.PackageName, "repository", pr.Spec.RepositoryName, "kptfile", kptfile) + log.Info("generic specializer root kptfile", "packageName", pr.Spec.PackageName, "repository", pr.Spec.RepositoryName, "kptfile", kptfile) kptf := kptfilelibv1.KptFile{Kptfile: rl.Items.GetRootKptfile()} pr.Status.Conditions = porchcondition.GetPorchConditions(kptf.GetConditions()) // TODO do we need to update the status? if err = r.porchClient.Update(ctx, prr); err != nil { r.recorder.Event(pr, corev1.EventTypeWarning, "ReconcileError", "cannot update packagerevision resources") - r.l.Error(err, "cannot update packagerevision resources") + log.Error(err, "cannot update packagerevision resources") return ctrl.Result{}, err } } return ctrl.Result{}, nil } -func (r *reconciler) getClusterName(workloadClusterObjs fn.KubeObjects) string { +func (r *reconciler) getClusterName(ctx context.Context, workloadClusterObjs fn.KubeObjects) string { clusterName := "" if len(workloadClusterObjs) > 0 { cluster, err := kubeobject.NewFromKubeObject[infrav1alpha1.WorkloadCluster](workloadClusterObjs[0]) if err != nil { - r.l.Error(err, "cannot get extended kubeobject") + log.FromContext(ctx).Error(err, "cannot get extended kubeobject") return clusterName } workloadCluster, err := cluster.GetGoStruct() if err != nil { - r.l.Error(err, "cannot get gostruct from kubeobject") + log.FromContext(ctx).Error(err, "cannot get gostruct from kubeobject") return clusterName } clusterName = workloadCluster.Spec.ClusterName diff --git a/controllers/pkg/reconcilers/ipam-specializer/reconciler.go b/controllers/pkg/reconcilers/ipam-specializer/reconciler.go index 90d13bad..485bf110 100644 --- a/controllers/pkg/reconcilers/ipam-specializer/reconciler.go +++ b/controllers/pkg/reconcilers/ipam-specializer/reconciler.go @@ -31,7 +31,6 @@ import ( "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" - "github.com/go-logr/logr" "github.com/nephio-project/nephio/controllers/pkg/resource" function "github.com/nephio-project/nephio/krm-functions/ipam-fn/fn" kptfilelibv1 "github.com/nephio-project/nephio/krm-functions/lib/kptfile/v1" @@ -87,20 +86,18 @@ type reconciler struct { For corev1.ObjectReference porchClient client.Client krmfn fn.ResourceListProcessor - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx).WithValues("req", req) - r.l.Info("reconcile specializer") + log := log.FromContext(ctx).WithValues("req", req) + log.Info("reconcile specializer") pr := &porchv1alpha1.PackageRevision{} if err := r.Get(ctx, req.NamespacedName, pr); err != nil { // There's no need to requeue if we no longer exist. Otherwise we'll be // requeued implicitly because we return an error. if resource.IgnoreNotFound(err) != nil { - r.l.Error(err, "cannot get resource") + log.Error(err, "cannot get resource") return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), "cannot get resource") } return ctrl.Result{}, nil @@ -112,32 +109,32 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // get package revision resourceList prr := &porchv1alpha1.PackageRevisionResources{} if err := r.porchClient.Get(ctx, req.NamespacedName, prr); err != nil { - r.l.Error(err, "cannot get package revision resources") + log.Error(err, "cannot get package revision resources") return ctrl.Result{}, errors.Wrap(err, "cannot get package revision resources") } // get resourceList from resources rl, err := kptrl.GetResourceList(prr.Spec.Resources) if err != nil { - r.l.Error(err, "cannot get resourceList") + log.Error(err, "cannot get resourceList") return ctrl.Result{}, errors.Wrap(err, "cannot get resourceList") } // run the function SDK _, err = r.krmfn.Process(rl) if err != nil { - r.l.Error(err, "function run failed") + log.Error(err, "function run failed") // TBD if we need to return here + check if kptfile is set //return ctrl.Result{}, errors.Wrap(err, "function run failed") } for _, o := range rl.Items { - r.l.Info("resourceList", "data", o.String()) + log.Info("resourceList", "data", o.String()) // TBD what if we create new resources // update the resources with the latest info prr.Spec.Resources[o.GetAnnotation(kioutil.PathAnnotation)] = o.String() } kptfile := rl.Items.GetRootKptfile() if kptfile == nil { - r.l.Error(fmt.Errorf("mandatory Kptfile is missing from the package"), "") + log.Error(fmt.Errorf("mandatory Kptfile is missing from the package"), "") return ctrl.Result{}, nil } diff --git a/controllers/pkg/reconcilers/network/reconciler.go b/controllers/pkg/reconcilers/network/reconciler.go index 945ede5b..e8ebf223 100644 --- a/controllers/pkg/reconcilers/network/reconciler.go +++ b/controllers/pkg/reconcilers/network/reconciler.go @@ -21,7 +21,6 @@ import ( "fmt" "reflect" - "github.com/go-logr/logr" configv1alpha1 "github.com/henderiw-nephio/network/apis/config/v1alpha1" infra2v1alpha1 "github.com/henderiw-nephio/network/apis/infra2/v1alpha1" "github.com/henderiw-nephio/network/pkg/endpoints" @@ -128,21 +127,20 @@ type reconciler struct { IpamClientProxy clientproxy.Proxy[*ipamv1alpha1.NetworkInstance, *ipamv1alpha1.IPClaim] VlanClientProxy clientproxy.Proxy[*vlanv1alpha1.VLANIndex, *vlanv1alpha1.VLANClaim] - l logr.Logger devices map[string]*ygotsrl.Device //targets targets.Target resources resources.Resources // get initialized for every cr/reconcile loop } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx) - r.l.Info("reconcile", "req", req) + log := log.FromContext(ctx) + log.Info("reconcile", "req", req) cr := &infrav1alpha1.Network{} if err := r.Get(ctx, req.NamespacedName, cr); err != nil { // if the resource no longer exists the reconcile loop is done if resource.IgnoreNotFound(err) != nil { - r.l.Error(err, errGetCr) + log.Error(err, errGetCr) return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), errGetCr) } return ctrl.Result{}, nil @@ -154,32 +152,32 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu if meta.WasDeleted(cr) { if err := r.finalizer.RemoveFinalizer(ctx, cr); err != nil { - r.l.Error(err, "cannot remove finalizer") + log.Error(err, "cannot remove finalizer") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } - r.l.Info("Successfully deleted resource") + log.Info("Successfully deleted resource") return ctrl.Result{Requeue: false}, nil } // add finalizer to avoid deleting the token w/o it being deleted from the git server if err := r.finalizer.AddFinalizer(ctx, cr); err != nil { - r.l.Error(err, "cannot add finalizer") + log.Error(err, "cannot add finalizer") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } eps, err := r.getProviderEndpoints(ctx, cr.Spec.Topology) if err != nil { - r.l.Error(err, "cannot list provider endpoints") + log.Error(err, "cannot list provider endpoints") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } nodes, err := r.getProviderNodes(ctx, cr.Spec.Topology) if err != nil { - r.l.Error(err, "cannot list provider nodes") + log.Error(err, "cannot list provider nodes") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } @@ -195,23 +193,23 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu }, ) - r.l.Info("apply initial resources") + log.Info("apply initial resources") if err := r.applyInitialresources(ctx, cr, eps, nodes); err != nil { - r.l.Error(err, "cannot apply initial resources") + log.Error(err, "cannot apply initial resources") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } - r.l.Info("get new resources") + log.Info("get new resources") if err := r.getNewResources(ctx, cr, eps, nodes); err != nil { - r.l.Error(err, "cannot get new resources") + log.Error(err, "cannot get new resources") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } - r.l.Info("apply all resources") + log.Info("apply all resources") if err := r.resources.APIApply(ctx); err != nil { - r.l.Error(err, "cannot apply resources to the API") + log.Error(err, "cannot apply resources to the API") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } @@ -235,7 +233,7 @@ func (r *reconciler) getProviderEndpoints(ctx context.Context, topology string) } eps := &invv1alpha1.EndpointList{} if err := r.List(ctx, eps, opts...); err != nil { - r.l.Error(err, "cannot list endpoints") + log.FromContext(ctx).Error(err, "cannot list endpoints") return nil, err } return &endpoints.Endpoints{EndpointList: eps}, nil @@ -250,7 +248,7 @@ func (r *reconciler) getProviderNodes(ctx context.Context, topology string) (*no } nos := &invv1alpha1.NodeList{} if err := r.List(ctx, nos, opts...); err != nil { - r.l.Error(err, "cannot list nodes") + log.FromContext(ctx).Error(err, "cannot list nodes") return nil, err } return &nodes.Nodes{NodeList: nos}, nil @@ -268,11 +266,11 @@ func (r *reconciler) applyInitialresources(ctx context.Context, cr *infrav1alpha }) if err := n.Run(ctx, cr); err != nil { - r.l.Error(err, "cannot execute network run") + log.FromContext(ctx).Error(err, "cannot execute network run") return err } if err := r.resources.APIApply(ctx); err != nil { - r.l.Error(err, "cannot apply resources to the API") + log.FromContext(ctx).Error(err, "cannot apply resources to the API") return err } return nil @@ -290,7 +288,7 @@ func (r *reconciler) getNewResources(ctx context.Context, cr *infrav1alpha1.Netw }) if err := n.Run(ctx, cr); err != nil { - r.l.Error(err, "cannot execute network run") + log.FromContext(ctx).Error(err, "cannot execute network run") return err } @@ -309,7 +307,7 @@ func (r *reconciler) getNewResources(ctx context.Context, cr *infrav1alpha1.Netw } for nodeName, device := range n.GetDevices() { - r.l.Info("node config", "nodeName", nodeName) + log.FromContext(ctx).Info("node config", "nodeName", nodeName) j, err := ygot.EmitJSON(device, &ygot.EmitJSONConfig{ Format: ygot.RFC7951, @@ -320,7 +318,7 @@ func (r *reconciler) getNewResources(ctx context.Context, cr *infrav1alpha1.Netw SkipValidation: false, }) if err != nil { - r.l.Error(err, "cannot construct json device info") + log.FromContext(ctx).Error(err, "cannot construct json device info") return err } diff --git a/controllers/pkg/reconcilers/network/watch_endpoint.go b/controllers/pkg/reconcilers/network/watch_endpoint.go index 9bd5c975..e4eb0578 100644 --- a/controllers/pkg/reconcilers/network/watch_endpoint.go +++ b/controllers/pkg/reconcilers/network/watch_endpoint.go @@ -19,7 +19,6 @@ package network import ( "context" - "github.com/go-logr/logr" infrav1alpha1 "github.com/nephio-project/api/infra/v1alpha1" invv1alpha1 "github.com/nokia/k8s-ipam/apis/inv/v1alpha1" "k8s.io/apimachinery/pkg/runtime" @@ -33,7 +32,6 @@ import ( type endpointEventHandler struct { client client.Client - l logr.Logger } // Create enqueues a request for all ip allocation within the ipam @@ -62,8 +60,8 @@ func (e *endpointEventHandler) add(ctx context.Context, obj runtime.Object, queu if !ok { return } - e.l = log.FromContext(ctx) - e.l.Info("event", "kind", obj.GetObjectKind(), "name", cr.GetName()) + log := log.FromContext(ctx) + log.Info("event", "kind", obj.GetObjectKind(), "name", cr.GetName()) networks := &infrav1alpha1.NetworkList{} if err := e.client.List(ctx, networks); err != nil { @@ -74,7 +72,7 @@ func (e *endpointEventHandler) add(ctx context.Context, obj runtime.Object, queu // only enqueue if the provider and the network topology match if cr.Labels[invv1alpha1.NephioProviderKey] == nokiaSRLProvider && cr.Labels[invv1alpha1.NephioTopologyKey] == network.Spec.Topology { - e.l.Info("event requeue network", "name", network.GetName()) + log.Info("event requeue network", "name", network.GetName()) queue.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Namespace: network.GetNamespace(), Name: network.GetName()}}) diff --git a/controllers/pkg/reconcilers/network/watch_node.go b/controllers/pkg/reconcilers/network/watch_node.go index e7637122..fd70508b 100644 --- a/controllers/pkg/reconcilers/network/watch_node.go +++ b/controllers/pkg/reconcilers/network/watch_node.go @@ -19,7 +19,6 @@ package network import ( "context" - "github.com/go-logr/logr" infrav1alpha1 "github.com/nephio-project/api/infra/v1alpha1" invv1alpha1 "github.com/nokia/k8s-ipam/apis/inv/v1alpha1" "k8s.io/apimachinery/pkg/runtime" @@ -33,7 +32,6 @@ import ( type nodeEventHandler struct { client client.Client - l logr.Logger } // Create enqueues a request for all ip allocation within the ipam @@ -62,8 +60,8 @@ func (e *nodeEventHandler) add(ctx context.Context, obj runtime.Object, queue ad if !ok { return } - e.l = log.FromContext(ctx) - e.l.Info("event", "kind", obj.GetObjectKind(), "name", cr.GetName()) + log := log.FromContext(ctx) + log.Info("event", "kind", obj.GetObjectKind(), "name", cr.GetName()) networks := &infrav1alpha1.NetworkList{} if err := e.client.List(ctx, networks); err != nil { @@ -74,7 +72,7 @@ func (e *nodeEventHandler) add(ctx context.Context, obj runtime.Object, queue ad // only enqueue if the provider and the network topology match if cr.Labels[invv1alpha1.NephioProviderKey] == nokiaSRLProvider && cr.Labels[invv1alpha1.NephioTopologyKey] == network.Spec.Topology { - e.l.Info("event requeue network", "name", network.GetName()) + log.Info("event requeue network", "name", network.GetName()) queue.Add(reconcile.Request{NamespacedName: types.NamespacedName{ Namespace: network.GetNamespace(), Name: network.GetName()}}) diff --git a/controllers/pkg/reconcilers/token/reconciler.go b/controllers/pkg/reconcilers/token/reconciler.go index acae009c..c3c325bf 100644 --- a/controllers/pkg/reconcilers/token/reconciler.go +++ b/controllers/pkg/reconcilers/token/reconciler.go @@ -22,7 +22,6 @@ import ( "reflect" "code.gitea.io/sdk/gitea" - "github.com/go-logr/logr" commonv1alpha1 "github.com/nephio-project/api/common/v1alpha1" infrav1alpha1 "github.com/nephio-project/api/infra/v1alpha1" "github.com/nephio-project/nephio/controllers/pkg/giteaclient" @@ -88,19 +87,17 @@ type reconciler struct { resource.APIPatchingApplicator giteaClient giteaclient.GiteaClient finalizer *resource.APIFinalizer - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx) - r.l.Info("reconcile", "req", req) + log := log.FromContext(ctx) + log.Info("reconcile", "req", req) cr := &infrav1alpha1.Token{} if err := r.Get(ctx, req.NamespacedName, cr); err != nil { // if the resource no longer exists the reconcile loop is done if resource.IgnoreNotFound(err) != nil { - r.l.Error(err, "cannot get resource") + log.Error(err, "cannot get resource") return ctrl.Result{Requeue: true}, errors.Wrap(resource.IgnoreNotFound(err), "cannot get resource") } return ctrl.Result{}, nil @@ -110,7 +107,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu giteaClient := r.giteaClient.Get() if giteaClient == nil { err := fmt.Errorf("gitea server unreachable") - r.l.Error(err, "cannot connect to gitea server") + log.Error(err, "cannot connect to gitea server") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } @@ -127,18 +124,18 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } if err := r.finalizer.RemoveFinalizer(ctx, cr); err != nil { - r.l.Error(err, "cannot remove finalizer") + log.Error(err, "cannot remove finalizer") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } - r.l.Info("Successfully deleted resource") + log.Info("Successfully deleted resource") return ctrl.Result{Requeue: false}, nil } // add finalizer to avoid deleting the token w/o it being deleted from the git server if err := r.finalizer.AddFinalizer(ctx, cr); err != nil { - r.l.Error(err, "cannot add finalizer") + log.Error(err, "cannot add finalizer") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return ctrl.Result{Requeue: true}, errors.Wrap(r.Status().Update(ctx, cr), errUpdateStatus) } @@ -152,9 +149,10 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } func (r *reconciler) createToken(ctx context.Context, giteaClient *gitea.Client, cr *infrav1alpha1.Token) error { + log := log.FromContext(ctx) tokens, _, err := giteaClient.ListAccessTokens(gitea.ListAccessTokensOptions{}) if err != nil { - r.l.Error(err, "cannot list repo") + log.Error(err, "cannot list repo") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return err } @@ -168,7 +166,7 @@ func (r *reconciler) createToken(ctx context.Context, giteaClient *gitea.Client, if !tokenFound { u, _, err := giteaClient.GetMyUserInfo() if err != nil { - r.l.Error(err, "cannot get user info") + log.Error(err, "cannot get user info") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return err } @@ -180,11 +178,11 @@ func (r *reconciler) createToken(ctx context.Context, giteaClient *gitea.Client, }, }) if err != nil { - r.l.Error(err, "cannot create token") + log.Error(err, "cannot create token") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return err } - r.l.Info("token created", "name", cr.GetName()) + log.Info("token created", "name", cr.GetName()) secret := &corev1.Secret{ TypeMeta: metav1.TypeMeta{ APIVersion: corev1.SchemeGroupVersion.Identifier(), @@ -213,10 +211,10 @@ func (r *reconciler) createToken(ctx context.Context, giteaClient *gitea.Client, } if err := r.Apply(ctx, secret); err != nil { cr.SetConditions(infrav1alpha1.Failed(err.Error())) - r.l.Error(err, "cannot create secret") + log.Error(err, "cannot create secret") return err } - r.l.Info("secret for token created", "name", cr.GetName()) + log.Info("secret for token created", "name", cr.GetName()) } return nil } @@ -224,10 +222,10 @@ func (r *reconciler) createToken(ctx context.Context, giteaClient *gitea.Client, func (r *reconciler) deleteToken(ctx context.Context, giteaClient *gitea.Client, cr *infrav1alpha1.Token) error { _, err := giteaClient.DeleteAccessToken(cr.GetTokenName()) if err != nil { - r.l.Error(err, "cannot delete token") + log.FromContext(ctx).Error(err, "cannot delete token") cr.SetConditions(infrav1alpha1.Failed(err.Error())) return err } - r.l.Info("token deleted", "name", cr.GetTokenName()) + log.FromContext(ctx).Info("token deleted", "name", cr.GetTokenName()) return nil } diff --git a/controllers/pkg/reconcilers/vlan-specializer/reconciler.go b/controllers/pkg/reconcilers/vlan-specializer/reconciler.go index a2178088..98f95fa1 100644 --- a/controllers/pkg/reconcilers/vlan-specializer/reconciler.go +++ b/controllers/pkg/reconcilers/vlan-specializer/reconciler.go @@ -29,7 +29,6 @@ import ( "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" - "github.com/go-logr/logr" "github.com/nephio-project/nephio/controllers/pkg/resource" kptfilelibv1 "github.com/nephio-project/nephio/krm-functions/lib/kptfile/v1" "github.com/nephio-project/nephio/krm-functions/lib/kptrl" @@ -85,20 +84,18 @@ type reconciler struct { For corev1.ObjectReference porchClient client.Client krmfn fn.ResourceListProcessor - - l logr.Logger } func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - r.l = log.FromContext(ctx).WithValues("req", req) - r.l.Info("reconcile specializer") + log := log.FromContext(ctx).WithValues("req", req) + log.Info("reconcile specializer") pr := &porchv1alpha1.PackageRevision{} if err := r.Get(ctx, req.NamespacedName, pr); err != nil { // There's no need to requeue if we no longer exist. Otherwise we'll be // requeued implicitly because we return an error. if resource.IgnoreNotFound(err) != nil { - r.l.Error(err, "cannot get resource") + log.Error(err, "cannot get resource") return ctrl.Result{}, errors.Wrap(resource.IgnoreNotFound(err), "cannot get resource") } return ctrl.Result{}, nil @@ -110,32 +107,32 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu // get package revision resourceList prr := &porchv1alpha1.PackageRevisionResources{} if err := r.porchClient.Get(ctx, req.NamespacedName, prr); err != nil { - r.l.Error(err, "cannot get package revision resources") + log.Error(err, "cannot get package revision resources") return ctrl.Result{}, errors.Wrap(err, "cannot get package revision resources") } // get resourceList from resources rl, err := kptrl.GetResourceList(prr.Spec.Resources) if err != nil { - r.l.Error(err, "cannot get resourceList") + log.Error(err, "cannot get resourceList") return ctrl.Result{}, errors.Wrap(err, "cannot get resourceList") } // run the function SDK _, err = r.krmfn.Process(rl) if err != nil { - r.l.Error(err, "function run failed") + log.Error(err, "function run failed") // TBD if we need to return here + check if kptfile is set //return ctrl.Result{}, errors.Wrap(err, "function run failed") } for _, o := range rl.Items { - r.l.Info("resourceList", "data", o.String()) + log.Info("resourceList", "data", o.String()) // TBD what if we create new resources // update the resources with the latest info prr.Spec.Resources[o.GetAnnotation(kioutil.PathAnnotation)] = o.String() } kptfile := rl.Items.GetRootKptfile() if kptfile == nil { - r.l.Error(fmt.Errorf("mandatory Kptfile is missing from the package"), "") + log.Error(fmt.Errorf("mandatory Kptfile is missing from the package"), "") return ctrl.Result{}, nil }