Skip to content

Commit

Permalink
Merge pull request #1409 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: potential nil pointer in telemetry & delete k0s folder
  • Loading branch information
FabianKramm committed Dec 12, 2023
2 parents d55f103 + c269447 commit 52581de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pkg/k0s/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/ghodss/yaml"
Expand All @@ -20,7 +21,16 @@ type k0sCommand struct {
Args []string `json:"args,omitempty"`
}

const runDir = "/run/k0s"

func StartK0S(ctx context.Context) error {
// make sure we delete the contents of /run/k0s
dirEntries, _ := os.ReadDir(runDir)
for _, entry := range dirEntries {
_ = os.RemoveAll(filepath.Join(runDir, entry.Name()))
}

// start k0s binary
reader, writer, err := os.Pipe()
if err != nil {
return err
Expand Down
12 changes: 9 additions & 3 deletions pkg/telemetry/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,18 @@ func (d *DefaultCollector) RecordStatus(ctx context.Context) {
}

func (d *DefaultCollector) RecordStart(ctx context.Context) {
chartInfo := d.getChartInfo(ctx)
properties := map[string]interface{}{
"vcluster_version": SyncerVersion,
"vcluster_k8s_distro": d.getChartInfo(ctx).Name,
"vcluster_k8s_distro_version": d.getVirtualClusterVersion(),
"host_cluster_k8s_version": d.getHostClusterVersion(),
"os_arch": runtime.GOOS + "/" + runtime.GOARCH,
"helm_values": d.getChartInfo(ctx).Values,
"creation_method": d.config.InstanceCreator,
}
if chartInfo != nil {
properties["vcluster_k8s_distro"] = chartInfo.Name
properties["helm_values"] = chartInfo.Values
}

// build the event and record
propertiesRaw, _ := json.Marshal(properties)
Expand Down Expand Up @@ -231,7 +234,10 @@ func (d *DefaultCollector) RecordError(ctx context.Context, severity ErrorSeveri

// if panic or fatal we add the helm values
if severity == PanicSeverity || severity == FatalSeverity {
properties["helm_values"] = d.getChartInfo(ctx).Values
chartInfo := d.getChartInfo(ctx)
if chartInfo != nil {
properties["helm_values"] = chartInfo.Values
}
}

// build the event and record
Expand Down

0 comments on commit 52581de

Please sign in to comment.