Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions api/operator/v1/vlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,14 @@ func (cr *VLCluster) IsOwnsServiceAccount() bool {

// AsURL implements stub for interface.
// nolint:dupl,lll
func (cr *VLCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string {
func (cr *VLCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) (string, error) {
var defaultPort string
var svcSpec *vmv1beta1.AdditionalServiceSpec
var extraArgs map[string]string
switch kind {
case vmv1beta1.ClusterComponentSelect:
if cr.Spec.VLSelect == nil {
return ""
return "", fmt.Errorf("vlcluster %q has no spec.vlSelect configured", cr.Name)
}
defaultPort = "9471"
if cr.Spec.VLSelect.Port != "" {
Expand All @@ -892,7 +892,7 @@ func (cr *VLCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string
extraArgs = cr.Spec.VLSelect.ExtraArgs
case vmv1beta1.ClusterComponentInsert:
if cr.Spec.VLInsert == nil {
return ""
return "", fmt.Errorf("vlcluster %q has no spec.vlInsert configured", cr.Name)
}
defaultPort = "9481"
if cr.Spec.VLInsert.Port != "" {
Expand All @@ -902,7 +902,7 @@ func (cr *VLCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string
extraArgs = cr.Spec.VLInsert.ExtraArgs
case vmv1beta1.ClusterComponentStorage:
if cr.Spec.VLStorage == nil {
return ""
return "", fmt.Errorf("vlcluster %q has no spec.vlStorage configured", cr.Name)
}
defaultPort = "9491"
if cr.Spec.VLStorage.Port != "" {
Expand All @@ -914,12 +914,16 @@ func (cr *VLCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string
panic("BUG unsupported cluster kind=" + string(kind))
}
svcName, port := vmv1beta1.ResolveServiceURL(cr.PrefixedName(kind), defaultPort, "http", svcSpec, isExtra)
return fmt.Sprintf("%s://%s.%s.svc:%s", vmv1beta1.HTTPProtoFromFlags(extraArgs), svcName, cr.Namespace, port)
return fmt.Sprintf("%s://%s.%s.svc:%s", vmv1beta1.HTTPProtoFromFlags(extraArgs), svcName, cr.Namespace, port), nil
}

// GetRemoteWriteURL returns the insert URL for VLCluster (used by VLDistributed)
func (cr *VLCluster) GetRemoteWriteURL() string {
return cr.AsURL(vmv1beta1.ClusterComponentInsert, false) + "/insert/native"
url, err := cr.AsURL(vmv1beta1.ClusterComponentInsert, false)
if err != nil {
return ""
}
return url + "/insert/native"
}

// +kubebuilder:object:root=true
Expand Down
16 changes: 10 additions & 6 deletions api/operator/v1/vtcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@ func (cr *VTCluster) Validate() error {
}
storageNodes := sets.New[string]()
if cr.Spec.Storage != nil {
storageNodes.Insert(cr.AsURL(vmv1beta1.ClusterComponentStorage, false))
storageURL, err := cr.AsURL(vmv1beta1.ClusterComponentStorage, false)
if err != nil {
return err
}
storageNodes.Insert(storageURL)
vts := cr.Spec.Storage
name := cr.PrefixedName(vmv1beta1.ClusterComponentStorage)
if vts.ServiceSpec != nil && vts.ServiceSpec.Name == name {
Expand Down Expand Up @@ -796,14 +800,14 @@ func (cr *VTCluster) IsOwnsServiceAccount() bool {

// AsURL implements stub for interface.
// nolint:dupl,lll
func (cr *VTCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string {
func (cr *VTCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) (string, error) {
Comment thread
AndrewChubatiuk marked this conversation as resolved.
var defaultPort string
var svcSpec *vmv1beta1.AdditionalServiceSpec
var extraArgs map[string]string
switch kind {
case vmv1beta1.ClusterComponentSelect:
if cr.Spec.Select == nil {
return ""
return "", fmt.Errorf("vtcluster %q has no spec.select configured", cr.Name)
}
defaultPort = "10471"
if cr.Spec.Select.Port != "" {
Expand All @@ -813,7 +817,7 @@ func (cr *VTCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string
extraArgs = cr.Spec.Select.ExtraArgs
case vmv1beta1.ClusterComponentInsert:
if cr.Spec.Insert == nil {
return ""
return "", fmt.Errorf("vtcluster %q has no spec.insert configured", cr.Name)
}
defaultPort = "10481"
if cr.Spec.Insert.Port != "" {
Expand All @@ -823,7 +827,7 @@ func (cr *VTCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string
extraArgs = cr.Spec.Insert.ExtraArgs
case vmv1beta1.ClusterComponentStorage:
if cr.Spec.Storage == nil {
return ""
return "", fmt.Errorf("vtcluster %q has no spec.storage configured", cr.Name)
}
defaultPort = "10491"
if cr.Spec.Storage.Port != "" {
Expand All @@ -835,7 +839,7 @@ func (cr *VTCluster) AsURL(kind vmv1beta1.ClusterComponent, isExtra bool) string
panic("BUG unsupported cluster kind=" + string(kind))
}
svcName, port := vmv1beta1.ResolveServiceURL(cr.PrefixedName(kind), defaultPort, "http", svcSpec, isExtra)
return fmt.Sprintf("%s://%s.%s.svc:%s", vmv1beta1.HTTPProtoFromFlags(extraArgs), svcName, cr.Namespace, port)
return fmt.Sprintf("%s://%s.%s.svc:%s", vmv1beta1.HTTPProtoFromFlags(extraArgs), svcName, cr.Namespace, port), nil
}

// +kubebuilder:object:root=true
Expand Down
6 changes: 3 additions & 3 deletions api/operator/v1alpha1/vmdistributed_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type VMDistributedZoneCluster struct {
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
Spec vmv1beta1.VMClusterSpec `json:"spec"`
Spec vmv1beta1.VMClusterSpecBase `json:"spec"`
Comment thread
AndrewChubatiuk marked this conversation as resolved.
}

// +k8s:openapi-gen=true
Expand Down Expand Up @@ -517,7 +517,7 @@ func (cr *VMDistributed) Validate() error {
hasCommonVMInsert := cr.Spec.ZoneCommon.VMCluster.Spec.VMInsert != nil
hasCommonVMSelect := cr.Spec.ZoneCommon.VMCluster.Spec.VMSelect != nil
hasCommonVMSingle := cr.Spec.ZoneCommon.VMSingle != nil && (cr.Spec.ZoneCommon.VMSingle.Name != "" || cr.Spec.ZoneCommon.VMSingle.Spec != nil)
hasCommonVMCluster := cr.Spec.ZoneCommon.VMCluster.Name != "" || !equality.Semantic.DeepEqual(cr.Spec.ZoneCommon.VMCluster.Spec, vmv1beta1.VMClusterSpec{})
hasCommonVMCluster := cr.Spec.ZoneCommon.VMCluster.Name != "" || !equality.Semantic.DeepEqual(cr.Spec.ZoneCommon.VMCluster.Spec, vmv1beta1.VMClusterSpecBase{})
if isVMSingle && hasCommonVMCluster {
return fmt.Errorf("backendType=VMSingle is incompatible with zoneCommon.vmcluster configuration")
}
Expand All @@ -534,7 +534,7 @@ func (cr *VMDistributed) Validate() error {
}
zones.Insert(zone.Name)
if isVMSingle {
if zone.VMCluster.Name != "" || !equality.Semantic.DeepEqual(zone.VMCluster.Spec, vmv1beta1.VMClusterSpec{}) {
if zone.VMCluster.Name != "" || !equality.Semantic.DeepEqual(zone.VMCluster.Spec, vmv1beta1.VMClusterSpecBase{}) {
return fmt.Errorf("spec.zones[%d]: backendType=VMSingle is incompatible with vmcluster configuration", i)
}
singleName := zone.VMSingleName(cr)
Expand Down
25 changes: 23 additions & 2 deletions api/operator/v1alpha1/vmdistributed_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestValidateVMDistributed(t *testing.T) {
{
Name: "zone-1",
VMSingle: &VMDistributedZoneSingle{Name: "single-a"},
VMCluster: VMDistributedZoneCluster{Spec: vmv1beta1.VMClusterSpec{
VMCluster: VMDistributedZoneCluster{Spec: vmv1beta1.VMClusterSpecBase{
VMInsert: &vmv1beta1.VMInsert{},
}},
},
Expand All @@ -143,7 +143,7 @@ func TestValidateVMDistributed(t *testing.T) {
VMSingle: &VMDistributedZoneSingle{
Spec: &vmv1beta1.VMSingleSpec{},
},
VMCluster: VMDistributedZoneCluster{Spec: vmv1beta1.VMClusterSpec{
VMCluster: VMDistributedZoneCluster{Spec: vmv1beta1.VMClusterSpecBase{
VMInsert: &vmv1beta1.VMInsert{},
}},
},
Expand Down Expand Up @@ -177,6 +177,27 @@ func TestValidateVMDistributed(t *testing.T) {
},
isErr: true,
})

// backendType=VMCluster with a valid shared vminsert/vmselect - no error
f(opts{
cr: VMDistributed{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: VMDistributedSpec{
ZoneCommon: VMDistributedZoneCommon{
VMCluster: VMDistributedZoneCluster{Spec: vmv1beta1.VMClusterSpecBase{
VMInsert: &vmv1beta1.VMInsert{},
VMSelect: &vmv1beta1.VMSelect{},
}},
},
Zones: []VMDistributedZone{
{Name: "zone-1"},
},
},
},
isErr: false,
})
}

func TestEnsureNoVMOwners(t *testing.T) {
Expand Down
Loading