Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add spec port #281

Merged
merged 4 commits into from
Sep 19, 2023
Merged
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
6 changes: 6 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ func generateContainers(c NebulaClusterComponent, cm *corev1.ConfigMap) []corev1
if c.ComponentType() == GraphdComponentType && nc.IsIntraZoneReadingEnabled() {
flags += " --assigned_zone=$NODE_ZONE"
}
if !c.IsDefaultThriftPort() {
flags += " --port=" + strconv.Itoa(int(c.GetThriftPort()))
}
if !c.IsDefaultHTTPPort() {
flags += " --ws_http_port=" + strconv.Itoa(int(c.GetHTTPPort()))
}

cmd := []string{"/bin/sh", "-ecx"}
if c.ComponentType() == GraphdComponentType && nc.IsIntraZoneReadingEnabled() {
Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ type NebulaClusterComponent interface {
IsReady() bool
GetUpdateRevision() string
UpdateComponentStatus(status *ComponentStatus)

IsDefaultThriftPort() bool
GetThriftPort() int32
IsDefaultHTTPPort() bool
GetHTTPPort() int32
Comment on lines +210 to +213
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use GetXxxPort? The default value is already defined in CRD.

}

// +k8s:deepcopy-gen=false
Expand Down
26 changes: 18 additions & 8 deletions apis/apps/v1alpha1/nebulacluster_graphd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const (
defaultGraphdPortThrift = 9669
GraphdPortNameHTTP = "http"
defaultGraphdPortHTTP = 19669
GraphdPortNameHTTP2 = "http2"
defaultGraphdPortHTTP2 = 19670
defaultGraphdImage = "vesoft/nebula-graphd"
)

Expand Down Expand Up @@ -141,15 +139,11 @@ func (c *graphdComponent) GenerateContainerPorts() []corev1.ContainerPort {
return []corev1.ContainerPort{
{
Name: GraphdPortNameThrift,
ContainerPort: defaultGraphdPortThrift,
ContainerPort: c.nc.Spec.Graphd.Port,
},
{
Name: GraphdPortNameHTTP,
ContainerPort: defaultGraphdPortHTTP,
},
{
Name: GraphdPortNameHTTP2,
ContainerPort: defaultGraphdPortHTTP2,
ContainerPort: c.nc.Spec.Graphd.HTTPPort,
},
}
}
Expand Down Expand Up @@ -308,3 +302,19 @@ func (c *graphdComponent) GenerateConfigMap() *corev1.ConfigMap {
func (c *graphdComponent) UpdateComponentStatus(status *ComponentStatus) {
c.nc.Status.Graphd = *status
}

func (c *graphdComponent) IsDefaultThriftPort() bool {
return c.nc.Spec.Graphd.Port == defaultGraphdPortThrift
}

func (c *graphdComponent) GetThriftPort() int32 {
return c.nc.Spec.Graphd.Port
}

func (c *graphdComponent) IsDefaultHTTPPort() bool {
return c.nc.Spec.Graphd.HTTPPort == defaultGraphdPortHTTP
}

func (c *graphdComponent) GetHTTPPort() int32 {
return c.nc.Spec.Graphd.HTTPPort
}
26 changes: 18 additions & 8 deletions apis/apps/v1alpha1/nebulacluster_metad.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const (
defaultMetadPortThrift = 9559
MetadPortNameHTTP = "http"
defaultMetadPortHTTP = 19559
MetadPortNameHTTP2 = "http2"
defaultMetadPortHTTP2 = 19560
defaultMetadImage = "vesoft/nebula-metad"
)

Expand Down Expand Up @@ -158,15 +156,11 @@ func (c *metadComponent) GenerateContainerPorts() []corev1.ContainerPort {
return []corev1.ContainerPort{
{
Name: MetadPortNameThrift,
ContainerPort: defaultMetadPortThrift,
ContainerPort: c.nc.Spec.Metad.Port,
},
{
Name: MetadPortNameHTTP,
ContainerPort: defaultMetadPortHTTP,
},
{
Name: MetadPortNameHTTP2,
ContainerPort: defaultMetadPortHTTP2,
ContainerPort: c.nc.Spec.Metad.HTTPPort,
},
}
}
Expand Down Expand Up @@ -386,3 +380,19 @@ func (c *metadComponent) GenerateConfigMap() *corev1.ConfigMap {
func (c *metadComponent) UpdateComponentStatus(status *ComponentStatus) {
c.nc.Status.Metad = *status
}

func (c *metadComponent) IsDefaultThriftPort() bool {
return c.nc.Spec.Metad.Port == defaultMetadPortThrift
}

func (c *metadComponent) GetThriftPort() int32 {
return c.nc.Spec.Metad.Port
}

func (c *metadComponent) IsDefaultHTTPPort() bool {
return c.nc.Spec.Metad.HTTPPort == defaultMetadPortHTTP
}

func (c *metadComponent) GetHTTPPort() int32 {
return c.nc.Spec.Metad.HTTPPort
}
28 changes: 19 additions & 9 deletions apis/apps/v1alpha1/nebulacluster_storaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const (
defaultStoragedPortThrift = 9779
StoragedPortNameHTTP = "http"
defaultStoragedPortHTTP = 19779
StoragedPortNameHTTP2 = "http2"
defaultStoragedPortHTTP2 = 19780
StoragedPortNameAdmin = "admin"
defaultStoragedPortAdmin = 9778
defaultStoragedImage = "vesoft/nebula-storaged"
Expand Down Expand Up @@ -159,19 +157,15 @@ func (c *storagedComponent) GenerateContainerPorts() []corev1.ContainerPort {
return []corev1.ContainerPort{
{
Name: StoragedPortNameThrift,
ContainerPort: defaultStoragedPortThrift,
ContainerPort: c.nc.Spec.Storaged.Port,
},
{
Name: StoragedPortNameHTTP,
ContainerPort: defaultStoragedPortHTTP,
},
{
Name: StoragedPortNameHTTP2,
ContainerPort: defaultStoragedPortHTTP2,
ContainerPort: c.nc.Spec.Storaged.HTTPPort,
},
{
Name: StoragedPortNameAdmin,
ContainerPort: defaultStoragedPortAdmin,
ContainerPort: c.nc.Spec.Storaged.Port - 1,
},
}
}
Expand Down Expand Up @@ -388,3 +382,19 @@ func storageDataVolumeClaims(storageClaims []StorageClaim, componentType string)
}
return pvcs, nil
}

func (c *storagedComponent) IsDefaultThriftPort() bool {
return c.nc.Spec.Storaged.Port == defaultStoragedPortThrift
}

func (c *storagedComponent) GetThriftPort() int32 {
return c.nc.Spec.Storaged.Port
}

func (c *storagedComponent) IsDefaultHTTPPort() bool {
return c.nc.Spec.Storaged.HTTPPort == defaultStoragedPortHTTP
}

func (c *storagedComponent) GetHTTPPort() int32 {
return c.nc.Spec.Storaged.HTTPPort
}
28 changes: 28 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ type ExporterSpec struct {
// IgnoreRegex means the regex to ignore metrics
// +optional
IgnoreRegex string `json:"ignoreRegex,omitempty"`

// +optional
// +kubebuilder:default=9100
HTTPPort int32 `json:"httpPort,omitempty"`
}

type ConsoleSpec struct {
Expand Down Expand Up @@ -358,6 +362,14 @@ type GraphdSpec struct {
// K8S persistent volume claim for Graphd log volume.
// +optional
LogVolumeClaim *StorageClaim `json:"logVolumeClaim,omitempty"`

// +optional
// +kubebuilder:default=9669
Port int32 `json:"port,omitempty"`

// +optional
// +kubebuilder:default=19669
HTTPPort int32 `json:"httpPort,omitempty"`
Comment on lines +367 to +372
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set validation:Maximum and validation:Minimum

}

// MetadSpec defines the desired state of Metad
Expand All @@ -384,6 +396,14 @@ type MetadSpec struct {

// LicenseManagerURL defines a nebula license manager url
LicenseManagerURL *string `json:"licenseManagerURL,omitempty"`

// +optional
// +kubebuilder:default=9559
Port int32 `json:"port,omitempty"`

// +optional
// +kubebuilder:default=19559
HTTPPort int32 `json:"httpPort,omitempty"`
}

// StoragedSpec defines the desired state of Storaged
Expand Down Expand Up @@ -417,6 +437,14 @@ type StoragedSpec struct {
// Note: This feature is in alpha state.
// +optional
ConcurrentTransfer *bool `json:"concurrentTransfer,omitempty"`

// +optional
// +kubebuilder:default=9779
Port int32 `json:"port,omitempty"`

// +optional
// +kubebuilder:default=19779
HTTPPort int32 `json:"httpPort,omitempty"`
}

// ComponentSpec is a common set of k8s resource configs for nebula components.
Expand Down
28 changes: 28 additions & 0 deletions config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ spec:
- name
type: object
type: array
httpPort:
default: 9100
format: int32
type: integer
ignoreRegex:
type: string
image:
Expand Down Expand Up @@ -3590,6 +3594,10 @@ spec:
- name
type: object
type: array
httpPort:
default: 19669
format: int32
type: integer
image:
type: string
initContainers:
Expand Down Expand Up @@ -4319,6 +4327,10 @@ spec:
additionalProperties:
type: string
type: object
port:
default: 9669
format: int32
type: integer
readinessProbe:
properties:
exec:
Expand Down Expand Up @@ -6368,6 +6380,10 @@ spec:
- name
type: object
type: array
httpPort:
default: 19559
format: int32
type: integer
image:
type: string
initContainers:
Expand Down Expand Up @@ -7106,6 +7122,10 @@ spec:
additionalProperties:
type: string
type: object
port:
default: 9559
format: int32
type: integer
readinessProbe:
properties:
exec:
Expand Down Expand Up @@ -9187,6 +9207,10 @@ spec:
- name
type: object
type: array
httpPort:
default: 19779
format: int32
type: integer
image:
type: string
initContainers:
Expand Down Expand Up @@ -9916,6 +9940,10 @@ spec:
additionalProperties:
type: string
type: object
port:
default: 9779
format: int32
type: integer
readinessProbe:
properties:
exec:
Expand Down
10 changes: 4 additions & 6 deletions pkg/controller/component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"github.com/vesoft-inc/nebula-operator/pkg/util/maputil"
)

const defaultMetricsPort = 9100

type nebulaExporter struct {
clientSet kube.ClientSet
}
Expand Down Expand Up @@ -97,8 +95,8 @@ func (e *nebulaExporter) generateService(nc *v1alpha1.NebulaCluster) *corev1.Ser
{
Name: "metrics",
Protocol: corev1.ProtocolTCP,
Port: defaultMetricsPort,
TargetPort: intstr.FromInt(defaultMetricsPort),
Port: nc.Spec.Exporter.HTTPPort,
TargetPort: intstr.FromInt(int(nc.Spec.Exporter.HTTPPort)),
},
},
},
Expand Down Expand Up @@ -137,7 +135,7 @@ func (e *nebulaExporter) generateDeployment(nc *v1alpha1.NebulaCluster) *appsv1.
{
Name: "metrics",
Protocol: corev1.ProtocolTCP,
ContainerPort: defaultMetricsPort,
ContainerPort: nc.Spec.Exporter.HTTPPort,
},
},
VolumeMounts: nc.ExporterComponent().ComponentSpec().VolumeMounts(),
Expand All @@ -149,7 +147,7 @@ func (e *nebulaExporter) generateDeployment(nc *v1alpha1.NebulaCluster) *appsv1.
container.LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromInt(defaultMetricsPort),
Port: intstr.FromInt(int(nc.Spec.Exporter.HTTPPort)),
Path: "/health",
Scheme: corev1.URISchemeHTTP,
},
Expand Down