Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for empty pointers in describe #1656

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions k8sutils/pkg/describe/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/client-go/kubernetes"
)

func printWorkloadManifestInfo(analyze *source.SourceAnalyze, sb *strings.Builder) bool {
func printWorkloadManifestInfo(analyze *source.SourceAnalyze, sb *strings.Builder) {
printProperty(sb, 0, &analyze.Name)
printProperty(sb, 0, &analyze.Kind)
printProperty(sb, 0, &analyze.Namespace)
Expand All @@ -21,8 +21,6 @@ func printWorkloadManifestInfo(analyze *source.SourceAnalyze, sb *strings.Builde
printProperty(sb, 1, analyze.Labels.Workload)
printProperty(sb, 1, analyze.Labels.Namespace)
printProperty(sb, 1, &analyze.Labels.InstrumentedText)

return analyze.Labels.Instrumented.Value.(bool)
}

func printInstrumentationConfigInfo(analyze *source.SourceAnalyze, sb *strings.Builder) {
Expand Down Expand Up @@ -60,22 +58,24 @@ func printInstrumentedApplicationInfo(analyze *source.SourceAnalyze, sb *strings
printProperty(sb, 1, &analyze.InstrumentedApplication.Created)
printProperty(sb, 1, analyze.InstrumentedApplication.CreateTime)

printProperty(sb, 1, &analyze.RuntimeInfo.Generation)
describeText(sb, 1, "Detected Containers:")
for _, container := range analyze.RuntimeInfo.Containers {
printProperty(sb, 2, &container.ContainerName)
printProperty(sb, 3, &container.Language)
printProperty(sb, 3, &container.RuntimeVersion)
if len(container.EnvVars) > 0 {
describeText(sb, 3, "Relevant Environment Variables:")
for _, envVar := range container.EnvVars {
describeText(sb, 4, fmt.Sprintf("%s: %s", envVar.Name, envVar.Value))
if analyze.RuntimeInfo != nil {
printProperty(sb, 1, &analyze.RuntimeInfo.Generation)
describeText(sb, 1, "Detected Containers:")
for _, container := range analyze.RuntimeInfo.Containers {
printProperty(sb, 2, &container.ContainerName)
printProperty(sb, 3, &container.Language)
printProperty(sb, 3, &container.RuntimeVersion)
if len(container.EnvVars) > 0 {
describeText(sb, 3, "Relevant Environment Variables:")
for _, envVar := range container.EnvVars {
describeText(sb, 4, fmt.Sprintf("%s: %s", envVar.Name, envVar.Value))
}
}
}
}
}

func printAppliedInstrumentationDeviceInfo(analyze *source.SourceAnalyze, workloadObj *source.K8sSourceObject, instrumented bool, sb *strings.Builder) {
func printAppliedInstrumentationDeviceInfo(analyze *source.SourceAnalyze, sb *strings.Builder) {

describeText(sb, 0, "\nInstrumentation Device:")
printProperty(sb, 1, &analyze.InstrumentationDevice.StatusText)
Expand Down Expand Up @@ -124,11 +124,11 @@ func printPodsInfo(analyze *source.SourceAnalyze, sb *strings.Builder) {
func DescribeSourceToText(analyze *source.SourceAnalyze) string {
var sb strings.Builder

instrumented := printWorkloadManifestInfo(analyze, &sb)
printWorkloadManifestInfo(analyze, &sb)
printInstrumentationConfigInfo(analyze, &sb)
printRuntimeDetails(analyze, &sb)
printInstrumentedApplicationInfo(analyze, &sb)
printAppliedInstrumentationDeviceInfo(analyze, nil, instrumented, &sb)
printAppliedInstrumentationDeviceInfo(analyze, &sb)
printPodsInfo(analyze, &sb)

return sb.String()
Expand Down
7 changes: 6 additions & 1 deletion k8sutils/pkg/describe/source/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,15 @@ func analyzeInstrumentedApplication(resources *OdigosSourceResources) Instrument
}
}

containers := make([]ContainerRuntimeInfoAnalyze, 0)
if resources.InstrumentedApplication != nil {
containers = analyzeRuntimeDetails(resources.InstrumentedApplication.Spec.RuntimeDetails)
}

return InstrumentedApplicationAnalyze{
Created: created,
CreateTime: createdTime,
Containers: analyzeRuntimeDetails(resources.InstrumentedApplication.Spec.RuntimeDetails),
Containers: containers,
}
}

Expand Down
Loading