diff --git a/Makefile b/Makefile index e4b985a8..4c1dd2e4 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,11 @@ generate-manager: ctrlkit-gen goimports-reviser ## Generate codes of controller @mv pkg/manager/risingwave_scale_view_controller_manager.go pkg/manager/risingwave_scale_view_controller_manager_generated.go @$(GOIMPORTS-REVISER) -apply-to-generated-files -format -rm-unused -set-alias -company-prefixes "github.com/risingwavelabs/risingwave-operator" pkg/manager/risingwave_scale_view_controller_manager_generated.go +go-work: ## create a new go.work file for this project. Will fix error 'gopls was not able to find modules in your workspace' + rm -f go.work + go work init + go work use -r . + fmt: ## Run go fmt against code. @go fmt ./... diff --git a/apis/risingwave/v1alpha1/risingwave_types.go b/apis/risingwave/v1alpha1/risingwave_types.go index 31f118b8..a9ab7b1f 100644 --- a/apis/risingwave/v1alpha1/risingwave_types.go +++ b/apis/risingwave/v1alpha1/risingwave_types.go @@ -186,6 +186,9 @@ type RisingWaveComponentsReplicasStatus struct { // Running status of connector. Connector ComponentReplicasStatus `json:"connector"` + + // Running status of standalone component. + Standalone ComponentReplicasStatus `json:"standalone"` } // RisingWaveConditionType is the condition type of RisingWave. diff --git a/apis/risingwave/v1alpha1/zz_generated.deepcopy.go b/apis/risingwave/v1alpha1/zz_generated.deepcopy.go index fa183d91..7c7edb72 100644 --- a/apis/risingwave/v1alpha1/zz_generated.deepcopy.go +++ b/apis/risingwave/v1alpha1/zz_generated.deepcopy.go @@ -256,6 +256,7 @@ func (in *RisingWaveComponentsReplicasStatus) DeepCopyInto(out *RisingWaveCompon in.Compute.DeepCopyInto(&out.Compute) in.Compactor.DeepCopyInto(&out.Compactor) in.Connector.DeepCopyInto(&out.Connector) + in.Standalone.DeepCopyInto(&out.Standalone) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RisingWaveComponentsReplicasStatus. diff --git a/config/crd/bases/risingwave.risingwavelabs.com_risingwaves.yaml b/config/crd/bases/risingwave.risingwavelabs.com_risingwaves.yaml index 2b25d98b..acbc4caa 100644 --- a/config/crd/bases/risingwave.risingwavelabs.com_risingwaves.yaml +++ b/config/crd/bases/risingwave.risingwavelabs.com_risingwaves.yaml @@ -43338,12 +43338,54 @@ spec: - running - target type: object + standalone: + description: Running status of standalone component. + properties: + groups: + description: List of running status of each group. + items: + description: ComponentGroupReplicasStatus are the running + status of Pods in group. + properties: + exists: + description: Existence status of the group. + type: boolean + name: + description: Name of the group. + type: string + running: + description: Running replicas in the group. + format: int32 + type: integer + target: + description: Target replicas of the group. + format: int32 + type: integer + required: + - name + - running + - target + type: object + type: array + running: + description: Total running replicas of the component. + format: int32 + type: integer + target: + description: Total target replicas of the component. + format: int32 + type: integer + required: + - running + - target + type: object required: - compactor - compute - connector - frontend - meta + - standalone type: object conditions: description: Conditions of the RisingWave. diff --git a/config/risingwave-operator-test.yaml b/config/risingwave-operator-test.yaml index 0958a431..0cf479a7 100644 --- a/config/risingwave-operator-test.yaml +++ b/config/risingwave-operator-test.yaml @@ -43355,12 +43355,54 @@ spec: - running - target type: object + standalone: + description: Running status of standalone component. + properties: + groups: + description: List of running status of each group. + items: + description: ComponentGroupReplicasStatus are the running + status of Pods in group. + properties: + exists: + description: Existence status of the group. + type: boolean + name: + description: Name of the group. + type: string + running: + description: Running replicas in the group. + format: int32 + type: integer + target: + description: Target replicas of the group. + format: int32 + type: integer + required: + - name + - running + - target + type: object + type: array + running: + description: Total running replicas of the component. + format: int32 + type: integer + target: + description: Total target replicas of the component. + format: int32 + type: integer + required: + - running + - target + type: object required: - compactor - compute - connector - frontend - meta + - standalone type: object conditions: description: Conditions of the RisingWave. diff --git a/config/risingwave-operator.yaml b/config/risingwave-operator.yaml index a2a465f0..dee75bbd 100644 --- a/config/risingwave-operator.yaml +++ b/config/risingwave-operator.yaml @@ -43355,12 +43355,54 @@ spec: - running - target type: object + standalone: + description: Running status of standalone component. + properties: + groups: + description: List of running status of each group. + items: + description: ComponentGroupReplicasStatus are the running + status of Pods in group. + properties: + exists: + description: Existence status of the group. + type: boolean + name: + description: Name of the group. + type: string + running: + description: Running replicas in the group. + format: int32 + type: integer + target: + description: Target replicas of the group. + format: int32 + type: integer + required: + - name + - running + - target + type: object + type: array + running: + description: Total running replicas of the component. + format: int32 + type: integer + target: + description: Total target replicas of the component. + format: int32 + type: integer + required: + - running + - target + type: object required: - compactor - compute - connector - frontend - meta + - standalone type: object conditions: description: Conditions of the RisingWave. diff --git a/docs/dev/development.md b/docs/dev/development.md index 6d44418b..c6f9bd71 100644 --- a/docs/dev/development.md +++ b/docs/dev/development.md @@ -188,7 +188,7 @@ Modify the [config/local/webhook.yaml](/config/local/webhook.yaml) to match your 1. Replace the `webhooks.*.clientConfig.caBundle` with the base64 encoded CA certs, which can be obtained by running the following command: ```bash -base64 ${TMPDIR}/k8s-webhook-server/serving-certs/tls.crt +base64 -i ${TMPDIR}/k8s-webhook-server/serving-certs/tls.crt ``` 2. Replace the `host.docker.internal` in `webhooks.*.clientConfig.url` with your host IP or hostname used above, like this: diff --git a/docs/general/api.md b/docs/general/api.md index 2b0f0e32..e8b289f0 100644 --- a/docs/general/api.md +++ b/docs/general/api.md @@ -987,6 +987,19 @@ ComponentReplicasStatus

Running status of connector.

+ + +standalone
+ + +ComponentReplicasStatus + + + + +

Running status of standalone component.

+ +

RisingWaveComponentsSpec diff --git a/pkg/controller/proto/common.pb.go b/pkg/controller/proto/common.pb.go index feb9272d..d4387038 100644 --- a/pkg/controller/proto/common.pb.go +++ b/pkg/controller/proto/common.pb.go @@ -1,4 +1,4 @@ -// Copyright 2023 RisingWave Labs +// Copyright 2024 RisingWave Labs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/controller/proto/meta.pb.go b/pkg/controller/proto/meta.pb.go index 7e87ea3d..13a41e1b 100644 --- a/pkg/controller/proto/meta.pb.go +++ b/pkg/controller/proto/meta.pb.go @@ -1,4 +1,4 @@ -// Copyright 2023 RisingWave Labs +// Copyright 2024 RisingWave Labs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/controller/proto/meta_grpc.pb.go b/pkg/controller/proto/meta_grpc.pb.go index ddbf6969..2323818d 100644 --- a/pkg/controller/proto/meta_grpc.pb.go +++ b/pkg/controller/proto/meta_grpc.pb.go @@ -1,4 +1,4 @@ -// Copyright 2023 RisingWave Labs +// Copyright 2024 RisingWave Labs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/manager/risingwave_controller_manager_generated.go b/pkg/manager/risingwave_controller_manager_generated.go index a55b8888..255ae3f4 100644 --- a/pkg/manager/risingwave_controller_manager_generated.go +++ b/pkg/manager/risingwave_controller_manager_generated.go @@ -1678,6 +1678,10 @@ func (m *RisingWaveControllerManager) CollectRunningStatisticsAndSyncStatusForSt return ctrlkit.RequeueIfError(err) } + if standaloneService == nil || standaloneStatefulSet == nil || configConfigMap == nil { + return ctrlkit.RequeueIfError(fmt.Errorf("standaloneService, standaloneStatefulSet, configConfigMap cannot be nil")) + } + // Invoke action. if m.hook != nil { defer func() { diff --git a/pkg/manager/risingwave_controller_manager_impl.go b/pkg/manager/risingwave_controller_manager_impl.go index 0f4cb072..41170818 100644 --- a/pkg/manager/risingwave_controller_manager_impl.go +++ b/pkg/manager/risingwave_controller_manager_impl.go @@ -58,9 +58,39 @@ type risingWaveControllerManagerImpl struct { forceUpdateEnabled bool } +func getStandaloneStatusUtil(rw *risingwavev1alpha1.RisingWave, logger logr.Logger, readyReplicas int32) risingwavev1alpha1.ComponentReplicasStatus { + requiredReplicas := int32(1) + if rw.Spec.Components.Standalone != nil { + requiredReplicas = rw.Spec.Components.Standalone.Replicas + } + + status := risingwavev1alpha1.ComponentReplicasStatus{ + Running: 0, + Target: requiredReplicas, + } + + status.Running = readyReplicas + status.Groups = append(status.Groups, risingwavev1alpha1.ComponentGroupReplicasStatus{ + Target: requiredReplicas, + Running: readyReplicas, + Exists: true, + }) + + return status +} + +func getStandaloneStatus(rw *risingwavev1alpha1.RisingWave, standaloneStatefulSet *appsv1.StatefulSet, logger logr.Logger) risingwavev1alpha1.ComponentReplicasStatus { + return getStandaloneStatusUtil(rw, logger, standaloneStatefulSet.Status.ReadyReplicas) +} + +func getOpenKruiseStandaloneStatus(rw *risingwavev1alpha1.RisingWave, standaloneStatefulSet *kruiseappsv1beta1.StatefulSet, logger logr.Logger) risingwavev1alpha1.ComponentReplicasStatus { + return getStandaloneStatusUtil(rw, logger, standaloneStatefulSet.Status.ReadyReplicas) +} + func buildNodeGroupStatus[T any, TP ptrAsObject[T], G any](groups []G, nameAndReplicas func(*G) (string, int32), workloads []T, groupAndReadyReplicas func(TP) (string, int32)) risingwavev1alpha1.ComponentReplicasStatus { status := risingwavev1alpha1.ComponentReplicasStatus{ - Target: 0, + Running: 0, + Target: 0, } expectedGroups := make(map[string]int32) @@ -156,12 +186,8 @@ func buildStateStoreType(stateStore *risingwavev1alpha1.RisingWaveStateStoreBack } // CollectOpenKruiseRunningStatisticsAndSyncStatus implements RisingWaveControllerManagerImpl. -func (mgr *risingWaveControllerManagerImpl) CollectOpenKruiseRunningStatisticsAndSyncStatus(ctx context.Context, logger logr.Logger, - frontendService *corev1.Service, metaService *corev1.Service, - computeService *corev1.Service, compactorService *corev1.Service, connectorService *corev1.Service, - metaAdvancedStatefulSets []kruiseappsv1beta1.StatefulSet, frontendCloneSets []kruiseappsv1alpha1.CloneSet, - computeStatefulSets []kruiseappsv1beta1.StatefulSet, compactorCloneSets []kruiseappsv1alpha1.CloneSet, connectorCloneSets []kruiseappsv1alpha1.CloneSet, - configConfigMap *corev1.ConfigMap) (reconcile.Result, error) { +func (mgr *risingWaveControllerManagerImpl) CollectOpenKruiseRunningStatisticsAndSyncStatus(ctx context.Context, logger logr.Logger, frontendService *corev1.Service, metaService *corev1.Service, computeService *corev1.Service, compactorService *corev1.Service, connectorService *corev1.Service, metaAdvancedStatefulSets []kruiseappsv1beta1.StatefulSet, frontendCloneSets []kruiseappsv1alpha1.CloneSet, computeStatefulSets []kruiseappsv1beta1.StatefulSet, compactorCloneSets []kruiseappsv1alpha1.CloneSet, connectorCloneSets []kruiseappsv1alpha1.CloneSet, configConfigMap *corev1.ConfigMap) (reconcile.Result, error) { + risingwave := mgr.risingwaveManager.RisingWave() embeddedConnectorEnabled := mgr.risingwaveManager.IsEmbeddedConnectorEnabled() @@ -178,11 +204,12 @@ func (mgr *risingWaveControllerManagerImpl) CollectOpenKruiseRunningStatisticsAn return t.Labels[consts.LabelRisingWaveGroup], t.Status.ReadyReplicas } componentReplicas := risingwavev1alpha1.RisingWaveComponentsReplicasStatus{ - Meta: buildNodeGroupStatus(componentsSpec.Meta.NodeGroups, getNameAndReplicasFromNodeGroup, metaAdvancedStatefulSets, getGroupAndReadyReplicasForStatefulSet), - Frontend: buildNodeGroupStatus(componentsSpec.Frontend.NodeGroups, getNameAndReplicasFromNodeGroup, frontendCloneSets, getGroupAndReadyReplicasForCloneSets), - Compactor: buildNodeGroupStatus(componentsSpec.Compactor.NodeGroups, getNameAndReplicasFromNodeGroup, compactorCloneSets, getGroupAndReadyReplicasForCloneSets), - Connector: buildNodeGroupStatus(componentsSpec.Connector.NodeGroups, getNameAndReplicasFromNodeGroup, connectorCloneSets, getGroupAndReadyReplicasForCloneSets), - Compute: buildNodeGroupStatus(componentsSpec.Compute.NodeGroups, getNameAndReplicasFromNodeGroup, computeStatefulSets, getGroupAndReadyReplicasForStatefulSet), + Meta: buildNodeGroupStatus(componentsSpec.Meta.NodeGroups, getNameAndReplicasFromNodeGroup, metaAdvancedStatefulSets, getGroupAndReadyReplicasForStatefulSet), + Frontend: buildNodeGroupStatus(componentsSpec.Frontend.NodeGroups, getNameAndReplicasFromNodeGroup, frontendCloneSets, getGroupAndReadyReplicasForCloneSets), + Compactor: buildNodeGroupStatus(componentsSpec.Compactor.NodeGroups, getNameAndReplicasFromNodeGroup, compactorCloneSets, getGroupAndReadyReplicasForCloneSets), + Connector: buildNodeGroupStatus(componentsSpec.Connector.NodeGroups, getNameAndReplicasFromNodeGroup, connectorCloneSets, getGroupAndReadyReplicasForCloneSets), + Compute: buildNodeGroupStatus(componentsSpec.Compute.NodeGroups, getNameAndReplicasFromNodeGroup, computeStatefulSets, getGroupAndReadyReplicasForStatefulSet), + Standalone: risingwavev1alpha1.ComponentReplicasStatus{Target: 0, Running: 0}, } mgr.risingwaveManager.UpdateStatus(func(status *risingwavev1alpha1.RisingWaveStatus) { // Report meta storage status. @@ -299,11 +326,12 @@ func (mgr *risingWaveControllerManagerImpl) CollectRunningStatisticsAndSyncStatu return t.Labels[consts.LabelRisingWaveGroup], t.Status.ReadyReplicas } componentReplicas := risingwavev1alpha1.RisingWaveComponentsReplicasStatus{ - Meta: buildNodeGroupStatus(componentsSpec.Meta.NodeGroups, getNameAndReplicasFromNodeGroup, metaStatefulSets, getGroupAndReadyReplicasForStatefulSet), - Frontend: buildNodeGroupStatus(componentsSpec.Frontend.NodeGroups, getNameAndReplicasFromNodeGroup, frontendDeployments, getGroupAndReadyReplicasForDeployment), - Compactor: buildNodeGroupStatus(componentsSpec.Compactor.NodeGroups, getNameAndReplicasFromNodeGroup, compactorDeployments, getGroupAndReadyReplicasForDeployment), - Connector: buildNodeGroupStatus(componentsSpec.Connector.NodeGroups, getNameAndReplicasFromNodeGroup, connectorDeployments, getGroupAndReadyReplicasForDeployment), - Compute: buildNodeGroupStatus(componentsSpec.Compute.NodeGroups, getNameAndReplicasFromNodeGroup, computeStatefulSets, getGroupAndReadyReplicasForStatefulSet), + Meta: buildNodeGroupStatus(componentsSpec.Meta.NodeGroups, getNameAndReplicasFromNodeGroup, metaStatefulSets, getGroupAndReadyReplicasForStatefulSet), + Frontend: buildNodeGroupStatus(componentsSpec.Frontend.NodeGroups, getNameAndReplicasFromNodeGroup, frontendDeployments, getGroupAndReadyReplicasForDeployment), + Compactor: buildNodeGroupStatus(componentsSpec.Compactor.NodeGroups, getNameAndReplicasFromNodeGroup, compactorDeployments, getGroupAndReadyReplicasForDeployment), + Connector: buildNodeGroupStatus(componentsSpec.Connector.NodeGroups, getNameAndReplicasFromNodeGroup, connectorDeployments, getGroupAndReadyReplicasForDeployment), + Compute: buildNodeGroupStatus(componentsSpec.Compute.NodeGroups, getNameAndReplicasFromNodeGroup, computeStatefulSets, getGroupAndReadyReplicasForStatefulSet), + Standalone: risingwavev1alpha1.ComponentReplicasStatus{Target: 0, Running: 0}, } mgr.risingwaveManager.UpdateStatus(func(status *risingwavev1alpha1.RisingWaveStatus) { @@ -1034,7 +1062,9 @@ func (mgr *risingWaveControllerManagerImpl) CollectRunningStatisticsAndSyncStatu status.Version = utils.GetVersionFromImage(mgr.risingwaveManager.RisingWave().Spec.Image) // Report component replicas. - status.ComponentReplicas = risingwavev1alpha1.RisingWaveComponentsReplicasStatus{} + status.ComponentReplicas = risingwavev1alpha1.RisingWaveComponentsReplicasStatus{ + Standalone: getStandaloneStatus(risingwave, standaloneStatefulSet, logger), + } }) recoverConditionAndReasons := []struct { @@ -1078,7 +1108,12 @@ func (mgr *risingWaveControllerManagerImpl) CollectRunningStatisticsAndSyncStatu } // CollectOpenKruiseRunningStatisticsAndSyncStatusForStandalone implements RisingWaveControllerManagerImpl. -func (mgr *risingWaveControllerManagerImpl) CollectOpenKruiseRunningStatisticsAndSyncStatusForStandalone(ctx context.Context, logger logr.Logger, standaloneService *corev1.Service, standaloneAdvancedStatefulSet *kruiseappsv1beta1.StatefulSet, configConfigMap *corev1.ConfigMap) (ctrl.Result, error) { +func (mgr *risingWaveControllerManagerImpl) CollectOpenKruiseRunningStatisticsAndSyncStatusForStandalone( + ctx context.Context, + logger logr.Logger, + standaloneService *corev1.Service, + standaloneAdvancedStatefulSet *kruiseappsv1beta1.StatefulSet, + configConfigMap *corev1.ConfigMap) (ctrl.Result, error) { risingwave := mgr.risingwaveManager.RisingWave() mgr.risingwaveManager.UpdateStatus(func(status *risingwavev1alpha1.RisingWaveStatus) { @@ -1098,7 +1133,9 @@ func (mgr *risingWaveControllerManagerImpl) CollectOpenKruiseRunningStatisticsAn status.Version = utils.GetVersionFromImage(mgr.risingwaveManager.RisingWave().Spec.Image) // Report component replicas. - status.ComponentReplicas = risingwavev1alpha1.RisingWaveComponentsReplicasStatus{} + status.ComponentReplicas = risingwavev1alpha1.RisingWaveComponentsReplicasStatus{ + Standalone: getOpenKruiseStandaloneStatus(risingwave, standaloneAdvancedStatefulSet, logger), + } }) recoverConditionAndReasons := []struct { diff --git a/test/e2e/tests/risingwave/manifests/standalone/standalone.yaml b/test/e2e/tests/risingwave/manifests/standalone/standalone.yaml index 1f31d24a..b1b542b5 100644 --- a/test/e2e/tests/risingwave/manifests/standalone/standalone.yaml +++ b/test/e2e/tests/risingwave/manifests/standalone/standalone.yaml @@ -160,4 +160,13 @@ spec: enableStandaloneMode: true components: standalone: - replicas: 1 \ No newline at end of file + replicas: 1 + template: + spec: + resources: + limits: + cpu: "2" + memory: 8Gi + requests: + cpu: 1500m + memory: 4Gi