1.修改kubectl debug 调用时切换工作目录 2.增加debug时参数能指定交互方式
This commit is contained in:
67
.gitlab-ci.yml
Normal file
67
.gitlab-ci.yml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
variables:
|
||||||
|
GIT_STRATEGY: "clone"
|
||||||
|
BUILD_BASED_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master"
|
||||||
|
BUILD_BASED_IMAGE_ROCKYLINUX8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- prebuild
|
||||||
|
- build-centos7
|
||||||
|
- build-rockylinux8
|
||||||
|
|
||||||
|
.build_rpm:
|
||||||
|
variables:
|
||||||
|
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
|
||||||
|
TESTING_VERSION_BUILD: 0
|
||||||
|
before_script:
|
||||||
|
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
|
||||||
|
- ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
|
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
|
||||||
|
- chmod +x ./ci/travis.sh
|
||||||
|
script:
|
||||||
|
- yum makecache
|
||||||
|
- ./ci/travis.sh
|
||||||
|
tags:
|
||||||
|
- share
|
||||||
|
|
||||||
|
feature_branch_build_rockylinux8:
|
||||||
|
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
|
||||||
|
stage: build-rockylinux8
|
||||||
|
variables:
|
||||||
|
PACKAGE: 1
|
||||||
|
LIBYAML_BUILD: 1
|
||||||
|
TESTING_VERSION_BUILD: 1
|
||||||
|
extends: .build_rpm
|
||||||
|
except:
|
||||||
|
- tags
|
||||||
|
- /^dev-.*$/i
|
||||||
|
- /^rel-.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
|
|
||||||
|
develop_build_rockylinux8:
|
||||||
|
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
|
||||||
|
stage: build-rockylinux8
|
||||||
|
variables:
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD: 1
|
||||||
|
LIBYAML_BUILD: 1
|
||||||
|
TESTING_VERSION_BUILD: 1
|
||||||
|
PULP3_RPM_REPO_NAME: tsg-testing-x86_64.el8
|
||||||
|
PULP3_RPM_DIST_NAME: tsg-testing-x86_64.el8
|
||||||
|
extends: .build_rpm
|
||||||
|
only:
|
||||||
|
- /^dev-.*$/i
|
||||||
|
- /^rel-.*$/i
|
||||||
|
- /^master.*$/i
|
||||||
|
|
||||||
|
release_build_rockylinux8:
|
||||||
|
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
|
||||||
|
stage: build-rockylinux8
|
||||||
|
variables:
|
||||||
|
PACKAGE: 1
|
||||||
|
UPLOAD: 1
|
||||||
|
LIBYAML_BUILD: 1
|
||||||
|
PULP3_RPM_REPO_NAME: tsg-stable-x86_64.el8
|
||||||
|
PULP3_RPM_DIST_NAME: tsg-stable-x86_64.el8
|
||||||
|
extends: .build_rpm
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
1268
autorevision.sh
Normal file
1268
autorevision.sh
Normal file
File diff suppressed because it is too large
Load Diff
63
ci/travis.sh
Normal file
63
ci/travis.sh
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
echo $CPLUS_INCLUDE_PATH
|
||||||
|
set -evx
|
||||||
|
|
||||||
|
chmod +x ci/get-nprocessors.sh
|
||||||
|
. ci/get-nprocessors.sh
|
||||||
|
|
||||||
|
# if possible, ask for the precise number of processors,
|
||||||
|
# otherwise take 2 processors as reasonable default; see
|
||||||
|
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
|
||||||
|
if [ -x /usr/bin/getconf ]; then
|
||||||
|
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
|
||||||
|
else
|
||||||
|
NPROCESSORS=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
|
||||||
|
# crashes if parallelized too much (maybe memory consumption problem),
|
||||||
|
# so limit to 4 processors for the time being.
|
||||||
|
if [ $NPROCESSORS -gt 4 ] ; then
|
||||||
|
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
|
||||||
|
NPROCESSORS=4
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tell make to use the processors. No preceding '-' required.
|
||||||
|
MAKEFLAGS="j${NPROCESSORS}"
|
||||||
|
export MAKEFLAGS
|
||||||
|
|
||||||
|
env | sort
|
||||||
|
|
||||||
|
# Set default values to OFF for these variables if not specified.
|
||||||
|
: "${NO_EXCEPTION:=OFF}"
|
||||||
|
: "${NO_RTTI:=OFF}"
|
||||||
|
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||||
|
|
||||||
|
yum install -y cligen-devel clixon-devel
|
||||||
|
|
||||||
|
if [ -n "${LIBYAML_BUILD}" ]; then
|
||||||
|
git clone https://github.com/yaml/libyaml.git
|
||||||
|
cd libyaml
|
||||||
|
sed -i 's/^add_library.*$/add_library(yaml SHARED ${SRCS})/g' CMakeLists.txt
|
||||||
|
cmake3 .
|
||||||
|
make && make install
|
||||||
|
cd ..
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir build || true
|
||||||
|
|
||||||
|
cd build
|
||||||
|
|
||||||
|
cmake3 -DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD ..
|
||||||
|
|
||||||
|
if [ -n "${PACKAGE}" ]; then
|
||||||
|
make package
|
||||||
|
fi
|
||||||
|
ls -halt ./*.rpm
|
||||||
|
|
||||||
|
if [ -n "${UPLOAD}" ]; then
|
||||||
|
cp ~/rpm_upload_tools.py ./
|
||||||
|
python3 rpm_upload_tools.py ${PULP3_RPM_REPO_NAME} ${PULP3_RPM_DIST_NAME} *.rpm
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -30,25 +30,40 @@ func terminalSize() (width, height int, err error) {
|
|||||||
}
|
}
|
||||||
return width, height, nil
|
return width, height, nil
|
||||||
}
|
}
|
||||||
func debug(config types.Coredump_config) error {
|
func debug(config types.Coredump_config, command string) error {
|
||||||
// 使用kubectl命令执行debug操作
|
// 使用kubectl命令执行debug操作
|
||||||
if config.Image_id != "" {
|
if config.Image_id != "" {
|
||||||
if config.Hostname == "" {
|
if config.Hostname == "" {
|
||||||
return errors.New("hostname must not be empty")
|
return errors.New("hostname must not be empty")
|
||||||
}
|
}
|
||||||
cmd := exec.Command("kubectl", "debug", "node/"+config.Hostname, "-it", "--image="+config.Image_id, "--image-pull-policy=Never", "-- bash")
|
if command == "gdb" {
|
||||||
cmd.Stdin = os.Stdin
|
chmod := "cd" + filepath.Dir(config.Process_exe_path)
|
||||||
cmd.Stdout = os.Stdout
|
cmd := exec.Command("kubectl", "debug", "node/"+config.Hostname, "-it", "--image="+config.Image_id, "--image-pull-policy=Never", "--", "gdb", config.Process_exe_path, "/host"+config.Storage, "-ex", chmod)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stdin = os.Stdin
|
||||||
fmt.Println(cmd.String())
|
cmd.Stdout = os.Stdout
|
||||||
input := fmt.Sprintf("you can exec gdb %s /host%s get stack info", config.Process_exe_path, config.Storage)
|
cmd.Stderr = os.Stderr
|
||||||
fmt.Println(input)
|
fmt.Println(cmd.String())
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err := cmd.Wait()
|
err := cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd := exec.Command("kubectl", "debug", "node/"+config.Hostname, "-it", "--image="+config.Image_id, "--image-pull-policy=Never", "--", command)
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
fmt.Println(cmd.String())
|
||||||
|
fmt.Println("exe=", config.Process_exe_path, "coredump=/host", config.Storage)
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err := cmd.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else { // 使用gdb命令进行命令行交互分析
|
} else { // 使用gdb命令进行命令行交互分析
|
||||||
cmd := exec.Command("gdb", config.Process_exe_path, config.Storage)
|
cmd := exec.Command("gdb", config.Process_exe_path, config.Storage)
|
||||||
@@ -93,25 +108,28 @@ func WalkDirectory(dir string) {
|
|||||||
fmt.Printf("Error walking directory %s: %v\n", dir, err)
|
fmt.Printf("Error walking directory %s: %v\n", dir, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func list() {
|
func list(pid string) {
|
||||||
defaultWidth := 80
|
defaultWidth := 80
|
||||||
if width, _, err := terminalSize(); err == nil {
|
if width, _, err := terminalSize(); err == nil {
|
||||||
defaultWidth = int(width)
|
defaultWidth = int(width)
|
||||||
}
|
}
|
||||||
// 输出表头信息
|
// 输出表头信息
|
||||||
fmt.Printf("%-6s %-6s %-6s %-15s %-20s %-15s %-10s %-20s %-20s\n",
|
fmt.Printf("%-8s %-3s %-3s %-3s %-20s %-30s %-30s %-100s %-50s\n",
|
||||||
"PID", "UID", "GID", "SIGNATURE", "TIMESTAMP", "FILE", "HOSTNAME", "IMAGE_NAME", "storge")
|
"PID", "UID", "GID", "SIG", "TIMESTAMP", "EXE", "HOSTNAME", "IMAGE", "STORGE")
|
||||||
fmt.Println(strings.Repeat("-", defaultWidth))
|
fmt.Println(strings.Repeat("-", defaultWidth))
|
||||||
|
total := 0
|
||||||
// 输出配置信息
|
// 输出配置信息
|
||||||
for _, c := range configs {
|
for _, c := range configs {
|
||||||
processExe := filepath.Base(c.Process_exe_path)
|
if pid != "" && strings.Compare(c.Initial_ns_pid, pid) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
coreTime := time.Unix(c.Timestamp, 0).Format("2006-01-02 15:04:05")
|
coreTime := time.Unix(c.Timestamp, 0).Format("2006-01-02 15:04:05")
|
||||||
fmt.Printf("%-6s %-6s %-6s %-15d %-20s %-15s %-10s %-20s %-20s\n",
|
fmt.Printf("%-8s %-3s %-3s %-6d %-20s %-30s %-30s %-100s %-50s\n",
|
||||||
c.Process_ns_pid, c.UID, c.GID, c.Signal, coreTime, processExe, c.Hostname, c.Image_id, c.Storage)
|
c.Initial_ns_pid, c.UID, c.GID, c.Signal, coreTime, c.Process_exe_path, c.Hostname, c.Image_id, c.Storage)
|
||||||
|
total += 1
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Total", len(configs), "coredumps")
|
fmt.Println("Total", total, "coredumps")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Help 打印使用帮助
|
// Help 打印使用帮助
|
||||||
@@ -120,15 +138,22 @@ func Help() {
|
|||||||
fmt.Println("list options:")
|
fmt.Println("list options:")
|
||||||
fmt.Println(" -dir string")
|
fmt.Println(" -dir string")
|
||||||
fmt.Println(" Directory path")
|
fmt.Println(" Directory path")
|
||||||
|
fmt.Println(" -p string")
|
||||||
|
fmt.Println(" Pid to matching")
|
||||||
|
fmt.Println(" -command string")
|
||||||
|
fmt.Println(" exe command when attach to pod")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
listCmd := flag.NewFlagSet("list", flag.ExitOnError)
|
listCmd := flag.NewFlagSet("list", flag.ExitOnError)
|
||||||
debugCmd := flag.NewFlagSet("debug", flag.ExitOnError)
|
debugCmd := flag.NewFlagSet("debug", flag.ExitOnError)
|
||||||
helpCmd := flag.NewFlagSet("help", flag.ExitOnError)
|
helpCmd := flag.NewFlagSet("help", flag.ExitOnError)
|
||||||
|
var dirPath, pid, command string
|
||||||
dirPath := flag.String("dir", "", "Directory path")
|
listCmd.StringVar(&pid, "p", "", "Pid to matching")
|
||||||
|
debugCmd.StringVar(&pid, "p", "", "Pid to matching")
|
||||||
|
listCmd.StringVar(&dirPath, "dir", "", "Directory path")
|
||||||
|
debugCmd.StringVar(&dirPath, "dir", "", "Directory path")
|
||||||
|
debugCmd.StringVar(&command, "command", "", "")
|
||||||
if len(os.Args) == 1 {
|
if len(os.Args) == 1 {
|
||||||
helpCmd.Usage()
|
helpCmd.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -146,21 +171,31 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if listCmd.Parsed() {
|
if listCmd.Parsed() {
|
||||||
if *dirPath == "" {
|
if dirPath == "" {
|
||||||
*dirPath = "/var/tmp"
|
dirPath = "/var/tmp"
|
||||||
}
|
}
|
||||||
WalkDirectory(*dirPath)
|
WalkDirectory(dirPath)
|
||||||
list()
|
list(pid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if debugCmd.Parsed() {
|
if debugCmd.Parsed() {
|
||||||
if *dirPath == "" {
|
if dirPath == "" {
|
||||||
*dirPath = "/var/tmp"
|
dirPath = "/var/tmp"
|
||||||
}
|
}
|
||||||
WalkDirectory(*dirPath)
|
if command == "" {
|
||||||
fmt.Println(configs[0])
|
command = "gdb"
|
||||||
if err := debug(configs[0]); err != nil {
|
}
|
||||||
fmt.Println(err)
|
WalkDirectory(dirPath)
|
||||||
|
for _, config := range configs {
|
||||||
|
fmt.Println(config)
|
||||||
|
if strings.Compare(config.Initial_ns_pid, pid) == 0 || pid == "" {
|
||||||
|
err := debug(config, command)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ func isDiskSufficient(pipe_config types.Pipeconfig) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
func createCoreDumpDir(pipe_config *types.Pipeconfig, args types.Coredump_config) error {
|
func createCoreDumpDir(pipe_config *types.Pipeconfig, args types.Coredump_config) error {
|
||||||
pipe_config.File_base_path = fmt.Sprintf("%s/%s_%s_%d", pipe_config.File_base_path, args.Initial_ns_pid, args.Process_ns_pid, args.Timestamp)
|
pipe_config.Storage = fmt.Sprintf("%s/%s_%s_%d_coredump", pipe_config.Storage, args.Initial_ns_pid, args.Process_ns_pid, args.Timestamp)
|
||||||
dirName := pipe_config.File_base_path
|
dirName := pipe_config.Storage
|
||||||
if _, err := os.Stat(dirName); os.IsNotExist(err) {
|
if _, err := os.Stat(dirName); os.IsNotExist(err) {
|
||||||
// 目录不存在,创建目录
|
// 目录不存在,创建目录
|
||||||
if err := os.MkdirAll(dirName, os.ModePerm); err != nil {
|
if err := os.MkdirAll(dirName, os.ModePerm); err != nil {
|
||||||
@@ -212,9 +212,9 @@ func main() {
|
|||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
coredump_config.Storage = pipe_config.File_base_path
|
coredump_config.Storage = pipe_config.Storage
|
||||||
//切换至存储coredump目录
|
//切换至存储coredump目录
|
||||||
err = changeDirectory(pipe_config.File_base_path)
|
err = changeDirectory(pipe_config.Storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
return
|
return
|
||||||
@@ -228,19 +228,22 @@ func main() {
|
|||||||
journal.Print(journal.PriInfo, err.Error())
|
journal.Print(journal.PriInfo, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if coredump_config.Image_id == "" {
|
||||||
|
coredump_config.Image_id = "NULL"
|
||||||
|
}
|
||||||
//根据配置项选择存储coredump文件方式
|
//根据配置项选择存储coredump文件方式
|
||||||
if pipe_config.Save_model == 0 {
|
if pipe_config.Compress == false {
|
||||||
err = writeCoreDumpToFile(coredump_config)
|
err = writeCoreDumpToFile(coredump_config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
}
|
}
|
||||||
coredump_config.Storage = fmt.Sprintf("%s/%s_%s_%d_coredump.info", pipe_config.File_base_path, coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Timestamp)
|
coredump_config.Storage = fmt.Sprintf("%s/%s_%s_%d_coredump.info", pipe_config.Storage, coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Timestamp)
|
||||||
} else if pipe_config.Save_model == 1 {
|
} else if pipe_config.Compress == true {
|
||||||
err = compress(coredump_config)
|
err = compress(coredump_config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
journal.Print(journal.PriErr, err.Error())
|
journal.Print(journal.PriErr, err.Error())
|
||||||
}
|
}
|
||||||
coredump_config.Storage = fmt.Sprintf("%s/%s_%s_%d_coredump.info.zip", pipe_config.File_base_path, coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Timestamp)
|
coredump_config.Storage = fmt.Sprintf("%s/%s_%s_%d_coredump.info.zip", pipe_config.Storage, coredump_config.Initial_ns_pid, coredump_config.Process_ns_pid, coredump_config.Timestamp)
|
||||||
}
|
}
|
||||||
//将image name写入coredump config
|
//将image name写入coredump config
|
||||||
err = writeCoreConfig(coredump_config)
|
err = writeCoreConfig(coredump_config)
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func TestIsDiskSufficient(t *testing.T) {
|
|||||||
|
|
||||||
func TestCreateCoreDumpDir(t *testing.T) {
|
func TestCreateCoreDumpDir(t *testing.T) {
|
||||||
pipe_config := types.Pipeconfig{
|
pipe_config := types.Pipeconfig{
|
||||||
File_base_path: "/tmp",
|
Storage: "/tmp",
|
||||||
}
|
}
|
||||||
err := createCoreDumpDir(&pipe_config, coredump_config)
|
err := createCoreDumpDir(&pipe_config, coredump_config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,17 +7,18 @@ type Coreconfig struct {
|
|||||||
Socket_path string
|
Socket_path string
|
||||||
}
|
}
|
||||||
type Pipeconfig struct {
|
type Pipeconfig struct {
|
||||||
Save_model int //0为文件保存 1为压缩保存 2为minidump保存
|
Compress bool //是否压缩
|
||||||
File_base_path string
|
Storage_type int //是否存储为minidump格式
|
||||||
Total_file_mem_limit string
|
Storage string //存储位置
|
||||||
Containered_sock_path string
|
Total_file_mem_limit string //磁盘空间限制
|
||||||
|
Containered_sock_path string //ctr sock地址
|
||||||
}
|
}
|
||||||
type Coredump_config struct {
|
type Coredump_config struct {
|
||||||
Initial_ns_pid string
|
Initial_ns_pid string
|
||||||
Process_ns_pid string
|
Process_ns_pid string
|
||||||
Process_exe_path string
|
Process_exe_path string
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
Corepipe_config_path string
|
Corepipe_config_path string `json:"-"`
|
||||||
Image_id string
|
Image_id string
|
||||||
UID string
|
UID string
|
||||||
GID string
|
GID string
|
||||||
|
|||||||
Reference in New Issue
Block a user