Skip to content

Commit

Permalink
add debug level classifier
Browse files Browse the repository at this point in the history
Signed-off-by: KfreeZ <[email protected]>
  • Loading branch information
KfreeZ committed Sep 10, 2024
1 parent bb375b3 commit c719b55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions microservices-connector/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
"go.uber.org/zap/zapcore"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -63,6 +64,7 @@ func main() {
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
opts := zap.Options{
Development: true,
Level: zapcore.InfoLevel,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
Expand Down Expand Up @@ -158,6 +160,7 @@ func main() {
if err = (&controller.GMConnectorReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("GMC"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GMConnector")
os.Exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down Expand Up @@ -99,7 +98,7 @@ var yamlDict = map[string]string{
}

var (
_log = log.Log.WithName("GMC")
_log = ctrl.Log.WithName("GMC")
)

// GMConnectorReconciler reconciles a GMConnector object
Expand Down Expand Up @@ -132,7 +131,7 @@ func (r *GMConnectorReconciler) reconcileResource(ctx context.Context, graphNs s
return nil, errors.New("invalid svc config")
}

_log.V(2).Info("processing step", "config", *stepCfg)
_log.V(1).Info("processing step", "config", *stepCfg)

var retObjs []*unstructured.Unstructured
// by default, the svc's namespace is the same as the graph
Expand Down Expand Up @@ -680,7 +679,7 @@ func applyRouterConfigToTemplates(step string, svcCfg *map[string]string, yamlFi
if err != nil {
return string(yamlFile), fmt.Errorf("error executing template: %v", err)
} else {
// fmt.Printf("applied config %s\n", appliedCfg.String())
_log.V(1).Info("applied config", "content", appliedCfg.String())
return appliedCfg.String(), nil
}
} else {
Expand Down Expand Up @@ -820,9 +819,7 @@ func isGMCSpecOrMetadataChanged(e event.UpdateEvent) bool {
specChanged := !reflect.DeepEqual(oldObject.Spec, newObject.Spec)
metadataChanged := isMetadataChanged(&(oldObject.ObjectMeta), &(newObject.ObjectMeta))

_log.Info("Check trigger condition?", "spec changed", specChanged, "meta changed", metadataChanged)
fmt.Printf("\n| spec changed %t | meta changed: %t |\n", specChanged, metadataChanged)

_log.V(1).Info("Check trigger condition?", "spec changed", specChanged, "meta changed", metadataChanged)
// Compare the old and new spec, ignore metadata, status changes
// metadata change: name, namespace, such change should create a new GMC
// status change: deployment status
Expand All @@ -838,12 +835,12 @@ func isDeploymentStatusChanged(e event.UpdateEvent) bool {
}

if len(newDeployment.OwnerReferences) == 0 {
// fmt.Printf("| %s:%s: no owner reference |\n", newDeployment.Namespace, newDeployment.Name)
_log.V(1).Info("No owner reference", "ns", newDeployment.Namespace, "name", newDeployment.Name)
return false
} else {
for _, owner := range newDeployment.OwnerReferences {
if owner.Kind == "GMConnector" {
// fmt.Printf("| %s:%s: owner is GMConnector |\n", newDeployment.Namespace, newDeployment.Name)
_log.V(1).Info("Owner is GMConnector", "ns", newDeployment.Namespace, "name", newDeployment.Name)
break
}
}
Expand All @@ -870,9 +867,9 @@ func isDeploymentStatusChanged(e event.UpdateEvent) bool {
if (oldStatus == corev1.ConditionTrue && oldStatus != newStatus) ||
(newStatus == corev1.ConditionTrue && oldStatus != newStatus) {
{
fmt.Printf("| %s:%s: status changed from : %v to %v|\n",
newDeployment.Namespace, newDeployment.Name,
oldStatus, newStatus)
_log.Info("status changed", "ns",
newDeployment.Namespace, "name", newDeployment.Name,
"from", oldStatus, "to", newStatus)
return true
}
}
Expand Down

0 comments on commit c719b55

Please sign in to comment.