Skip to content

Commit

Permalink
chore: component controller don't handle default headless service (#5868
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Y-Rookie authored Nov 20, 2023
1 parent ad90544 commit 8255825
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 130 deletions.
5 changes: 3 additions & 2 deletions apis/apps/v1alpha1/componentdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type ComponentDefinitionSpec struct {
Volumes []ComponentVolume `json:"volumes"`

// Services defines endpoints that can be used to access the component service to manage the component.
// In addition, a reserved headless service will be created by default, with the name pattern {clusterName}-{componentName}-headless.
// Cannot be updated.
// +optional
Services []Service `json:"services,omitempty"`
Expand Down Expand Up @@ -461,8 +462,8 @@ const (

type LifecycleActionHandler struct {
// builtinHandler specifies the builtin action handler name to do the action.
// Different lifecycleActions support different BuiltinActionHandlers. Details can be queried through official documentation in the future.
// use CustomActionHandler to define your own actions if none of them satisfies the requirement.
// the BuiltinHandler within the same ComponentLifecycleActions should be consistent. Details can be queried through official documentation in the future.
// use CustomHandler to define your own actions if none of them satisfies the requirement.
// +optional
BuiltinHandler *BuiltinActionHandlerType `json:"builtinHandler,omitempty"`

Expand Down
114 changes: 58 additions & 56 deletions config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -490,11 +490,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -756,11 +756,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -1022,11 +1022,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -1289,11 +1289,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -1552,11 +1552,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -1815,11 +1815,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -2079,11 +2079,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -2342,11 +2342,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -2605,11 +2605,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -2868,11 +2868,11 @@ spec:
properties:
builtinHandler:
description: builtinHandler specifies the builtin action handler
name to do the action. Different lifecycleActions support
different BuiltinActionHandlers. Details can be queried
through official documentation in the future. use CustomActionHandler
to define your own actions if none of them satisfies the
requirement.
name to do the action. the BuiltinHandler within the same
ComponentLifecycleActions should be consistent. Details
can be queried through official documentation in the future.
use CustomHandler to define your own actions if none of
them satisfies the requirement.
type: string
customHandler:
description: customHandler defines the custom way to do action.
Expand Down Expand Up @@ -11212,7 +11212,9 @@ spec:
type: string
services:
description: Services defines endpoints that can be used to access
the component service to manage the component. Cannot be updated.
the component service to manage the component. In addition, a reserved
headless service will be created by default, with the name pattern
{clusterName}-{componentName}-headless. Cannot be updated.
items:
properties:
componentSelector:
Expand Down
16 changes: 0 additions & 16 deletions controllers/apps/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,6 @@ var _ = Describe("Cluster Controller", func() {
g.Expect(svc.Spec.Selector).Should(HaveKeyWithValue(constant.RoleLabelKey, constant.Leader))
}
})).Should(Succeed())

By("check component headless service created")
compHeadlessSvcKey := types.NamespacedName{
Namespace: clusterKey.Namespace,
Name: constant.GenerateComponentServiceName(clusterObj.Name, compName, "headless"),
}
Eventually(testapps.CheckObj(&testCtx, compHeadlessSvcKey, func(g Gomega, svc *corev1.Service) {
g.Expect(svc.Spec.Selector).Should(HaveKeyWithValue(constant.AppManagedByLabelKey, constant.AppName))
g.Expect(svc.Spec.Selector).Should(HaveKeyWithValue(constant.AppInstanceLabelKey, clusterObj.Name))
g.Expect(svc.Spec.Selector).Should(HaveKeyWithValue(constant.KBAppComponentLabelKey, compName))
g.Expect(svc.Spec.Selector).Should(HaveKey(constant.RoleLabelKey))
if compDefName == consensusCompDefName {
// default role selector for Consensus workload
g.Expect(svc.Spec.Selector).Should(HaveKeyWithValue(constant.RoleLabelKey, constant.Leader))
}
})).Should(Succeed())
}

testClusterCredential := func(compName, compDefName string, createObj func(string, string, func(*testapps.MockClusterFactory))) {
Expand Down
10 changes: 10 additions & 0 deletions controllers/apps/transformer_component_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (t *componentServiceTransformer) Transform(ctx graph.TransformContext, dag
synthesizeComp := transCtx.SynthesizeComponent
graphCli, _ := transCtx.Client.(model.GraphClient)
for _, service := range synthesizeComp.ComponentServices {
// component controller does not handle the default headless service; the default headless service is managed by the RSM.
if t.isDefaultHeadlessSvc(synthesizeComp, &service) {
continue
}
svc, err := t.buildService(transCtx.Component, synthesizeComp, &service)
if err != nil {
return err
Expand Down Expand Up @@ -109,3 +113,9 @@ func (t *componentServiceTransformer) checkRoleSelector(synthesizeComp *componen
}
return nil
}

func (t *componentServiceTransformer) isDefaultHeadlessSvc(synthesizeComp *component.SynthesizedComponent, service *appsv1alpha1.Service) bool {
svcName := constant.GenerateComponentServiceName(synthesizeComp.ClusterName, synthesizeComp.Name, service.ServiceName)
defaultHeadlessSvcName := constant.GenerateDefaultComponentHeadlessServiceName(synthesizeComp.ClusterName, synthesizeComp.Name)
return svcName == defaultHeadlessSvcName
}
Loading

0 comments on commit 8255825

Please sign in to comment.