Skip to content

Commit

Permalink
feat: support adversting with IP addresses, useful to avoid DNS probl…
Browse files Browse the repository at this point in the history
…ems (#682)

Signed-off-by: arkbriar <arkbriar@gmail.com>
  • Loading branch information
arkbriar authored Jul 17, 2024
1 parent b255d45 commit ac47edd
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ build-local-certs:
-out ${TMPDIR}/k8s-webhook-server/serving-certs/tls.crt -subj "/CN=localhost" \
-extensions san -config <(echo '[req]'; echo 'distinguished_name=req'; echo '[san]'; echo 'subjectAltName=DNS:host.docker.internal')
K8S_LOCAL_CONTEXT ?= docker-desktop
use-local-context:
kubectl config use docker-desktop
kubectl config use $(K8S_LOCAL_CONTEXT)
install-local: use-local-context kustomize manifests
$(KUSTOMIZE) build config/local | kubectl apply --server-side --force-conflicts -f - >/dev/null
Expand Down
4 changes: 4 additions & 0 deletions apis/risingwave/v1alpha1/risingwave_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ type RisingWaveSpec struct {
// +kubebuilder:default=false
EnableEmbeddedServingMode *bool `json:"enableEmbeddedServingMode,omitempty"`

// Flag to control whether to enable advertising with IP. If enabled, the meta and compute nodes will be advertised
// with their IP addresses. This is useful when one wants to avoid the DNS resolution overhead and latency.
EnableAdvertisingWithIP *bool `json:"enableAdvertisingWithIP,omitempty"`

// Image for RisingWave component.
Image string `json:"image"`

Expand Down
5 changes: 5 additions & 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.

Original file line number Diff line number Diff line change
Expand Up @@ -30348,6 +30348,11 @@ spec:
type: boolean
type: object
type: object
enableAdvertisingWithIP:
description: |-
Flag to control whether to enable advertising with IP. If enabled, the meta and compute nodes will be advertised
with their IP addresses. This is useful when one wants to avoid the DNS resolution overhead and latency.
type: boolean
enableDefaultServiceMonitor:
description: |-
Flag to indicate if a default ServiceMonitor (from Prometheus operator) should be created by the controller.
Expand Down
5 changes: 5 additions & 0 deletions config/risingwave-operator-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30365,6 +30365,11 @@ spec:
type: boolean
type: object
type: object
enableAdvertisingWithIP:
description: |-
Flag to control whether to enable advertising with IP. If enabled, the meta and compute nodes will be advertised
with their IP addresses. This is useful when one wants to avoid the DNS resolution overhead and latency.
type: boolean
enableDefaultServiceMonitor:
description: |-
Flag to indicate if a default ServiceMonitor (from Prometheus operator) should be created by the controller.
Expand Down
5 changes: 5 additions & 0 deletions config/risingwave-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30365,6 +30365,11 @@ spec:
type: boolean
type: object
type: object
enableAdvertisingWithIP:
description: |-
Flag to control whether to enable advertising with IP. If enabled, the meta and compute nodes will be advertised
with their IP addresses. This is useful when one wants to avoid the DNS resolution overhead and latency.
type: boolean
enableDefaultServiceMonitor:
description: |-
Flag to indicate if a default ServiceMonitor (from Prometheus operator) should be created by the controller.
Expand Down
24 changes: 24 additions & 0 deletions docs/general/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,18 @@ with embedded serving node enabled, and the compute nodes will serve streaming w
</tr>
<tr>
<td>
<code>enableAdvertisingWithIP</code><br/>
<em>
bool
</em>
</td>
<td>
<p>Flag to control whether to enable advertising with IP. If enabled, the meta and compute nodes will be advertised
with their IP addresses. This is useful when one wants to avoid the DNS resolution overhead and latency.</p>
</td>
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
Expand Down Expand Up @@ -4537,6 +4549,18 @@ with embedded serving node enabled, and the compute nodes will serve streaming w
</tr>
<tr>
<td>
<code>enableAdvertisingWithIP</code><br/>
<em>
bool
</em>
</td>
<td>
<p>Flag to control whether to enable advertising with IP. If enabled, the meta and compute nodes will be advertised
with their IP addresses. This is useful when one wants to avoid the DNS resolution overhead and latency.</p>
</td>
</tr>
<tr>
<td>
<code>image</code><br/>
<em>
string
Expand Down
18 changes: 16 additions & 2 deletions pkg/factory/risingwave_object_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ func (f *RisingWaveObjectFactory) coreEnvsForMeta() []corev1.EnvVar {
}

func (f *RisingWaveObjectFactory) envsForMetaArgs() []corev1.EnvVar {
var advertiseAddr string
if ptr.Deref(f.risingwave.Spec.EnableAdvertisingWithIP, false) {
advertiseAddr = fmt.Sprintf("$(POD_IP):%d", consts.MetaServicePort)
} else {
advertiseAddr = fmt.Sprintf("$(POD_NAME).%s:%d", f.componentAddr(consts.ComponentMeta, ""), consts.MetaServicePort)
}

envVars := []corev1.EnvVar{
// Env var for local risectl access.
{
Expand All @@ -549,7 +556,7 @@ func (f *RisingWaveObjectFactory) envsForMetaArgs() []corev1.EnvVar {
},
{
Name: envs.RWAdvertiseAddr,
Value: fmt.Sprintf("$(POD_NAME).%s:%d", f.componentAddr(consts.ComponentMeta, ""), consts.MetaServicePort),
Value: advertiseAddr,
},
{
Name: envs.RWPrometheusHost,
Expand Down Expand Up @@ -645,6 +652,13 @@ func (f *RisingWaveObjectFactory) envsForResourceLimits(cpuLimit int64, memLimit
}

func (f *RisingWaveObjectFactory) envsForComputeArgs(cpuLimit int64, memLimit int64) []corev1.EnvVar {
var advertiseAddr string
if ptr.Deref(f.risingwave.Spec.EnableAdvertisingWithIP, false) {
advertiseAddr = fmt.Sprintf("$(POD_IP):%d", consts.ComputeServicePort)
} else {
advertiseAddr = fmt.Sprintf("$(POD_NAME).%s:%d", f.componentAddr(consts.ComponentCompute, ""), consts.ComputeServicePort)
}

envVars := []corev1.EnvVar{
{
Name: envs.RWConfigPath,
Expand All @@ -656,7 +670,7 @@ func (f *RisingWaveObjectFactory) envsForComputeArgs(cpuLimit int64, memLimit in
},
{
Name: envs.RWAdvertiseAddr,
Value: fmt.Sprintf("$(POD_NAME).%s:%d", f.componentAddr(consts.ComponentCompute, ""), consts.ComputeServicePort),
Value: advertiseAddr,
},
{
Name: envs.RWMetaAddr,
Expand Down
5 changes: 5 additions & 0 deletions pkg/object/risingwave_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ func (r *RisingWaveReader) IsStandaloneModeEnabled() bool {
return ptr.Deref(r.risingwave.Spec.EnableStandaloneMode, false)
}

// IsAdvertisingWithIP returns true when the advertising with IP is enabled.
func (r *RisingWaveReader) IsAdvertisingWithIP() bool {
return ptr.Deref(r.risingwave.Spec.EnableAdvertisingWithIP, false)
}

// KeepLock resets the current scale views record in the status with the given array.
func (mgr *RisingWaveManager) KeepLock(aliveScaleView []risingwavev1alpha1.RisingWaveScaleViewLock) {
mgr.mu.Lock()
Expand Down

0 comments on commit ac47edd

Please sign in to comment.