<commit_before>package render

import (
	"strings"

	"github.com/weaveworks/scope/probe/docker"
	"github.com/weaveworks/scope/probe/kubernetes"
	"github.com/weaveworks/scope/report"
)

// Constants are used in the tests.
const (
	UnmanagedID    = "unmanaged"
	UnmanagedMajor = "Unmanaged"
)

func renderKubernetesTopologies(rpt report.Report) bool {
	return len(rpt.Pod.Nodes)+len(rpt.Service.Nodes) > 1
}

// PodRenderer is a Renderer which produces a renderable kubernetes
// graph by merging the container graph and the pods topology.
var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
	ApplyDecorators(MakeFilter(
		func(n report.Node) bool {
			state, ok := n.Latest.Lookup(kubernetes.State)
			return (!ok || state != kubernetes.StateDeleted)
		},
		MakeReduce(
			MakeMap(
				MapContainer2Pod,
				ContainerWithImageNameRenderer,
			),
			SelectPod,
		),
	)),
)

// PodServiceRenderer is a Renderer which produces a renderable kubernetes services
// graph by merging the pods graph and the services topology.
var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
	ApplyDecorators(FilterEmpty(report.Pod,
		MakeReduce(
			MakeMap(
				Map2Service,
				PodRenderer,
			),
			SelectService,
		),
	)),
)

// DeploymentRenderer is a Renderer which produces a renderable kubernetes deployments
// graph by merging the pods graph and the deployments topology.
var DeploymentRenderer = ApplyDecorators(
	FilterEmpty(report.Pod,
		MakeReduce(
			MakeMap(
				Map2Deployment,
				ReplicaSetRenderer,
			),
			SelectDeployment,
		),
	),
)

// ReplicaSetRenderer is a Renderer which produces a renderable kubernetes replica sets
// graph by merging the pods graph and the replica sets topology.
var ReplicaSetRenderer = ApplyDecorators(
	FilterEmpty(report.Pod,
		MakeReduce(
			MakeMap(
				Map2ReplicaSet,
				PodRenderer,<commit_msg>Don't filter out Services etc which don't have pods - we don't do our filtering like that anymore.<commit_after>package render

import (
	"strings"

	"github.com/weaveworks/scope/probe/docker"
	"github.com/weaveworks/scope/probe/kubernetes"
	"github.com/weaveworks/scope/report"
)

// Constants are used in the tests.
const (
	UnmanagedID    = "unmanaged"
	UnmanagedMajor = "Unmanaged"
)

func renderKubernetesTopologies(rpt report.Report) bool {
	return len(rpt.Pod.Nodes)+len(rpt.Service.Nodes) > 1
}

// PodRenderer is a Renderer which produces a renderable kubernetes
// graph by merging the container graph and the pods topology.
var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
	ApplyDecorators(MakeFilter(
		func(n report.Node) bool {
			state, ok := n.Latest.Lookup(kubernetes.State)
			return (!ok || state != kubernetes.StateDeleted)
		},
		MakeReduce(
			MakeMap(
				MapContainer2Pod,
				ContainerWithImageNameRenderer,
			),
			SelectPod,
		),
	)),
)

// PodServiceRenderer is a Renderer which produces a renderable kubernetes services
// graph by merging the pods graph and the services topology.
var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
	ApplyDecorators(
		MakeReduce(
			MakeMap(
				Map2Service,
				PodRenderer,
			),
			SelectService,
		),
	),
)

// DeploymentRenderer is a Renderer which produces a renderable kubernetes deployments
// graph by merging the pods graph and the deployments topology.
var DeploymentRenderer = ConditionalRenderer(renderKubernetesTopologies,
	ApplyDecorators(
		MakeReduce(
			MakeMap(
				Map2Deployment,
				ReplicaSetRenderer,
			),
			SelectDeployment,
		),
	),
)

// ReplicaSetRenderer is a Renderer which produces a renderable kubernetes replica sets
// graph by merging the pods graph and the replica sets topology.
var ReplicaSetRenderer = ConditionalRenderer(renderKubernetesTopologies,
	ApplyDecorators(
		MakeReduce(
			MakeMap(
				Map2ReplicaSet,
				PodRenderer,
{'fraction_non_alphanumeric': 0.08253059099192918, 'fraction_numerical': 0.0026034886748242643, 'mean_word_length': 4.358437935843794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4375203', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1155, 'n_words': 317}