-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from zong-zhe/add-affinity
feat: add 'affinity' to server
- Loading branch information
Showing
18 changed files
with
327 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,11 @@ | ||
import konfig.models.kube.frontend | ||
import konfig.models.kube.frontend.container | ||
import konfig.models.kube.templates.resource as res_tpl | ||
|
||
# Application Configuration | ||
appConfiguration: frontend.Server { | ||
# Main Container Configuration | ||
mainContainer = container.Main {} | ||
schedulingStrategy.resource = res_tpl.tiny | ||
image = "gcr.io/google-samples/gb-frontend:v4" | ||
} |
This file contains 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,7 @@ | ||
[package] | ||
name = "nginx-example" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
konfig = { path = "../../../../konfig" } | ||
k8s = "1.28" |
This file contains 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,10 @@ | ||
[package] | ||
name = "app_affinity-prod" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
konfig = { path = "../../../../../konfig" } | ||
k8s = "1.28" | ||
[profile] | ||
entries = ["../base/base.k", "main.k", "${konfig:KCL_MOD}/models/kube/render/render.k"] | ||
|
This file contains 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,20 @@ | ||
import konfig.models.kube.frontend | ||
|
||
# The application configuration in stack will overwrite | ||
# the configuration with the same attribute in base. | ||
appConfiguration: frontend.Server { | ||
affinity: { | ||
podAntiAffinity: { | ||
requiredDuringSchedulingIgnoredDuringExecution: [{ | ||
labelSelector: { | ||
matchExpressions: [{ | ||
key: "app", | ||
operator: "In", | ||
values: ["release-rest-server"] | ||
}] | ||
}, | ||
topologyKey: "kubernetes.io/hostname" | ||
}] | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "app_stateful_set-prod" | ||
name = "app_deployment_strategy-prod" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
|
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "konfig" | ||
version = "0.11.0" | ||
version = "0.12.0" | ||
|
||
[dependencies] | ||
k8s = "1.31.2" |
This file contains 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 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,29 @@ | ||
""" | ||
This is the affinity module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema Affinity: | ||
r""" | ||
Affinity is a group of affinity scheduling rules. | ||
|
||
Attributes | ||
---------- | ||
nodeAffinity : NodeAffinity, default is Undefined, optional | ||
Describes node affinity scheduling rules for the pod. | ||
podAffinity : PodAffinity, default is Undefined, optional | ||
Describes pod affinity scheduling rules (e.g. co-locate this pod in the same node, zone, etc. as some other pod(s)). | ||
podAntiAffinity : PodAntiAffinity, default is Undefined, optional | ||
Describes pod anti-affinity scheduling rules (e.g. avoid putting this pod in the same node, zone, etc. as some other pod(s)). | ||
""" | ||
|
||
|
||
nodeAffinity?: NodeAffinity | ||
|
||
podAffinity?: PodAffinity | ||
|
||
podAntiAffinity?: PodAntiAffinity | ||
|
||
|
This file contains 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,25 @@ | ||
""" | ||
This is the node_affinity module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema NodeAffinity: | ||
r""" | ||
Node affinity is a group of node affinity scheduling rules. | ||
|
||
Attributes | ||
---------- | ||
preferredDuringSchedulingIgnoredDuringExecution : [PreferredSchedulingTerm], default is Undefined, optional | ||
The scheduler will prefer to schedule pods to nodes that satisfy the affinity expressions specified by this field, but it may choose a node that violates one or more of the expressions. The node that is most preferred is the one with the greatest sum of weights, i.e. for each node that meets all of the scheduling requirements (resource request, requiredDuringScheduling affinity expressions, etc.), compute a sum by iterating through the elements of this field and adding "weight" to the sum if the node matches the corresponding matchExpressions; the node(s) with the highest sum are the most preferred. | ||
requiredDuringSchedulingIgnoredDuringExecution : NodeSelector, default is Undefined, optional | ||
If the affinity requirements specified by this field are not met at scheduling time, the pod will not be scheduled onto the node. If the affinity requirements specified by this field cease to be met at some point during pod execution (e.g. due to an update), the system may or may not try to eventually evict the pod from its node. | ||
""" | ||
|
||
|
||
preferredDuringSchedulingIgnoredDuringExecution?: [PreferredSchedulingTerm] | ||
|
||
requiredDuringSchedulingIgnoredDuringExecution?: NodeSelector | ||
|
||
|
This file contains 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,21 @@ | ||
""" | ||
This is the node_selector module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema NodeSelector: | ||
r""" | ||
A node selector represents the union of the results of one or more label queries over a set of nodes; that is, it represents the OR of the selectors represented by the node selector terms. | ||
|
||
Attributes | ||
---------- | ||
nodeSelectorTerms : [NodeSelectorTerm], default is Undefined, required | ||
Required. A list of node selector terms. The terms are ORed. | ||
""" | ||
|
||
|
||
nodeSelectorTerms: [NodeSelectorTerm] | ||
|
||
|
This file contains 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,29 @@ | ||
""" | ||
This is the node_selector_requirement module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema NodeSelectorRequirement: | ||
r""" | ||
A node selector requirement is a selector that contains values, a key, and an operator that relates the key and values. | ||
|
||
Attributes | ||
---------- | ||
key : str, default is Undefined, required | ||
The label key that the selector applies to. | ||
operator : str, default is Undefined, required | ||
Represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. | ||
values : [str], default is Undefined, optional | ||
An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. If the operator is Gt or Lt, the values array must have a single element, which will be interpreted as an integer. This array is replaced during a strategic merge patch. | ||
""" | ||
|
||
|
||
key: str | ||
|
||
operator: str | ||
|
||
values?: [str] | ||
|
||
|
This file contains 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,25 @@ | ||
""" | ||
This is the node_selector_term module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema NodeSelectorTerm: | ||
r""" | ||
A null or empty node selector term matches no objects. The requirements of them are ANDed. The TopologySelectorTerm type implements a subset of the NodeSelectorTerm. | ||
|
||
Attributes | ||
---------- | ||
matchExpressions : [NodeSelectorRequirement], default is Undefined, optional | ||
A list of node selector requirements by node's labels. | ||
matchFields : [NodeSelectorRequirement], default is Undefined, optional | ||
A list of node selector requirements by node's fields. | ||
""" | ||
|
||
|
||
matchExpressions?: [NodeSelectorRequirement] | ||
|
||
matchFields?: [NodeSelectorRequirement] | ||
|
||
|
This file contains 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,25 @@ | ||
""" | ||
This is the pod_affinity module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema PodAffinity: | ||
r""" | ||
Pod affinity is a group of inter pod affinity scheduling rules. | ||
|
||
Attributes | ||
---------- | ||
preferredDuringSchedulingIgnoredDuringExecution : [WeightedPodAffinityTerm], default is Undefined, optional | ||
The scheduler will prefer to schedule pods to nodes that satisfy the affinity expressions specified by this field, but it may choose a node that violates one or more of the expressions. The node that is most preferred is the one with the greatest sum of weights, i.e. for each node that meets all of the scheduling requirements (resource request, requiredDuringScheduling affinity expressions, etc.), compute a sum by iterating through the elements of this field and adding "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the node(s) with the highest sum are the most preferred. | ||
requiredDuringSchedulingIgnoredDuringExecution : [PodAffinityTerm], default is Undefined, optional | ||
If the affinity requirements specified by this field are not met at scheduling time, the pod will not be scheduled onto the node. If the affinity requirements specified by this field cease to be met at some point during pod execution (e.g. due to a pod label update), the system may or may not try to eventually evict the pod from its node. When there are multiple elements, the lists of nodes corresponding to each podAffinityTerm are intersected, i.e. all terms must be satisfied. | ||
""" | ||
|
||
|
||
preferredDuringSchedulingIgnoredDuringExecution?: [WeightedPodAffinityTerm] | ||
|
||
requiredDuringSchedulingIgnoredDuringExecution?: [PodAffinityTerm] | ||
|
||
|
This file contains 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,42 @@ | ||
""" | ||
This is the pod_affinity_term module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
import k8s.apimachinery.pkg.apis.meta.v1 | ||
|
||
|
||
schema PodAffinityTerm: | ||
r""" | ||
Defines a set of pods (namely those matching the labelSelector relative to the given namespace(s)) that this pod should be co-located (affinity) or not co-located (anti-affinity) with, where co-located is defined as running on a node whose value of the label with key <topologyKey> matches that of any node on which a pod of the set of pods is running | ||
|
||
Attributes | ||
---------- | ||
labelSelector : v1.LabelSelector, default is Undefined, optional | ||
A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods. | ||
matchLabelKeys : [str], default is Undefined, optional | ||
MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default). | ||
mismatchLabelKeys : [str], default is Undefined, optional | ||
MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default). | ||
namespaceSelector : v1.LabelSelector, default is Undefined, optional | ||
A label query over the set of namespaces that the term applies to. The term is applied to the union of the namespaces selected by this field and the ones listed in the namespaces field. null selector and null or empty namespaces list means "this pod's namespace". An empty selector ({}) matches all namespaces. | ||
namespaces : [str], default is Undefined, optional | ||
namespaces specifies a static list of namespace names that the term applies to. The term is applied to the union of the namespaces listed in this field and the ones selected by namespaceSelector. null or empty namespaces list and null namespaceSelector means "this pod's namespace". | ||
topologyKey : str, default is Undefined, required | ||
This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed. | ||
""" | ||
|
||
|
||
labelSelector?: v1.LabelSelector | ||
|
||
matchLabelKeys?: [str] | ||
|
||
mismatchLabelKeys?: [str] | ||
|
||
namespaceSelector?: v1.LabelSelector | ||
|
||
namespaces?: [str] | ||
|
||
topologyKey: str | ||
|
||
|
This file contains 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,25 @@ | ||
""" | ||
This is the pod_anti_affinity module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema PodAntiAffinity: | ||
r""" | ||
Pod anti affinity is a group of inter pod anti affinity scheduling rules. | ||
|
||
Attributes | ||
---------- | ||
preferredDuringSchedulingIgnoredDuringExecution : [WeightedPodAffinityTerm], default is Undefined, optional | ||
The scheduler will prefer to schedule pods to nodes that satisfy the anti-affinity expressions specified by this field, but it may choose a node that violates one or more of the expressions. The node that is most preferred is the one with the greatest sum of weights, i.e. for each node that meets all of the scheduling requirements (resource request, requiredDuringScheduling anti-affinity expressions, etc.), compute a sum by iterating through the elements of this field and adding "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the node(s) with the highest sum are the most preferred. | ||
requiredDuringSchedulingIgnoredDuringExecution : [PodAffinityTerm], default is Undefined, optional | ||
If the anti-affinity requirements specified by this field are not met at scheduling time, the pod will not be scheduled onto the node. If the anti-affinity requirements specified by this field cease to be met at some point during pod execution (e.g. due to a pod label update), the system may or may not try to eventually evict the pod from its node. When there are multiple elements, the lists of nodes corresponding to each podAffinityTerm are intersected, i.e. all terms must be satisfied. | ||
""" | ||
|
||
|
||
preferredDuringSchedulingIgnoredDuringExecution?: [WeightedPodAffinityTerm] | ||
|
||
requiredDuringSchedulingIgnoredDuringExecution?: [PodAffinityTerm] | ||
|
||
|
This file contains 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,25 @@ | ||
""" | ||
This is the preferred_scheduling_term module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema PreferredSchedulingTerm: | ||
r""" | ||
An empty preferred scheduling term matches all objects with implicit weight 0 (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op). | ||
|
||
Attributes | ||
---------- | ||
preference : NodeSelectorTerm, default is Undefined, required | ||
A node selector term, associated with the corresponding weight. | ||
weight : int, default is Undefined, required | ||
Weight associated with matching the corresponding nodeSelectorTerm, in the range 1-100. | ||
""" | ||
|
||
|
||
preference: NodeSelectorTerm | ||
|
||
weight: int | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
models/kube/frontend/affinity/weighted_pod_affinity_term.k
This file contains 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,25 @@ | ||
""" | ||
This is the weighted_pod_affinity_term module in k8s.api.core.v1 package. | ||
This file was generated by the KCL auto-gen tool. DO NOT EDIT. | ||
Editing this file might prove futile when you re-run the KCL auto-gen generate command. | ||
""" | ||
|
||
|
||
schema WeightedPodAffinityTerm: | ||
r""" | ||
The weights of all of the matched WeightedPodAffinityTerm fields are added per-node to find the most preferred node(s) | ||
|
||
Attributes | ||
---------- | ||
podAffinityTerm : PodAffinityTerm, default is Undefined, required | ||
Required. A pod affinity term, associated with the corresponding weight. | ||
weight : int, default is Undefined, required | ||
weight associated with matching the corresponding podAffinityTerm, in the range 1-100. | ||
""" | ||
|
||
|
||
podAffinityTerm: PodAffinityTerm | ||
|
||
weight: int | ||
|
||
|
This file contains 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