From 2d066915639a2593ebcfc38650c460eb39466972 Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Tue, 12 Dec 2023 17:23:57 +0100 Subject: [PATCH 1/2] fix: potential nil pointer in telemetry --- pkg/telemetry/collect.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/telemetry/collect.go b/pkg/telemetry/collect.go index 3a204bab0..436d1ebd5 100644 --- a/pkg/telemetry/collect.go +++ b/pkg/telemetry/collect.go @@ -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) @@ -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 From c269447bfbbfec726a6ad37d1acf1e45f6727ec0 Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Tue, 12 Dec 2023 17:47:07 +0100 Subject: [PATCH 2/2] fix: delete k0s contents --- pkg/k0s/k0s.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/k0s/k0s.go b/pkg/k0s/k0s.go index 2fc85c7c1..a824b60af 100644 --- a/pkg/k0s/k0s.go +++ b/pkg/k0s/k0s.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "strings" "github.com/ghodss/yaml" @@ -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