Skip to content

Commit

Permalink
feat: 新增status字段逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
googs1025 committed Jan 6, 2024
1 parent b84c76f commit 22ebec8
Show file tree
Hide file tree
Showing 32 changed files with 282 additions and 63 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
spec:
# 设置多个 step 步骤,会按照填入的 container 顺序执行
steps:
# 每项都是一个 container 对象
# 每项都是一个 container 对象,每个 container 都会顺序执行
- name: step1
image: busybox:1.28
command: [ "sh","-c" ]
Expand All @@ -23,12 +23,27 @@ spec:
args: [ "echo step2" ]
- name: step3
image: devopscube/kubernetes-job-demo:latest
args: [ "100" ]
args: [ "10" ]
```
### 项目功能
1. 支持任务中的 container 顺序执行
2. 查看任务流状态
```bash
[root@VM-0-16-centos yaml]# kubectl get tasks.api.practice.com
NAME STATUS START DURATION AGE
example-taskflow Successful 2024-01-06 22:19:24 31s 80s
example-taskflow-error-test Running 2024-01-06 22:20:36 6s
[root@VM-0-16-centos yaml]# kubectl get tasks.api.practice.com
NAME STATUS START DURATION AGE
example-taskflow Successful 2024-01-06 22:19:24 31s 84s
example-taskflow-error-test Failure 2024-01-06 22:20:36 6s 10s
[root@VM-0-16-centos yaml]# kubectl get tasks.api.practice.com
NAME STATUS START DURATION AGE
example-taskflow Successful 2024-01-06 22:19:24 31s 86s
example-taskflow-error-test Failure 2024-01-06 22:20:36 6s 12s
```

### 项目部署与使用
1. 打成镜像或是使用编译二进制。
Expand Down Expand Up @@ -131,6 +146,6 @@ I0101 05:17:12.141048 1 helper.go:242] annotation order: 2
I0101 05:17:12.141057 1 task_controller.go:49] successful reconcile
I0101 05:17:12.141302 1 helper.go:241] pod status: Running
```

6. 使用 资源对象

### RoadMap
5 changes: 4 additions & 1 deletion container-agent/cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// ValidateFlags 检查参数
func ValidateFlags() {
if encodeFile == "" {
if waitFile == "" || out == "" || command == "" {
if waitFile == "" || out == "" {
log.Println("error input param...")
os.Exit(1)
}
Expand Down Expand Up @@ -119,6 +119,9 @@ func ExecCmdAndArgs(args []string) {
cmd := ""
// 非加密文件模式
if encodeFile == "" {
if command == "" {
command = "sh"
}
cmdList := strings.Split(command, " ") // 如 sh -c 这种字符串,要切割,取出第一个作为command
cmd = cmdList[0] //肯定有值 ,所以不用判断
if len(cmdList) > 1 { //把剩余的合并到argList 前面
Expand Down
13 changes: 13 additions & 0 deletions deploy/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ spec:
served: true
#是否是存储版本
storage: true
additionalPrinterColumns:
- name: Status
type: string
jsonPath: .status.status
- name: Start
type: string
jsonPath: .status.startAt
- name: Duration
type: string
jsonPath: .status.duration
- name: Age
type: date
jsonPath: .metadata.creationTimestamp
schema:
openAPIV3Schema:
type: object
Expand Down
16 changes: 4 additions & 12 deletions docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ IMAGE_NAME="docker.io/taskflow/agent" # 镜像名称
TAG="v1.0" # 镜像标签


# 检查镜像是否已经存在
if docker inspect "${IMAGE_NAME}:${TAG}" &> /dev/null; then
echo "镜像 ${IMAGE_NAME}:${TAG} 已存在,无需构建。"
else
echo "镜像 ${IMAGE_NAME}:${TAG} 不存在,开始构建..."
# 执行 Docker build 命令
docker build -t "${IMAGE_NAME}:${TAG}" -f "${DOCKERFILE_PATH}" .
echo "镜像构建完成。"

# 可选:推送镜像到 Docker 镜像仓库
# docker push "${IMAGE_NAME}:${TAG}"
fi
echo "镜像 ${IMAGE_NAME}:${TAG} 开始构建..."
# 执行 Docker build 命令
docker build -t "${IMAGE_NAME}:${TAG}" -f "${DOCKERFILE_PATH}" .
echo "镜像构建完成。"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/myoperator/cicdoperator
module github.com/myoperator/taskflowoperator

go 1.18

Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
taskv1alpha1 "github.com/myoperator/cicdoperator/pkg/apis/task/v1alpha1"
"github.com/myoperator/cicdoperator/pkg/controller"
builder2 "github.com/myoperator/cicdoperator/pkg/image"
"github.com/myoperator/cicdoperator/pkg/k8sconfig"
taskv1alpha1 "github.com/myoperator/taskflowoperator/pkg/apis/task/v1alpha1"
"github.com/myoperator/taskflowoperator/pkg/controller"
builder2 "github.com/myoperator/taskflowoperator/pkg/image"
"github.com/myoperator/taskflowoperator/pkg/k8sconfig"
corev1 "k8s.io/api/core/v1"
_ "k8s.io/code-generator"
"log"
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/task/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Task struct {
// TODO: 加入 TaskStatus 用于查看每个工作流的状态 Running Complete Failed ...
// TODO: 记录运行时间,需要在 status加入一个时间值字段 开始时记录时间 结束或错误退出时记录时间
// 在调协中修改 status
Status TaskStatus `json:"status,omitempty"`
}

type TaskSpec struct {
Expand All @@ -30,6 +31,15 @@ type TaskStep struct {
Script string `json:"script,omitempty"`
}

type TaskStatus struct {
// Status 任务状态
Status string `json:"status"`
// StartAt 任务起始时间
StartAt string `json:"startAt"`
// Duration 任务执行多久
Duration string `json:"duration"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// TaskList ..
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/task/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/client/clientset/versioned/fake/clientset_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/client/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/client/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions pkg/client/clientset/versioned/typed/task/v1alpha1/task.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/client/clientset/versioned/typed/tasks/v1alpha1/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/client/clientset/versioned/typed/tasks/v1alpha1/fake/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 22ebec8

Please sign in to comment.