Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Milica-Cvrkota-IBM committed Aug 8, 2024
1 parent 99daf22 commit 0edba70
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers

import (
"context"
"fmt"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -60,6 +61,7 @@ func (r *InstanaAgentReconciler) getIstioOutboundConfigAndNodeIps(ctx context.Co
log := logf.FromContext(ctx)
var nodeIPs []string

log.Info("Check if REGISTRY_ONLY is enabled")
isIstioRegistryOnlyEnabled := r.checkRegistryOnlyMode(ctx, namespace, configmap)

if isIstioRegistryOnlyEnabled {
Expand All @@ -75,11 +77,15 @@ func (r *InstanaAgentReconciler) getIstioOutboundConfigAndNodeIps(ctx context.Co

func (r *InstanaAgentReconciler) checkRegistryOnlyMode(ctx context.Context, namespace string, configmap string) bool {
istioConfigMap := &corev1.ConfigMap{}
log := logf.FromContext(ctx)
log.Info(fmt.Sprintf("Checking Istio ConfigMap %s in namespace %s for outbound traffic policy", configmap, namespace))
err := r.client.Get(ctx, types.NamespacedName{Name: configmap, Namespace: namespace}, istioConfigMap)
if err != nil {
log.Error(err, "Failed fetching istio ConfigMap")
return false
}
if istioConfigMap.Data == nil {
log.Info(fmt.Sprintf("Istio configmap %s in namespace %s data in nil", configmap, namespace))
return false
}
meshConfigData, ok := istioConfigMap.Data["mesh"]
Expand All @@ -88,10 +94,13 @@ func (r *InstanaAgentReconciler) checkRegistryOnlyMode(ctx context.Context, name
}

var meshConfig IstioMeshConfig
log.Info("Unmarshalling config data")
err = yaml.Unmarshal([]byte(meshConfigData), &meshConfig)
if err != nil {
log.Error(err, "Unmarshalling config data ERROR")
return false
}
log.Info("Checking if policy is REGISTRY_ONLY")

return strings.EqualFold(meshConfig.OutboundTrafficPolicy.Mode, "REGISTRY_ONLY")
}
Expand Down

0 comments on commit 0edba70

Please sign in to comment.