Skip to content

Commit

Permalink
update crd
Browse files Browse the repository at this point in the history
Signed-off-by: ii2day <ji.li@daocloud.io>
  • Loading branch information
ii2day committed Aug 23, 2023
1 parent 52b93dc commit 276d452
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 36 deletions.
1 change: 0 additions & 1 deletion charts/crds/kdoctor.io_apphttphealthies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ spec:
type: object
type: object
terminationGracePeriodMinutes:
default: 60
format: int64
type: integer
type: object
Expand Down
1 change: 0 additions & 1 deletion charts/crds/kdoctor.io_netdnses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,6 @@ spec:
type: object
type: object
terminationGracePeriodMinutes:
default: 60
format: int64
type: integer
type: object
Expand Down
1 change: 0 additions & 1 deletion charts/crds/kdoctor.io_netreaches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ spec:
type: object
type: object
terminationGracePeriodMinutes:
default: 60
format: int64
type: integer
type: object
Expand Down
1 change: 1 addition & 0 deletions charts/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data:
nethttp_defaultRequest_PerRequestTimeoutInMS: {{ .Values.feature.nethttp_defaultRequest_PerRequestTimeoutInMS }}
netdns_defaultConcurrency: {{ .Values.feature.netdns_defaultConcurrency }}
multusPodAnnotationKey: {{ .Values.feature.multusPodAnnotationKey }}
agentDefaultTerminationGracePeriodMinutes: {{ .Values.feature.agentDefaultTerminationGracePeriodMinutes }}
crdMaxHistory: {{ .Values.feature.crdMaxHistory }}
{{- if .Values.feature.enableIPv4 }}
agentSerivceIpv4Name: {{ include "project.kdoctorAgent.serviceIpv4Name" . }}
Expand Down
7 changes: 4 additions & 3 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ feature:
## @param feature.netdns_defaultConcurrency concurrency for kind netdns
netdns_defaultConcurrency: 50

## @param feature.agentDefaultTerminationGracePeriodMinutes agent termination after minutes
agentDefaultTerminationGracePeriodMinutes: 60

## @param feature.taskPollIntervalInSecond the interval to poll the task in controller and agent pod
taskPollIntervalInSecond: 5

Expand Down Expand Up @@ -213,9 +216,7 @@ kdoctorAgent:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 100m
memory: 128Mi


## @param kdoctorAgent.securityContext the security Context of kdoctorAgent pod
securityContext: {}
Expand Down
20 changes: 10 additions & 10 deletions docs/reference/apphttphealthy-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ status:
#### AgentSpec
| 字段 | 描述 | 结构 | 验证 | 取值 | 默认值 |
|-------------------------------|------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----|----------------------|--------------------|
| annotation | agent 工作负载的 annotation | map[string]string | 可选 | | |
| kind | agent 工作负载的类型 | string | 可选 | Deployment、DaemonSet | DaemonSet |
| deploymentReplicas | agent 工作负载类型为 deployment 时的期望副本数 | int | 可选 | 大于等于 0 | 0 |
| affinity | agent 工作负载亲和性 | [labelSelector](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L1195) | 可选 | | |
| env | agent 工作负载环境变量 | [env](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2012) | 可选 | | |
| hostNetwork | agent 工作负载是否使用宿主机网络 | bool | 可选 | true、false | false |
| resources | agent 工作负载资源使用配置 | [resources](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2333) | 可选 | | cpu:100m,memory:128Mi |
| terminationGracePeriodMinutes | agent 工作负载完成任务后多少分钟之后终止 | int | 可选 | 大于等于 0 | 60 |
| 字段 | 描述 | 结构 | 验证 | 取值 | 默认值 |
|-------------------------------|------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----|----------------------|-------------------------------|
| annotation | agent 工作负载的 annotation | map[string]string | 可选 | | |
| kind | agent 工作负载的类型 | string | 可选 | Deployment、DaemonSet | DaemonSet |
| deploymentReplicas | agent 工作负载类型为 deployment 时的期望副本数 | int | 可选 | 大于等于 0 | 0 |
| affinity | agent 工作负载亲和性 | [labelSelector](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L1195) | 可选 | | |
| env | agent 工作负载环境变量 | [env](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2012) | 可选 | | |
| hostNetwork | agent 工作负载是否使用宿主机网络 | bool | 可选 | true、false | false |
| resources | agent 工作负载资源使用配置 | [resources](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2333) | 可选 | | limit cpu:1000m,memory:1024Mi |
| terminationGracePeriodMinutes | agent 工作负载完成任务后多少分钟之后终止 | int | 可选 | 大于等于 0 | 60 |
#### Schedule
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/netdns-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ spec:
| affinity | agent 工作负载亲和性 | [labelSelector](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L1195) | 可选 | | |
| env | agent 工作负载环境变量 | [env](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2012) | 可选 | | |
| hostNetwork | agent 工作负载是否使用宿主机网络 | bool | 可选 | true、false | false |
| resources | agent 工作负载资源使用配置 | [resources](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2333) | 可选 | | |
| resources | agent 工作负载资源使用配置 | [resources](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2333) | 可选 | | limit cpu:1000m,memory:1024Mi |
| terminationGracePeriodMinutes | agent 工作负载完成任务后多少分钟之后终止 | int | 可选 | 大于等于 0 | 60 |
Expand Down
20 changes: 10 additions & 10 deletions docs/reference/netreach-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ status:
#### AgentSpec
| 字段 | 描述 | 结构 | 验证 | 取值 | 默认值 |
|-------------------------------|------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----|----------------------|-----------|
| annotation | agent 工作负载的 annotation | map[string]string | 可选 | | |
| kind | agent 工作负载的类型 | string | 可选 | Deployment、DaemonSet | DaemonSet |
| deploymentReplicas | agent 工作负载类型为 deployment 时的期望副本数 | int | 可选 | 大于等于 0 | 0 |
| affinity | agent 工作负载亲和性 | [labelSelector](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L1195) | 可选 | | |
| env | agent 工作负载环境变量 | [env](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2012) | 可选 | | |
| hostNetwork | agent 工作负载是否使用宿主机网络 | bool | 可选 | true、false | false |
| resources | agent 工作负载资源使用配置 | [resources](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2333) | 可选 | | |
| terminationGracePeriodMinutes | agent 工作负载完成任务后多少分钟之后终止 | int | 可选 | 大于等于 0 | 60 |
| 字段 | 描述 | 结构 | 验证 | 取值 | 默认值 |
|-------------------------------|------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----|----------------------|--------------------------------|
| annotation | agent 工作负载的 annotation | map[string]string | 可选 | | |
| kind | agent 工作负载的类型 | string | 可选 | Deployment、DaemonSet | DaemonSet |
| deploymentReplicas | agent 工作负载类型为 deployment 时的期望副本数 | int | 可选 | 大于等于 0 | 0 |
| affinity | agent 工作负载亲和性 | [labelSelector](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L1195) | 可选 | | |
| env | agent 工作负载环境变量 | [env](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2012) | 可选 | | |
| hostNetwork | agent 工作负载是否使用宿主机网络 | bool | 可选 | true、false | false |
| resources | agent 工作负载资源使用配置 | [resources](https://github.com/kubernetes/kubernetes/blob/v1.27.0/staging/src/k8s.io/api/core/v1/types.go#L2333) | 可选 | | limit cpu:1000m,memory:1024Mi |
| terminationGracePeriodMinutes | agent 工作负载完成任务后多少分钟之后终止 | int | 可选 | 大于等于 0 | 60 |
Expand Down
35 changes: 34 additions & 1 deletion docs/reference/runtime-zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## runtime

当下发任务 CR 后,kdoctor-controller 会根据 CR 中的 AgentSpec 生成对应的任务载体(DaemonSet 或 Deployment)执行任务,每一个任务独立使用一个载体。
当下发任务 CR 后,kdoctor-controller 会根据 CR 中的 AgentSpec 生成对应的任务载体(DaemonSet 或 Deployment)当所有 Pod 就绪后,开始按照 Spec 中的任务定义执行任务,每一个任务独立使用一个载体。

### 载体资源

Expand All @@ -24,3 +24,36 @@

当任务 CR 下发后,kdoctor-controller 会将任务注册进 ReportManager,ReportManager 会定期去每一个任务负载中通过 GRPC 接口获取报告,并聚合
在 kdoctor-controller 中,聚合后可通过命令 `kubectl get kdoctorreport` 获取报告结果,因此,若报告未收集完成就将工作负载删除将影响报告聚合结果。


### 生命周期

```mermaid
sequenceDiagram
participant cr 任务
participant kdoctor_controller
participant workload
participant pod
participant service
participant ingress
cr 任务 ->>kdoctor_controller: cr 任务下发
kdoctor_controller ->>workload: 创建 ownerReferences 为任务 cr 工作负载(daemonSet 或 Deployment)
workload ->>pod: 创建任务执行 pod
kdoctor_controller ->>service: 创建 ownerReferences 为工作负载的 service
kdoctor_controller ->>ingress: 创建 ownerReferences 为工作负载的 ingress
workload ->>kdoctor_controller: workload 就绪
service ->>kdoctor_controller: service 就绪
ingress ->>kdoctor_controller: ingress 就绪
kdoctor_controller ->>pod: 任务执行
kdoctor_controller ->>pod: 定时收取报告
pod ->>kdoctor_controller: 任务执行完成
kdoctor_controller ->>pod: 报告收取完成
kdoctor_controller ->>workload: 到达 runtime 销毁时间,销毁 workload
workload ->>service: 到达 runtime 销毁时间,销毁 service
workload ->>ingress: 到达 runtime 销毁时间,销毁 ingress
cr 任务 ->>kdoctor_controller: cr 任务删除
kdoctor_controller ->> workload: cr 任务删除,workload 删除
workload ->> pod: workload 删除,pod 删除
workload ->>service: workload 删除,service 删除
workload ->>ingress: workload 删除,ingress 删除
1 change: 0 additions & 1 deletion pkg/k8s/apis/kdoctor.io/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ type AgentSpec struct {
// +kubebuilder:validation:Optional
Resources *v1.ResourceRequirements `json:"resources,omitempty"`

// +kubebuilder:default=60
// +kubebuilder:validation:Optional
TerminationGracePeriodMinutes *int64 `json:"terminationGracePeriodMinutes,omitempty"`
}
7 changes: 7 additions & 0 deletions pkg/pluginManager/apphttphealthy/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func (s *PluginAppHttpHealthy) WebhookMutating(logger *zap.Logger, ctx context.C
}
}

// agentSpec
if true {
if req.Spec.AgentSpec.TerminationGracePeriodMinutes == nil {
req.Spec.AgentSpec.TerminationGracePeriodMinutes = &types.ControllerConfig.Configmap.AgentDefaultTerminationGracePeriodMinutes
}
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/pluginManager/netdns/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func (s *PluginNetDns) WebhookMutating(logger *zap.Logger, ctx context.Context,
}
logger.Sugar().Infof("obj: %+v", r)

// agentSpec
if true {
if r.Spec.AgentSpec.TerminationGracePeriodMinutes == nil {
r.Spec.AgentSpec.TerminationGracePeriodMinutes = &types.ControllerConfig.Configmap.AgentDefaultTerminationGracePeriodMinutes
}
}
// TODO: mutating default value

return nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/pluginManager/netreach/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func (s *PluginNetReach) WebhookMutating(logger *zap.Logger, ctx context.Context
logger.Sugar().Debugf("set default SuccessCondition for NetReach %v", req.Name)
}

// agentSpec
if true {
if req.Spec.AgentSpec.TerminationGracePeriodMinutes == nil {
req.Spec.AgentSpec.TerminationGracePeriodMinutes = &types.ControllerConfig.Configmap.AgentDefaultTerminationGracePeriodMinutes
}
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type ConfigmapConfig struct {
AgentIngressName string `yaml:"agentIngressName"`
AgentDaemonsetName string `yaml:"agentDaemonsetName"`

KdoctorAgent KdoctorAgentConfig `yaml:"kdoctorAgent"`
AgentDefaultTerminationGracePeriodMinutes int64 `yaml:"agentDefaultTerminationGracePeriodMinutes"`
KdoctorAgent KdoctorAgentConfig `yaml:"kdoctorAgent"`
}

type KdoctorAgentConfig struct {
Expand Down
Loading

0 comments on commit 276d452

Please sign in to comment.