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: potential nil pointer in telemetry & delete k0s folder #1409

Merged
merged 2 commits into from
Dec 12, 2023
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
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