-
Notifications
You must be signed in to change notification settings - Fork 832
feat(configmapset): enables zero-downtime configuration updates #2149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Placeboy
wants to merge
1
commit into
openkruise:master
Choose a base branch
from
Placeboy:feature/configmapset
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/intstr" | ||
| ) | ||
|
|
||
| // ConfigMapSetSpec defines the desired state of ConfigMapSet | ||
| type ConfigMapSetSpec struct { | ||
| // +optional | ||
| // 当前版本的别名 | ||
| CustomVersion string `json:"customVersion,omitempty"` | ||
| // Selector 用来挑选pod | ||
| Selector *metav1.LabelSelector `json:"selector"` | ||
| // Data 存放的是配置与内容的映射 | ||
| Data map[string]string `json:"data"` | ||
| // InjectedContainers 表示的是需要被注入配置的容器 | ||
| InjectedContainers []InjectedContainerSpec `json:"injectedContainers"` | ||
| // RevisionHistoryLimit 用于描述 最多在RMC中维护多少个版本的数据 | ||
| // +optional | ||
| RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` | ||
| // InjectUpdateOrder 为 true 表示采用仅注入策略, controller为需要重启的pod打上标签 configmapset.cms1/updateOrder=1 | ||
| // +optional | ||
| InjectUpdateOrder bool `json:"injectUpdateOrder,omitempty"` | ||
| // UpdateStrategy 指定更新策略, 详见结构体定义 | ||
| // +optional | ||
| UpdateStrategy ConfigMapSetUpdateStrategy `json:"updateStrategy,omitempty"` | ||
| } | ||
|
|
||
| type InjectedContainerSpec struct { | ||
| // +optional | ||
| Name string `json:"name,omitempty"` // 需要挂载配置的容器名(静态注入) | ||
| // +optional | ||
| NameFrom *ValueFromSource `json:"NameFrom,omitempty"` // 从pod中获取(动态注入), 如metadata.labels['cName'] | ||
| MountPath string `json:"mountPath"` // 容器内挂载路径 | ||
| } | ||
|
|
||
| type ValueFromSource struct { | ||
| FieldRef corev1.ObjectFieldSelector `json:"fieldRef"` | ||
| } | ||
|
|
||
| type Distribution struct { | ||
| // +optional | ||
| Revision string `json:"revision,omitempty"` // 版本hash | ||
| // +optional | ||
| CustomVersion string `json:"customVersion,omitempty"` // caster上的版本别名 | ||
| Reserved int32 `json:"reserved"` // 需要多少个该版本的实例 | ||
| // +optional | ||
| Preferred bool `json:"preferred,omitempty"` // 当设置为true时, 如果所有distribution的数量加起来小于pod总数, 则其他的pod都使用该版本 | ||
| } | ||
|
|
||
| type ConfigMapSetUpdateStrategy struct { | ||
| // +optional | ||
| Distributions []Distribution `json:"distributions,omitempty"` | ||
| // +optional | ||
| Partition *intstr.IntOrString `json:"partition,omitempty"` // 旧版本的比例, 多个旧版本的情况不做区分 | ||
| // +optional | ||
| RestartInjectedContainers bool `json:"restartInjectedContainers,omitempty"` // 开启该选项后, 被注入最新配置的容器发生重启 | ||
| // +optional | ||
| MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"` // 最大同时不可用实例数 | ||
| } | ||
|
|
||
| // ConfigMapSetStatus 定义观测状态 | ||
| type ConfigMapSetStatus struct { | ||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
| CurrentRevision string `json:"currentRevision,omitempty"` // 当前版本hash, 即partition中最新的版本 | ||
| UpdateRevision string `json:"updateRevision,omitempty"` // 目标版本hash, 即partition以外的版本 | ||
| MatchedPods int32 `json:"matchedPods"` // 根据标签匹配到的pod数量(不含terminating的) | ||
| UpdatedPods int32 `json:"updatedPods"` // 已经最新的pod数量 | ||
| ReadyPods int32 `json:"readyPods"` // 所有pod里面ready的数量 | ||
| UpdatedReadyPods int32 `json:"updatedReadyPods"` // 已经最新的pod里面ready的数量 | ||
| LastContainersTimestamp *metav1.Time `json:"lastContainersTimestamp"` // spec.containers最后一次更新时间, 用于冷启动决策 | ||
| LastContainersHash string `json:"lastContainersHash"` // 上一个cms版本spec.containers的hash值 | ||
| LastSpecTimestamp *metav1.Time `json:"lastSpecTimestamp"` // spec最后一次更新时间 | ||
| LastSpecHash string `json:"lastSpecHash"` // 上一个cms版本spec的hash值 | ||
| } | ||
|
|
||
| // +genclient | ||
| // +k8s:openapi-gen=true | ||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:resource:shortName=cms,singular=configmapset,path=configmapsets,scope=Namespaced | ||
| // +kubebuilder:printcolumn:name="MatchedPods",type=integer,JSONPath=`.status.matchedPods`,description="Number of matched pods" | ||
| // +kubebuilder:printcolumn:name="UpdatedPods",type=integer,JSONPath=`.status.updatedPods`,description="Number of updated pods" | ||
| // +kubebuilder:printcolumn:name="ReadyPods",type=integer,JSONPath=`.status.readyPods`,description="Number of ready pods" | ||
| // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` | ||
|
|
||
| type ConfigMapSet struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec ConfigMapSetSpec `json:"spec,omitempty"` | ||
| // +optional | ||
| Status ConfigMapSetStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| type ConfigMapSetList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []ConfigMapSet `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&ConfigMapSet{}, &ConfigMapSetList{}) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz consider extract the RestartInjectedContainers field to a separate field in the ConfigMapSetSpec, maybe called "LoadStrategy", with three possible option