ResourceInterpreterCustomization v1alpha1
apiVersion: config.karmada.io/v1alpha1
import "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
ResourceInterpreterCustomization
ResourceInterpreterCustomization 描述特定资源的配置,方便 Karmada 获取结构。它的优先级高于默认解释器和 webhook 解释器。
-
apiVersion: config.karmada.io/v1alpha1
-
kind: ResourceInterpreterCustomization
-
metadata (ObjectMeta)
-
spec (ResourceInterpreterCustomizationSpec),必选
Spec 是配置的详情。
ResourceInterpreterCustomizationSpec
ResourceInterpreterCustomizationSpec 是配置的详情。
-
customizations (CustomizationRules),必选
Customizations 是对解释规则的描述。
CustomizationRules 是对解释规则的描述。
-
customizations.dependencyInterpretation (DependencyInterpretation)
DependencyInterpretation 描述了 Karmada 分析依赖资源的规则。Karmada 为几种标准的 Kubernetes 类型提供了内置规则。如果设置了 DependencyInterpretation,内置规则将被忽略。更多信息,请浏览:https://karmada.io/docs/userguide/globalview/customizing-resource-interpreter/#interpretdependency
DependencyInterpretation 是用于解释特定资源的依赖资源的规则。
-
customizations.dependencyInterpretation.luaScript (string),必选
LuaScript 是用于解释特定资源的依赖关系的 Lua 脚本。该脚本应实现以下功能:
luaScript: >
function GetDependencies(desiredObj)
dependencies = []
serviceAccountName = desiredObj.spec.template.spec.serviceAccountName
if serviceAccountName ~= nil and serviceAccountName ~= "default" then
dependency = []
dependency.apiVersion = "v1"
dependency.kind = "ServiceAccount"
dependency.name = serviceAccountName
dependency.namespace = desiredObj.metadata.namespace
dependencies[1] = dependency
end
return dependencies
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
- desiredObj:将应用于成员集群的配置。
返回值由 DependentObjectReference 的列表表示。
-
-
-
customizations.healthInterpretation (HealthInterpretation)
HealthInterpretation 描述了健康评估规则,Karmada 可以通过这些规则评估各类资源的健康状态。
HealthInterpretation 是解释特定资源健康状态的规则。
-
customizations.healthInterpretation.luaScript (string),必选
LuaScript 是评估特定资源的健康状态的 Lua 脚本。该脚本应实现以下功能:
luaScript: >
function InterpretHealth(observedObj)
if observedObj.status.readyReplicas == observedObj.spec.replicas then
return true
end
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
- observedObj:从特定成员集群观测到的配置。
返回的 boolean 值表示健康状态。
-
-
customizations.replicaResource (ReplicaResourceRequirement)
ReplicaResource 描述了 Karmada 发现资源副本及资源需求的规则。对于声明式工作负载类型(如 Deployment)的 CRD 资源,可能会有用。由于 Karmada 知晓发现 Kubernetes 本机资源信息的方式,因此 Kubernetes 本机资源(Deployment、Job)通常不需要该字段。但如果已设置该字段,内置的发现规则将被忽略。
ReplicaResourceRequirement 保存了获取所需副本及每个副本资源要求的脚本。
-
customizations.replicaResource.luaScript (string),必选
LuaScript 是发现资源所用的副本以及资源需求的 Lua 脚本。
该脚本应实现以下功能:
luaScript: >
function GetReplicas(desiredObj)
replica = desiredObj.spec.replicas
requirement = []
requirement.nodeClaim = []
requirement.nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector
requirement.nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations
requirement.resourceRequest = desiredObj.spec.template.spec.containers[1].resources.limits
return replica, requirement
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
- desiredObj:待应用于成员集群的配置。
该函数有两个返回值:
- replica:声明的副本编号。
- requirement:每个副本所需的资源,使用 ResourceBindingSpec.ReplicaRequirements 表示。
返回值将被 ResourceBinding 或 ClusterResourceBinding 使用。
-
-
customizations.replicaRevision (ReplicaRevision)
ReplicaRevision 描述了 Karmada 修改资源副本的规则。对于声明式工作负载类型(如 Deployment)的 CRD 资源,可能会有用。由于 Karmada 知晓修改 Kubernetes 本机资源副本的方式,因此 Kubernetes 本机资源(Deployment、Job)通常不需要该字段。但如果已设置该字段,内置的修改规则将被忽略。
ReplicaRevision 保存了用于修改所需副本的脚本。
-
customizations.replicaRevision.luaScript (string),必选
LuaScript 是修改所需规范中的副本的 Lua 脚本。该脚本应实现以下功能:
luaScript: >
function ReviseReplica(desiredObj, desiredReplica)
desiredObj.spec.replicas = desiredReplica
return desiredObj
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
-
desiredObj:待应用于成员集群的配置。
-
desiredReplica:待应用于成员集群的期望副本数。
返回的是修订后的配置,最终将应用于成员集群。
-
customizations.retention (LocalValueRetention)
Retention 描述了 Karmada 对成员集群组件变化的预期反应。这样可以避免系统进入无意义循环,即 Karmada 资源控制器和成员集群组件,对同一个字段采用不同的值。例如,成员群集的 HPA 控制器可能会更改 Deployment 的 replicas。在这种情况下,Karmada 会保留 replicas,而不会去更改它。
LocalValueRetention 保存了要保留的脚本。当前只支持 Lua 脚本。
-
customizations.retention.luaScript (string),必选
LuaScript 是将运行时值保留到所需规范的 Lua 脚本。
该脚本应实现以下功能:
luaScript: >
function Retain(desiredObj, observedObj)
desiredObj.spec.fieldFoo = observedObj.spec.fieldFoo
return desiredObj
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
-
desiredObj:待应用于成员集群的配置。
-
observedObj:从特定成员集群观测到的配置。
-
返回的是保留的配置,最终将应用于成员集群。
-
-
-
customizations.statusAggregation (StatusAggregation)
StatusAggregation 描述了 Karmada 从成员集群收集的状态汇总到资源模板的规则。Karmada 为几种标准的 Kubernetes 类型提供了内置规则。如果设置了 StatusAggregation,内置规则将被忽略。更多信息,请浏览:https://karmada.io/docs/userguide/globalview/customizing-resource-interpreter/#aggregatestatus
StatusAggregation 保存了用于聚合多个分散状态的脚本。
-
customizations.statusAggregation.luaScript (string),必选
LuaScript 是将分散状态聚合到所需规范的 Lua 脚本。该脚本应实现以下功能:
luaScript: >
function AggregateStatus(desiredObj, statusItems)
for i = 1, #statusItems do
desiredObj.status.readyReplicas = desiredObj.status.readyReplicas + items[i].readyReplicas
end
return desiredObj
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
- desiredObj:资源模板。
- statusItems:用 AggregatedStatusItem 表示的状态列表。
返回的是状态聚合成的完整对象。
-
customizations.statusReflection (StatusReflection)
StatusReflection 描述了 Karmada 挑选资源状态的规则。Karmada 为几种标准的 Kubernetes 类型提供了内置规则。如果设置了 StatusReflection,内置规则将被忽略。更多信息,请浏览:https://karmada.io/docs/userguide/globalview/customizing-resource-interpreter/#interpretstatus
StatusReflection 保存了用于获取状态的脚本。
-
customizations.statusReflection.luaScript (string),必选
LuaScript 是从观测到的规范中获取状态的 Lua 脚本。该脚本应实现以下功能:
luaScript: >
function ReflectStatus(observedObj)
status = []
status.readyReplicas = observedObj.status.observedObj
return status
endLuaScript 的内容是一个完整的函数,包括声明和定义。
以下参数将由系统提供:
- observedObj:从特定成员集群观测到的配置。
返回的是整个状态,也可以是状态的一部分,并会被 Work 和 ResourceBinding(ClusterResourceBinding) 使用。
-
-
-
target (CustomizationTarget),必选
CustomizationTarget 表示自定义的资源类型。
CustomizationTarget 表示自定义的资源类型。
-
target.apiVersion(string),必选
APIVersion 表示目标资源的 API 版本。
-
target.kind(string),必选
Kind 表示目标资源的类别。
-
ResourceInterpreterCustomizationList
ResourceInterpreterCustomizationList 包含 ResourceInterpreterCustomization 的列表。
-
apiVersion: config.karmada.io/v1alpha1
-
kind: ResourceInterpreterCustomizationList
-
metadata (ListMeta)
-
items ([]ResourceInterpreterCustomization),必选
操作
get:查询指定的 ResourceInterpreterCustomization
HTTP 请求
GET /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 的名称
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
get:查询指定 ResourceInterpreterCustomization 的状态
HTTP 请求
GET /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}/status
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 名称
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
list:查询所有 ResourceInterpreterCustomization
HTTP 请求
GET /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations
参数
-
allowWatchBookmarks(查询参数):boolean
-
continue(查询参数):string
-
fieldSelector(查询参数):string
-
labelSelector(查询参数):string
-
limit(查询参数):integer
-
pretty(查询参数):string
-
resourceVersion(查询参数):string
-
resourceVersionMatch(查询参数):string
-
sendInitialEvents(查询参数):boolean
-
timeoutSeconds(查询参数):integer
-
watch(查询参数):boolean
响应
200 (ResourceInterpreterCustomizationList): OK
create:创建一个 ResourceInterpreterCustomization
HTTP 请求
POST /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations
参数
-
body: ResourceInterpreterCustomization,必选
-
dryRun(查询参数):string
-
fieldManager(查询参数):string
-
fieldValidation(查询参数):string
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
201 (ResourceInterpreterCustomization): Created
202 (ResourceInterpreterCustomization): Accepted
update:更新指定的 ResourceInterpreterCustomization
HTTP 请求
PUT /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 名称
-
body: ResourceInterpreterCustomization,必选
-
dryRun(查询参数):string
-
fieldManager(查询参数):string
-
fieldValidation(查询参数):string
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
201 (ResourceInterpreterCustomization): Created
update:更新指定 ResourceInterpreterCustomization 的状态
HTTP 请求
PUT /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}/status
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 的名称
-
body: ResourceInterpreterCustomization,必选
-
dryRun(查询参数):string
-
fieldManager(查询参数):string
-
fieldValidation(查询参数):string
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
201 (ResourceInterpreterCustomization): Created
patch:更新指定 ResourceInterpreterCustomization 的部分信息
HTTP 请求
PATCH /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 的名称
-
body: Patch,必选
-
dryRun(查询参数):string
-
fieldManager(查询参数):string
-
fieldValidation(查询参数):string
-
force(查询参数):boolean
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
201 (ResourceInterpreterCustomization): Created
patch:更新指定 ResourceInterpreterCustomization 状态的部分信息
HTTP 请求
PATCH /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}/status
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 的名称
-
body: Patch,必选
-
dryRun(查询参数):string
-
fieldManager(查询参数):string
-
fieldValidation(查询参数):string
-
force(查询参数):boolean
-
pretty(查询参数):string
响应
200 (ResourceInterpreterCustomization): OK
201 (ResourceInterpreterCustomization): Created
delete:删除一个 ResourceInterpreterCustomization
HTTP 请求
DELETE /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations/{name}
参数
-
name(路径参数):string,必选
ResourceInterpreterCustomization 名称
-
body: DeleteOptions
-
dryRun(查询参数):string
-
gracePeriodSeconds(查询参数):integer
-
pretty(查询参数):string
-
propagationPolicy(查询参数):string
响应
200 (Status): OK
202 (Status): Accepted
deletecollection:删除所有 ResourceInterpreterCustomization
HTTP 请求
DELETE /apis/config.karmada.io/v1alpha1/resourceinterpretercustomizations
参数
-
body: DeleteOptions
-
continue(查询参数):string
-
dryRun(查询参数):string
-
fieldSelector(查询参数):string
-
gracePeriodSeconds(查询参数):integer
-
labelSelector(查询参数):string
-
limit(查询参数):integer
-
pretty(查询参数):string
-
propagationPolicy(查询参数):string
-
resourceVersion(查询参数):string
-
resourceVersionMatch(查询参数):string
-
sendInitialEvents(查询参数):boolean
-
timeoutSeconds(查询参数):integer
响应
200 (Status): OK