diff --git a/apis/apps/v1alpha1/componentdefinition_types.go b/apis/apps/v1alpha1/componentdefinition_types.go index b957e9f17d4..254e1eafd3d 100644 --- a/apis/apps/v1alpha1/componentdefinition_types.go +++ b/apis/apps/v1alpha1/componentdefinition_types.go @@ -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"` @@ -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"` diff --git a/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml b/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml index 7ac40a82cee..68dcd608ae9 100644 --- a/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml +++ b/config/crd/bases/apps.kubeblocks.io_componentdefinitions.yaml @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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: diff --git a/controllers/apps/cluster_controller_test.go b/controllers/apps/cluster_controller_test.go index 0206d4c49d0..7492695d38d 100644 --- a/controllers/apps/cluster_controller_test.go +++ b/controllers/apps/cluster_controller_test.go @@ -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))) { diff --git a/controllers/apps/transformer_component_service.go b/controllers/apps/transformer_component_service.go index 0781736cd3f..d9a91b7f0c8 100644 --- a/controllers/apps/transformer_component_service.go +++ b/controllers/apps/transformer_component_service.go @@ -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 @@ -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 +} diff --git a/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml b/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml index 7ac40a82cee..68dcd608ae9 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_componentdefinitions.yaml @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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: