Skip to content

Commit

Permalink
feat: support PodManagementPolicy for the instanceSet controller (#7540)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3c6237e)
  • Loading branch information
sophon-zt committed Jun 18, 2024
1 parent 85962c8 commit 900b5c9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 29 deletions.
11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/componentdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
"time"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -444,6 +445,16 @@ type ComponentDefinitionSpec struct {
// +optional
UpdateStrategy *UpdateStrategy `json:"updateStrategy,omitempty"`

// InstanceSet controls the creation of pods during initial scale up, replacement of pods on nodes, and scaling down.
//
// - `OrderedReady`: Creates pods in increasing order (pod-0, then pod-1, etc). The controller waits until each pod
// is ready before continuing. Pods are removed in reverse order when scaling down.
// - `Parallel`: Creates pods in parallel to match the desired scale without waiting. All pods are deleted at once
// when scaling down.
//
// +optional
PodManagementPolicy *appsv1.PodManagementPolicyType `json:"podManagementPolicy,omitempty"`

// Enumerate all possible roles assigned to each replica of the Component, influencing its behavior.
//
// A replica can have zero to multiple roles.
Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 9 additions & 0 deletions config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5207,6 +5207,15 @@ spec:
- scrapePort
type: object
type: object
podManagementPolicy:
description: "InstanceSet controls the creation of pods during initial
scale up, replacement of pods on nodes, and scaling down. \n - `OrderedReady`:
Creates pods in increasing order (pod-0, then pod-1, etc). The controller
waits until each pod is ready before continuing. Pods are removed
in reverse order when scaling down. - `Parallel`: Creates pods in
parallel to match the desired scale without waiting. All pods are
deleted at once when scaling down."
type: string
policyRules:
description: "Defines the namespaced policy rules required by the
Component. \n The `policyRules` field is an array of `rbacv1.PolicyRule`
Expand Down
9 changes: 9 additions & 0 deletions deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5207,6 +5207,15 @@ spec:
- scrapePort
type: object
type: object
podManagementPolicy:
description: "InstanceSet controls the creation of pods during initial
scale up, replacement of pods on nodes, and scaling down. \n - `OrderedReady`:
Creates pods in increasing order (pod-0, then pod-1, etc). The controller
waits until each pod is ready before continuing. Pods are removed
in reverse order when scaling down. - `Parallel`: Creates pods in
parallel to match the desired scale without waiting. All pods are
deleted at once when scaling down."
type: string
policyRules:
description: "Defines the namespaced policy rules required by the
Component. \n The `policyRules` field is an array of `rbacv1.PolicyRule`
Expand Down
40 changes: 40 additions & 0 deletions docs/developer_docs/api-reference/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,26 @@ at least 3 operational for quorum.</li>
</tr>
<tr>
<td>
<code>podManagementPolicy</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#podmanagementpolicytype-v1-apps">
Kubernetes apps/v1.PodManagementPolicyType
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>InstanceSet controls the creation of pods during initial scale up, replacement of pods on nodes, and scaling down.</p>
<ul>
<li><code>OrderedReady</code>: Creates pods in increasing order (pod-0, then pod-1, etc). The controller waits until each pod
is ready before continuing. Pods are removed in reverse order when scaling down.</li>
<li><code>Parallel</code>: Creates pods in parallel to match the desired scale without waiting. All pods are deleted at once
when scaling down.</li>
</ul>
</td>
</tr>
<tr>
<td>
<code>roles</code><br/>
<em>
<a href="#apps.kubeblocks.io/v1alpha1.ReplicaRole">
Expand Down Expand Up @@ -8207,6 +8227,26 @@ at least 3 operational for quorum.</li>
</tr>
<tr>
<td>
<code>podManagementPolicy</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#podmanagementpolicytype-v1-apps">
Kubernetes apps/v1.PodManagementPolicyType
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>InstanceSet controls the creation of pods during initial scale up, replacement of pods on nodes, and scaling down.</p>
<ul>
<li><code>OrderedReady</code>: Creates pods in increasing order (pod-0, then pod-1, etc). The controller waits until each pod
is ready before continuing. Pods are removed in reverse order when scaling down.</li>
<li><code>Parallel</code>: Creates pods in parallel to match the desired scale without waiting. All pods are deleted at once
when scaling down.</li>
</ul>
</td>
</tr>
<tr>
<td>
<code>roles</code><br/>
<em>
<a href="#apps.kubeblocks.io/v1alpha1.ReplicaRole">
Expand Down
59 changes: 30 additions & 29 deletions pkg/controller/component/synthesize_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,35 +148,36 @@ func buildSynthesizedComponent(reqCtx intctrlutil.RequestCtx,
}
compDefObj := compDef.DeepCopy()
synthesizeComp := &SynthesizedComponent{
Namespace: comp.Namespace,
ClusterName: clusterName,
ClusterUID: clusterUID,
Comp2CompDefs: comp2CompDef,
Name: compName,
FullCompName: comp.Name,
CompDefName: compDef.Name,
ServiceVersion: comp.Spec.ServiceVersion,
ClusterGeneration: clusterGeneration(cluster, comp),
PodSpec: &compDef.Spec.Runtime,
HostNetwork: compDefObj.Spec.HostNetwork,
ComponentServices: compDefObj.Spec.Services,
LogConfigs: compDefObj.Spec.LogConfigs,
ConfigTemplates: compDefObj.Spec.Configs,
ScriptTemplates: compDefObj.Spec.Scripts,
Roles: compDefObj.Spec.Roles,
UpdateStrategy: compDefObj.Spec.UpdateStrategy,
MinReadySeconds: compDefObj.Spec.MinReadySeconds,
PolicyRules: compDefObj.Spec.PolicyRules,
LifecycleActions: compDefObj.Spec.LifecycleActions,
SystemAccounts: mergeSystemAccounts(compDefObj.Spec.SystemAccounts, comp.Spec.SystemAccounts),
RoleArbitrator: compDefObj.Spec.RoleArbitrator,
Replicas: comp.Spec.Replicas,
Resources: comp.Spec.Resources,
TLSConfig: comp.Spec.TLSConfig,
ServiceAccountName: comp.Spec.ServiceAccountName,
Instances: comp.Spec.Instances,
OfflineInstances: comp.Spec.OfflineInstances,
DisableExporter: comp.Spec.DisableExporter,
Namespace: comp.Namespace,
ClusterName: clusterName,
ClusterUID: clusterUID,
Comp2CompDefs: comp2CompDef,
Name: compName,
FullCompName: comp.Name,
CompDefName: compDef.Name,
ServiceVersion: comp.Spec.ServiceVersion,
ClusterGeneration: clusterGeneration(cluster, comp),
PodSpec: &compDef.Spec.Runtime,
HostNetwork: compDefObj.Spec.HostNetwork,
ComponentServices: compDefObj.Spec.Services,
LogConfigs: compDefObj.Spec.LogConfigs,
ConfigTemplates: compDefObj.Spec.Configs,
ScriptTemplates: compDefObj.Spec.Scripts,
Roles: compDefObj.Spec.Roles,
UpdateStrategy: compDefObj.Spec.UpdateStrategy,
MinReadySeconds: compDefObj.Spec.MinReadySeconds,
PolicyRules: compDefObj.Spec.PolicyRules,
LifecycleActions: compDefObj.Spec.LifecycleActions,
SystemAccounts: mergeSystemAccounts(compDefObj.Spec.SystemAccounts, comp.Spec.SystemAccounts),
RoleArbitrator: compDefObj.Spec.RoleArbitrator,
Replicas: comp.Spec.Replicas,
Resources: comp.Spec.Resources,
TLSConfig: comp.Spec.TLSConfig,
ServiceAccountName: comp.Spec.ServiceAccountName,
Instances: comp.Spec.Instances,
OfflineInstances: comp.Spec.OfflineInstances,
DisableExporter: comp.Spec.DisableExporter,
PodManagementPolicy: compDef.Spec.PodManagementPolicy,
}

// build backward compatible fields, including workload, services, componentRefEnvs, clusterDefName, clusterCompDefName, and clusterCompVer, etc.
Expand Down

0 comments on commit 900b5c9

Please sign in to comment.