Skip to content

Commit

Permalink
fix: failed to reconfigure for the stateless component (#5439)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Oct 16, 2023
1 parent b7d0de2 commit 077f4b8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
9 changes: 6 additions & 3 deletions controllers/apps/configuration/config_reconcile_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,19 @@ func (c *configReconcileContext) GetRelatedObjects() error {
ClusterVer().
ClusterComponent().
ClusterDefComponent().
StatefulSet().
RSM().
StatefulSet().
Deployment().
Complete()
}

func (c *configReconcileContext) StatefulSet() *configReconcileContext {
stsFn := func() (err error) {
dComp := c.ClusterDefComObj
if dComp == nil || dComp.WorkloadType == appsv1alpha1.Stateless {
if dComp == nil || dComp.WorkloadType == appsv1alpha1.Stateless || len(c.RSMList) != 0 {
return
}

c.StatefulSets, c.Containers, err = retrieveRelatedComponentsByConfigmap(
c.Client,
c.Context,
Expand Down Expand Up @@ -124,6 +125,7 @@ func (c *configReconcileContext) RSM() *configReconcileContext {
}

// fix uid mismatch bug: convert rsm to sts
// NODE: all components use the StatefulSet
for _, rsm := range c.RSMList {
var stsObject appv1.StatefulSet
if err = c.Client.Get(c.Context, client.ObjectKeyFromObject(components.ConvertRSMToSTS(&rsm)), &stsObject); err != nil {
Expand All @@ -139,9 +141,10 @@ func (c *configReconcileContext) RSM() *configReconcileContext {
func (c *configReconcileContext) Deployment() *configReconcileContext {
deployFn := func() (err error) {
dComp := c.ClusterDefComObj
if dComp == nil || dComp.WorkloadType != appsv1alpha1.Stateless {
if dComp == nil || dComp.WorkloadType != appsv1alpha1.Stateless || len(c.RSMList) != 0 {
return
}

c.Deployments, c.Containers, err = retrieveRelatedComponentsByConfigmap(
c.Client,
c.Context,
Expand Down
8 changes: 1 addition & 7 deletions controllers/apps/configuration/policy_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ func getReplicationSetPods(params reconfigureParams) ([]corev1.Pod, error) {
func GetComponentPods(params reconfigureParams) ([]corev1.Pod, error) {
componentPods := make([]corev1.Pod, 0)
for i := range params.ComponentUnits {
pods, err := common.GetPodListByStatefulSetWithSelector(params.Ctx.Ctx,
params.Client,
&params.ComponentUnits[i],
client.MatchingLabels{
constant.KBAppComponentLabelKey: params.ClusterComponent.Name,
constant.AppInstanceLabelKey: params.Cluster.Name,
})
pods, err := common.GetPodListByStatefulSet(params.Ctx.Ctx, params.Client, &params.ComponentUnits[i])
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions controllers/apps/configuration/reconfigure_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (r *ReconfigureReconciler) sync(reqCtx intctrlutil.RequestCtx, configMap *c
ContainerNames: reconcileContext.Containers,
ComponentUnits: reconcileContext.StatefulSets,
DeploymentUnits: reconcileContext.Deployments,
RSMList: reconcileContext.RSMList,
Component: reconcileContext.ClusterDefComObj,
ClusterComponent: reconcileContext.ClusterComObj,
Restart: forceRestart || !cfgcm.IsSupportReload(configConstraint.Spec.ReloadOptions),
Expand Down
4 changes: 3 additions & 1 deletion controllers/apps/configuration/reconfigure_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1"
"github.com/apecloud/kubeblocks/internal/configuration/core"
cfgproto "github.com/apecloud/kubeblocks/internal/configuration/proto"
"github.com/apecloud/kubeblocks/internal/configuration/util"
Expand Down Expand Up @@ -104,9 +105,10 @@ type reconfigureParams struct {

// List of StatefulSets using this config template.
ComponentUnits []appsv1.StatefulSet

// List of Deployment using this config template.
DeploymentUnits []appsv1.Deployment
// List of ReplicatedStateMachine using this config template.
RSMList []workloads.ReplicatedStateMachine
}

var (
Expand Down
10 changes: 8 additions & 2 deletions controllers/apps/configuration/simple_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ func (s *simplePolicy) Upgrade(params reconfigureParams) (ReturnedStatus, error)
funcs = GetReplicationRollingUpgradeFuncs()
compLists = fromStatefulSetObjects(params.ComponentUnits)
case appsv1alpha1.Stateless:
funcs = GetDeploymentRollingUpgradeFuncs()
compLists = fromDeploymentObjects(params.DeploymentUnits)
// NODE: stateless component uses the StatefulSet object
if len(params.RSMList) != 0 {
funcs = GetStatefulSetRollingUpgradeFuncs()
compLists = fromStatefulSetObjects(params.ComponentUnits)
} else {
funcs = GetDeploymentRollingUpgradeFuncs()
compLists = fromDeploymentObjects(params.DeploymentUnits)
}
}
return restartAndCheckComponent(params, funcs, compLists)
}
Expand Down

0 comments on commit 077f4b8

Please sign in to comment.