Skip to content

Commit 11e7f1f

Browse files
committed
feat(longhorn): collect from log-path
longhorn/longhorn-11522 Signed-off-by: Chin-Ya Huang <[email protected]>
1 parent 12a5a93 commit 11e7f1f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

hack/collector-longhorn

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ function collect_kubelet_log(){
5858
fi
5959
}
6060

61+
collect_longhorn_logs() {
62+
local src_dir
63+
src_dir=$(join_paths "$HOST_PATH" "$LONGHORN_LOG_PATH")
64+
65+
if [ -d "$src_dir" ]; then
66+
cp -r "$src_dir"/* .
67+
else
68+
echo "Longhorn log directory not found: $src_dir" >&2
69+
fi
70+
}
71+
72+
join_paths() {
73+
local base="$1"
74+
local sub="$2"
75+
# Remove trailing slash from base and leading slash from sub
76+
printf "%s/%s\n" "${base%/}" "${sub#/}"
77+
}
78+
6179
function collect_logs(){
6280
cd ${BUNDLE_DIR}
6381
mkdir -p logs
@@ -66,6 +84,7 @@ function collect_logs(){
6684
collect_dmesg
6785
collect_syslog
6886
collect_kubelet_log
87+
collect_longhorn_logs
6988
}
7089

7190
collect_sysinfo

pkg/manager/agent.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package manager
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/pkg/errors"
78
"github.com/sirupsen/logrus"
@@ -138,9 +139,21 @@ func (a *AgentDaemonSet) Create(image string, managerURL string) (*appsv1.Daemon
138139
}
139140
}
140141

142+
switch a.sbm.SpecifyCollector {
143+
case "longhorn":
144+
a.prepareDaemonSetForLonghorn(daemonSet)
145+
}
146+
141147
return a.sbm.k8s.CreateDaemonSets(a.sbm.PodNamespace, daemonSet)
142148
}
143149

150+
func (a *AgentDaemonSet) prepareDaemonSetForLonghorn(daemonset *appsv1.DaemonSet) {
151+
daemonset.Spec.Template.Spec.Containers[0].Env = append(daemonset.Spec.Template.Spec.Containers[0].Env, corev1.EnvVar{
152+
Name: "LONGHORN_LOG_PATH",
153+
Value: os.Getenv("LONGHORN_LOG_PATH"),
154+
})
155+
}
156+
144157
func (a *AgentDaemonSet) Cleanup() error {
145158
dsName := a.getDaemonSetName()
146159
err := a.sbm.k8s.DeleteDaemonSets(a.sbm.PodNamespace, dsName)

0 commit comments

Comments
 (0)