Skip to content

Commit

Permalink
chore: add enrichment rules for k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarschulte committed Dec 11, 2023
1 parent 0570ff9 commit 1e31ec1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Specification struct {
//STEADYBIT_EXTENSION_PROJECT_ID
ProjectID string `json:"projectId" required:"false" split_words:"true"`
DiscoveryAttributesExcludesVM []string `json:"discoveryAttributesExcludesVM" required:"false" split_words:"true"`
EnrichVMDataForTargetTypes []string `json:"EnrichScaleSetVMDataForTargetTypes" split_words:"true" default:"com.steadybit.extension_jvm.application,com.steadybit.extension_container.container,com.steadybit.extension_kubernetes.kubernetes-deployment,com.steadybit.extension_kubernetes.kubernetes-pod,com.steadybit.extension_kubernetes.kubernetes-daemonset,com.steadybit.extension_kubernetes.kubernetes-statefulset"`
}

var (
Expand Down
37 changes: 36 additions & 1 deletion extvm/vm_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,15 @@ func getStringValue(val *string) string {
}

func (d *vmDiscovery) DescribeEnrichmentRules() []discovery_kit_api.TargetEnrichmentRule {
return []discovery_kit_api.TargetEnrichmentRule{
rules := []discovery_kit_api.TargetEnrichmentRule{
getToHostEnrichmentRule(),
getToContainerEnrichmentRule(),
getToKubernetesNodeEnrichmentRule(),
}
for _, targetType := range config.Config.EnrichVMDataForTargetTypes {
rules = append(rules, getVMToXEnrichmentRule(targetType))
}
return rules
}

func getToHostEnrichmentRule() discovery_kit_api.TargetEnrichmentRule {
Expand Down Expand Up @@ -417,6 +421,37 @@ func getToKubernetesNodeEnrichmentRule() discovery_kit_api.TargetEnrichmentRule
}
}


func getVMToXEnrichmentRule(destTargetType string) discovery_kit_api.TargetEnrichmentRule {
id := fmt.Sprintf("com.steadybit.extension_gcp.vm.instance-to-%s", destTargetType)
return discovery_kit_api.TargetEnrichmentRule{
Id: id,
Version: extbuild.GetSemverVersionStringOrUnknown(),
Src: discovery_kit_api.SourceOrDestination{
Type: TargetIDVM,
Selector: map[string]string{
"gcp-vm.hostname": "${dest.host.hostname}",
},
},
Dest: discovery_kit_api.SourceOrDestination{
Type: destTargetType,
Selector: map[string]string{
"host.hostname": "${src.gcp-vm.hostname}",
},
},
Attributes: []discovery_kit_api.Attribute{
{
Matcher: discovery_kit_api.Equals,
Name: "gcp.zone",
},
{
Matcher: discovery_kit_api.Equals,
Name: "gcp.project.id",
},
},
}
}

func getToContainerEnrichmentRule() discovery_kit_api.TargetEnrichmentRule {
return discovery_kit_api.TargetEnrichmentRule{
Id: "com.steadybit.extension_gcp.gcp-vm-to-container",
Expand Down

0 comments on commit 1e31ec1

Please sign in to comment.