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 3464ea6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/v1/instanaagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func (in *InstanaAgent) Default() {
optional.ValueOrDefault(&in.Spec.K8sSensor.ImageSpec.Tag, "latest")
optional.ValueOrDefault(&in.Spec.K8sSensor.ImageSpec.PullPolicy, corev1.PullAlways)
optional.ValueOrDefault(&in.Spec.K8sSensor.DeploymentSpec.Replicas, 3)
optional.ValueOrDefault(&in.Spec.ServiceMesh.Namespace, "istio-system")
optional.ValueOrDefault(&in.Spec.ServiceMesh.Configmap, "istio")
optional.ValueOrDefault(&in.Spec.Agent.ServiceMesh.Namespace, "istio-system")
optional.ValueOrDefault(&in.Spec.Agent.ServiceMesh.Configmap, "istio")
}

// +kubebuilder:object:root=true
Expand Down
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 3464ea6

Please sign in to comment.