Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
omris94 committed Dec 10, 2024
1 parent 8d98a0c commit b011696
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 19 deletions.
172 changes: 167 additions & 5 deletions src/mapper/pkg/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/mapper/pkg/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/mapper/pkg/kubefinder/kubefinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func (k *KubeFinder) ResolveOtterizeIdentityForService(ctx context.Context, svc
resolutionData := model.IdentityResolutionData{
IsService: lo.ToPtr(true),
ExtraInfo: lo.ToPtr("ResolveOtterizeIdentityForService"),
LastSeen: lo.ToPtr(lastSeen.String()),
}

if len(pods) == 0 {
Expand Down Expand Up @@ -468,6 +469,9 @@ func (k *KubeFinder) ResolveOtterizeIdentityForService(ctx context.Context, svc
return model.OtterizeServiceIdentity{}, false, errors.Wrap(err)
}

resolutionData.PodHostname = lo.ToPtr(pod.Name)
resolutionData.Uptime = lo.ToPtr(time.Since(pod.CreationTimestamp.Time).String())

dstSvcIdentity := model.OtterizeServiceIdentity{
Name: dstService.Name,
Namespace: pod.Namespace,
Expand Down
9 changes: 8 additions & 1 deletion src/mapper/pkg/resolvers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/samber/lo"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"time"
)

func (r *Resolver) discoverInternalSrcIdentity(ctx context.Context, src *model.RecordedDestinationsForSrc) (model.OtterizeServiceIdentity, error) {
Expand Down Expand Up @@ -44,7 +45,12 @@ func (r *Resolver) discoverInternalSrcIdentity(ctx context.Context, src *model.R
// It may cause a bug because the function will not be able to modify the "src" object of the caller.
r.filterTargetsAccordingToPodCreationTime(src, srcPod)

return r.resolveInClusterIdentity(ctx, srcPod)
svcIdentity, err := r.resolveInClusterIdentity(ctx, srcPod)
if err != nil {
return model.OtterizeServiceIdentity{}, errors.Wrap(err)
}
svcIdentity.ResolutionData.ProcfsHostname = lo.ToPtr(src.SrcHostname)
return svcIdentity, nil
}

func (r *Resolver) filterTargetsAccordingToPodCreationTime(src *model.RecordedDestinationsForSrc, srcPod *corev1.Pod) {
Expand Down Expand Up @@ -78,6 +84,7 @@ func (r *Resolver) resolveInClusterIdentity(ctx context.Context, pod *corev1.Pod
PodHostname: lo.ToPtr(pod.Name),
IsService: lo.ToPtr(false),
ExtraInfo: lo.ToPtr("resolveInClusterIdentity"),
Uptime: lo.ToPtr(time.Since(pod.CreationTimestamp.Time).String()),
},
}
if svcIdentity.OwnerObject != nil {
Expand Down
28 changes: 20 additions & 8 deletions src/mapper/pkg/resolvers/schema.helpers.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ func (r *Resolver) resolveDestIdentity(ctx context.Context, dest model.Destinati
return model.OtterizeServiceIdentity{}, false, errors.Wrap(err)
}
if ok {
dstSvcIdentity.ResolutionData = &model.IdentityResolutionData{
Host: lo.ToPtr(dest.Destination),
Port: dest.DestinationPort,
IsService: lo.ToPtr(true),
ExtraInfo: lo.ToPtr("resolveDestIdentity"),
}
dstSvcIdentity.ResolutionData.Host = lo.ToPtr(dest.Destination)
dstSvcIdentity.ResolutionData.Port = dest.DestinationPort
dstSvcIdentity.ResolutionData.ExtraInfo = lo.ToPtr("resolveDestIdentity")
return dstSvcIdentity, true, nil
}
}
Expand Down Expand Up @@ -113,6 +110,8 @@ func (r *Resolver) resolveDestIdentity(ctx context.Context, dest model.Destinati
Port: dest.DestinationPort,
IsService: lo.ToPtr(false),
ExtraInfo: lo.ToPtr("resolveDestIdentity"),
LastSeen: lo.ToPtr(dest.LastSeen.String()),
Uptime: lo.ToPtr(time.Since(destPod.CreationTimestamp.Time).String()),
},
}
if dstService.OwnerObject != nil {
Expand Down Expand Up @@ -182,8 +181,20 @@ func (r *Resolver) addSocketScanPodIntent(ctx context.Context, srcSvcIdentity mo
if err != nil {
return errors.Wrap(err)
}

dstSvcIdentity := &model.OtterizeServiceIdentity{Name: dstService.Name, Namespace: destPod.Namespace, Labels: kubefinder.PodLabelsToOtterizeLabels(destPod)}
dstSvcIdentity := &model.OtterizeServiceIdentity{
Name: dstService.Name,
Namespace: destPod.Namespace,
Labels: kubefinder.PodLabelsToOtterizeLabels(destPod),
ResolutionData: &model.IdentityResolutionData{
Host: lo.ToPtr(dest.Destination),
PodHostname: lo.ToPtr(destPod.Name),
Port: dest.DestinationPort,
IsService: lo.ToPtr(false),
ExtraInfo: lo.ToPtr("addSocketScanPodIntent"),
LastSeen: lo.ToPtr(dest.LastSeen.String()),
Uptime: lo.ToPtr(time.Since(destPod.CreationTimestamp.Time).String()),
},
}
if dstService.OwnerObject != nil {
dstSvcIdentity.PodOwnerKind = model.GroupVersionKindFromKubeGVK(dstService.OwnerObject.GetObjectKind().GroupVersionKind())
}
Expand Down Expand Up @@ -414,6 +425,7 @@ func (r *Resolver) resolveOtterizeIdentityForExternalAccessDestination(ctx conte
}

dstSvcIdentity, ok, err := r.kubeFinder.ResolveOtterizeIdentityForService(ctx, destService, dest.LastSeen)
dstSvcIdentity.ResolutionData.Host = lo.ToPtr(destIP)
if err != nil {
return model.OtterizeServiceIdentity{}, false, errors.Wrap(err)
}
Expand Down
3 changes: 3 additions & 0 deletions src/mappergraphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ type GroupVersionKind {
type IdentityResolutionData {
host: String
podHostname: String
procfsHostname: String
port: Int
isService: Boolean
uptime: String
lastSeen: String
extraInfo: String
}

Expand Down

0 comments on commit b011696

Please sign in to comment.