Skip to content

Commit

Permalink
batch of fixes for the controller. (istio#360)
Browse files Browse the repository at this point in the history
* minor fixes for the controller.

* apply comments.
  • Loading branch information
Morven Cao authored and istio-testing committed Oct 12, 2019
1 parent cf75bd0 commit 2638b23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
15 changes: 4 additions & 11 deletions pkg/controller/istiocontrolplane/istiocontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package istiocontrolplane
import (
"context"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -71,15 +70,6 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// TODO(user): Modify this to be the types you create that are owned by the primary resource
// Watch for changes to secondary resource Pods and requeue the owner IstioControlPlane
err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &v1alpha2.IstioControlPlane{},
})
if err != nil {
return err
}
log.Info("Controller added")
return nil
}
Expand Down Expand Up @@ -171,8 +161,11 @@ func (r *ReconcileIstioControlPlane) Reconcile(request reconcile.Request) (recon
reconciler, err := r.factory.New(instance, r.client)
if err == nil {
err = reconciler.Reconcile()
if err != nil {
log.Errorf("reconciling err: %s", err)
}
} else {
log.Errorf("failed to create reconciler; %s", err)
log.Errorf("failed to create reconciler: %s", err)
}

return reconcile.Result{}, err
Expand Down
14 changes: 5 additions & 9 deletions pkg/helmreconciler/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,35 +248,31 @@ func (l *LoggingRenderingListener) BeginChart(chart string, manifests []manifest

// BeginResource logs the event and updates the logger to log with values resource=name, kind=kind, apiVersion=api-version
func (l *LoggingRenderingListener) BeginResource(obj runtime.Object) (runtime.Object, error) {
accessor := meta.NewAccessor()
kind, _ := accessor.Kind(obj)
name, _ := accessor.Name(obj)
version, _ := accessor.APIVersion(obj)
log.Infof("begin resource update (%s, %s, %s)", version, kind, name)
log.Infof("begin resource update: %s", obj.GetObjectKind().GroupVersionKind())
return obj, nil
}

// ResourceCreated logs the event
func (l *LoggingRenderingListener) ResourceCreated(created runtime.Object) error {
log.Info("new resource created")
log.Infof("resource created: %s", created.GetObjectKind().GroupVersionKind())
return nil
}

// ResourceUpdated logs the event
func (l *LoggingRenderingListener) ResourceUpdated(updated runtime.Object, old runtime.Object) error {
log.Info("existing resource updated")
log.Infof("resource updated: %s", updated.GetObjectKind().GroupVersionKind())
return nil
}

// ResourceDeleted logs the event
func (l *LoggingRenderingListener) ResourceDeleted(deleted runtime.Object) error {
log.Info("resource deleted")
log.Infof("resource deleted: %s", deleted.GetObjectKind().GroupVersionKind())
return nil
}

// ResourceError logs the event and the error
func (l *LoggingRenderingListener) ResourceError(obj runtime.Object, err error) error {
log.Errorf("error processing resource: %s", err)
log.Errorf("error processing resource: %s", obj.GetObjectKind().GroupVersionKind())
return nil
}

Expand Down

0 comments on commit 2638b23

Please sign in to comment.