Skip to content

Commit

Permalink
feat: add missing standalone status field (#572)
Browse files Browse the repository at this point in the history
* found root cause

* go-work target Makefile

* first draft

* call getStandaloneStatus

* working version

* add util func

* add license

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add license

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add license

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* cleanup

* cleanup

* feedback

* fix e2e tests

* remove statefulset name

* nil ptr deref

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
CAJan93 and github-actions[bot] authored Jan 5, 2024
1 parent 606c3fd commit e08f00f
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 25 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
3 changes: 3 additions & 0 deletions apis/risingwave/v1alpha1/risingwave_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions apis/risingwave/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions config/crd/bases/risingwave.risingwavelabs.com_risingwaves.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions config/risingwave-operator-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions config/risingwave-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions docs/general/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,19 @@ ComponentReplicasStatus
<p>Running status of connector.</p>
</td>
</tr>
<tr>
<td>
<code>standalone</code><br/>
<em>
<a href="#risingwave.risingwavelabs.com/v1alpha1.ComponentReplicasStatus">
ComponentReplicasStatus
</a>
</em>
</td>
<td>
<p>Running status of standalone component.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="risingwave.risingwavelabs.com/v1alpha1.RisingWaveComponentsSpec">RisingWaveComponentsSpec
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/proto/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/proto/meta.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/controller/proto/meta_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/manager/risingwave_controller_manager_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 57 additions & 20 deletions pkg/manager/risingwave_controller_manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/tests/risingwave/manifests/standalone/standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,13 @@ spec:
enableStandaloneMode: true
components:
standalone:
replicas: 1
replicas: 1
template:
spec:
resources:
limits:
cpu: "2"
memory: 8Gi
requests:
cpu: 1500m
memory: 4Gi

0 comments on commit e08f00f

Please sign in to comment.