Skip to content

Commit

Permalink
fix: etcd role probe (apecloud#6751)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun authored Mar 5, 2024
1 parent 79fd7f5 commit 20d29fa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/component/component_definition_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,13 @@ func (c *compDefLifecycleActionsConvertor) convertBuiltinActionHandler(clusterCo
}

func (c *compDefLifecycleActionsConvertor) convertRoleProbe(clusterCompDef *appsv1alpha1.ClusterComponentDefinition) *appsv1alpha1.RoleProbe {
builtinHandler := c.convertBuiltinActionHandler(clusterCompDef)
// if RSMSpec has role probe CustomHandler, use it first.
if clusterCompDef.RSMSpec != nil && clusterCompDef.RSMSpec.RoleProbe != nil && len(clusterCompDef.RSMSpec.RoleProbe.CustomHandler) > 0 {
// TODO(xingran): RSMSpec.RoleProbe.CustomHandler support multiple images and commands, but ComponentDefinition.LifeCycleAction.RoleProbe only support one image and command now.
return &appsv1alpha1.RoleProbe{
LifecycleActionHandler: appsv1alpha1.LifecycleActionHandler{
BuiltinHandler: nil,
BuiltinHandler: &builtinHandler,
CustomHandler: &appsv1alpha1.Action{
Image: clusterCompDef.RSMSpec.RoleProbe.CustomHandler[0].Image,
Exec: &appsv1alpha1.ExecAction{
Expand All @@ -636,7 +637,6 @@ func (c *compDefLifecycleActionsConvertor) convertRoleProbe(clusterCompDef *apps
PeriodSeconds: clusterCompDefRoleProbe.PeriodSeconds,
}

builtinHandler := c.convertBuiltinActionHandler(clusterCompDef)
roleProbe.BuiltinHandler = &builtinHandler
if clusterCompDefRoleProbe.Commands == nil || len(clusterCompDefRoleProbe.Commands.Queries) == 0 {
roleProbe.CustomHandler = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ var _ = Describe("Component Definition Convertor", func() {

actions := res.(*appsv1alpha1.ComponentLifecycleActions)
Expect(actions.RoleProbe).ShouldNot(BeNil())
Expect(actions.RoleProbe.BuiltinHandler).Should(BeNil())
Expect(*actions.RoleProbe.BuiltinHandler).Should(BeEquivalentTo(appsv1alpha1.WeSQLBuiltinActionHandler))
Expect(actions.RoleProbe.CustomHandler).ShouldNot(BeNil())
Expect(actions.RoleProbe.CustomHandler.Image).Should(BeEquivalentTo("mock-rsm-role-probe-image"))
Expect(actions.RoleProbe.CustomHandler.Exec.Command).Should(BeEquivalentTo(mockCommand))
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/component/lorry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func buildLorryContainers(reqCtx intctrlutil.RequestCtx, synthesizeComp *Synthes
}
}

container := buildBasicContainer(synthesizeComp, int(lorryHTTPPort))
container := buildBasicContainer(int(lorryHTTPPort))
// inject role probe container
var compRoleProbe *appsv1alpha1.RoleProbe
if synthesizeComp.LifecycleActions != nil {
Expand All @@ -94,7 +94,7 @@ func buildLorryContainers(reqCtx intctrlutil.RequestCtx, synthesizeComp *Synthes
// inject volume protection probe container
if volumeProtectionEnabled(synthesizeComp) {
c := container.DeepCopy()
buildVolumeProtectionProbeContainer(synthesizeComp.CharacterType, c, int(lorryHTTPPort))
buildVolumeProtectionProbeContainer(c, int(lorryHTTPPort))
lorryContainers = append(lorryContainers, *c)
}

Expand All @@ -119,7 +119,7 @@ func adaptLorryIfCustomHandlerDefined(synthesizeComp *SynthesizedComponent, lorr
if len(actionCommands) == 0 {
return
}
initContainer := buildLorryInitContainer(synthesizeComp)
initContainer := buildLorryInitContainer()
synthesizeComp.PodSpec.InitContainers = append(synthesizeComp.PodSpec.InitContainers, *initContainer)
execContainer := getExecContainer(synthesizeComp.PodSpec.Containers, containerName)
if execImage == "" {
Expand Down Expand Up @@ -160,7 +160,7 @@ func adaptLorryIfCustomHandlerDefined(synthesizeComp *SynthesizedComponent, lorr
}
}

func buildBasicContainer(synthesizeComp *SynthesizedComponent, lorryHTTPPort int) *corev1.Container {
func buildBasicContainer(lorryHTTPPort int) *corev1.Container {
return builder.NewContainerBuilder("string").
SetImage("infracreate-registry.cn-zhangjiakou.cr.aliyuncs.com/google_containers/pause:3.6").
SetImagePullPolicy(corev1.PullIfNotPresent).
Expand Down Expand Up @@ -198,7 +198,7 @@ func buildLorryServiceContainer(synthesizeComp *SynthesizedComponent, container
buildLorryEnvs(container, synthesizeComp, clusterCompSpec)
}

func buildLorryInitContainer(component *SynthesizedComponent) *corev1.Container {
func buildLorryInitContainer() *corev1.Container {
container := &corev1.Container{}
container.Image = viper.GetString(constant.KBToolsImage)
container.Name = constant.LorryInitContainerName
Expand Down Expand Up @@ -283,7 +283,7 @@ func volumeProtectionEnabled(component *SynthesizedComponent) bool {
return component.VolumeProtection != nil
}

func buildVolumeProtectionProbeContainer(characterType string, c *corev1.Container, probeSvcHTTPPort int) {
func buildVolumeProtectionProbeContainer(c *corev1.Container, probeSvcHTTPPort int) {
c.Name = constant.VolumeProtectionProbeContainerName
probe := &corev1.Probe{}
httpGet := &corev1.HTTPGetAction{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/lorry_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var _ = Describe("Lorry Utils", func() {
Containers: []corev1.Container{},
}

container = buildBasicContainer(component, lorryHTTPPort)
container = buildBasicContainer(lorryHTTPPort)
})

It("build role probe containers", func() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/lorry/engines/mysql/get_replica_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (mgr *Manager) GetReplicaRole(ctx context.Context, cluster *dcs.Cluster) (s
}

func (mgr *Manager) GetReplicaRoleFromDB(ctx context.Context) (string, error) {
slaveRunning, err := mgr.isSlaveRunning(ctx)
slaveRunning, err := mgr.isSlaveRunning()
if err != nil {
return "", err
}
if slaveRunning {
return models.SECONDARY, nil
}

hasSlave, err := mgr.hasSlaveHosts(ctx)
hasSlave, err := mgr.hasSlaveHosts()
if err != nil {
return "", err
}
Expand All @@ -75,7 +75,7 @@ func (mgr *Manager) GetReplicaRoleFromDB(ctx context.Context) (string, error) {
return models.PRIMARY, nil
}

func (mgr *Manager) isSlaveRunning(ctx context.Context) (bool, error) {
func (mgr *Manager) isSlaveRunning() (bool, error) {
var rowMap = mgr.slaveStatus

if len(rowMap) == 0 {
Expand All @@ -89,7 +89,7 @@ func (mgr *Manager) isSlaveRunning(ctx context.Context) (bool, error) {
return false, nil
}

func (mgr *Manager) hasSlaveHosts(ctx context.Context) (bool, error) {
func (mgr *Manager) hasSlaveHosts() (bool, error) {
sql := "show slave hosts"
var rowMap RowMap

Expand Down

0 comments on commit 20d29fa

Please sign in to comment.