Skip to content

Commit

Permalink
fix: check for empty pointers in describe (#1656)
Browse files Browse the repository at this point in the history
This PR fixes a bug in #1649 where a pointer would be accessed without
first checking if it's nil
  • Loading branch information
blumamir authored Oct 29, 2024
1 parent e00722f commit 1e0c3fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
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

0 comments on commit 1e0c3fd

Please sign in to comment.