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

support exporter and log rotate #179

Merged
merged 1 commit into from
Feb 22, 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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ LDFLAGS = $(if $(DEBUGGER),,-s -w) $(shell ./hack/version.sh)

DOCKER_REGISTRY ?= docker.io
DOCKER_REPO ?= ${DOCKER_REGISTRY}/vesoft
IMAGE_TAG ?= v1.4.0
IMAGE_TAG ?= v1.4.1

CHARTS_VERSION ?= 1.4.0
CHARTS_VERSION ?= 1.4.1

export GO111MODULE := on
GOOS := $(if $(GOOS),$(GOOS),linux)
Expand Down Expand Up @@ -94,8 +94,8 @@ build: generate check ## Build binary.

helm-charts:
cp config/crd/bases/*.yaml charts/nebula-operator/crds/
helm package charts/nebula-operator --version $(CHARTS_VERSION)
helm package charts/nebula-cluster --version $(CHARTS_VERSION)
helm package charts/nebula-operator --version $(CHARTS_VERSION) --app-version $(CHARTS_VERSION)
helm package charts/nebula-cluster --version $(CHARTS_VERSION) --app-version $(CHARTS_VERSION)
mv nebula-operator-*.tgz nebula-cluster-*.tgz charts/
helm repo index charts/ --url https://github.com/vesoft-inc/nebula-operator/releases/download/v$(CHARTS_VERSION)

Expand Down
66 changes: 66 additions & 0 deletions apis/apps/v1alpha1/exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"

"github.com/vesoft-inc/nebula-operator/pkg/label"
)

func (nc *NebulaCluster) GetExporterImage() string {
return getImage(nc.Spec.Exporter.Image, nc.Spec.Exporter.Version, defaultExporterImage)
}

func (nc *NebulaCluster) GetExporterReplicas() *int32 {
return nc.Spec.Exporter.Replicas
}

func (nc *NebulaCluster) GetExporterResources() *corev1.ResourceRequirements {
return getResources(nc.Spec.Exporter.Resources)
}

func (nc *NebulaCluster) GetExporterEnvVars() []corev1.EnvVar {
return nc.Spec.Exporter.PodSpec.EnvVars
}

func (nc *NebulaCluster) GetExporterPodAnnotations() map[string]string {
return nc.Spec.Exporter.PodSpec.Annotations
}

func (nc *NebulaCluster) GetExporterLabels() map[string]string {
selector := label.New().Cluster(nc.GetName()).Exporter()
labels := selector.Copy().Labels()
podLabels := nc.Spec.Exporter.PodSpec.Labels

return mergeStringMaps(true, labels, podLabels)
}

func (nc *NebulaCluster) GetExporterNodeSelector() map[string]string {
selector := map[string]string{}
for k, v := range nc.Spec.NodeSelector {
selector[k] = v
}
for k, v := range nc.Spec.Exporter.PodSpec.NodeSelector {
selector[k] = v
}
return selector
}

func (nc *NebulaCluster) GetExporterAffinity() *corev1.Affinity {
affinity := nc.Spec.Graphd.PodSpec.Affinity
if affinity == nil {
affinity = nc.Spec.Affinity
}
return affinity
}

func (nc *NebulaCluster) GetExporterTolerations() []corev1.Toleration {
tolerations := nc.Spec.Exporter.PodSpec.Tolerations
if len(tolerations) == 0 {
return nc.Spec.Tolerations
}
return tolerations
}

func (nc *NebulaCluster) GetExporterLivenessProbe() *corev1.Probe {
return nc.Spec.Exporter.PodSpec.LivenessProbe
}
4 changes: 4 additions & 0 deletions apis/apps/v1alpha1/nebulacluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ func (nc *NebulaCluster) IsBREnabled() bool {
}
return *enabled
}

func (nc *NebulaCluster) IsLogRotateEnabled() bool {
return nc.Spec.LogRotate != nil
}
72 changes: 53 additions & 19 deletions apis/apps/v1alpha1/nebulacluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"

kruisepub "github.com/openkruise/kruise-api/apps/pub"
Expand All @@ -37,11 +38,12 @@ import (
)

const (
AgentSidecarContainerName = "br-agent"
AgentInitContainerName = "br-init-agent"
AgentSidecarContainerName = "ng-agent"
AgentInitContainerName = "ng-init-agent"
DefaultAgentPortGRPC = 8888
agentPortNameGRPC = "grpc"
defaultAgentImage = "vesoft/nebula-agent:latest"
defaultAgentImage = "megabyte875/nebula-agent:latest"
defaultExporterImage = "vesoft/nebula-stats-exporter"
)

func getComponentName(clusterName string, typ ComponentType) string {
Expand Down Expand Up @@ -205,33 +207,65 @@ func generateAgentContainer(c NebulaClusterComponentter, init bool) corev1.Conta
fmt.Sprintf(" --agent=$(hostname).%s:%d", c.GetServiceFQDN(), DefaultAgentPortGRPC)+
" --ratelimit=1073741824 --debug")
} else {
agentCmd = append(agentCmd, "sleep 30; exec /usr/local/bin/agent"+
fmt.Sprintf(" --agent=$(hostname).%s:%d", c.GetServiceFQDN(), DefaultAgentPortGRPC)+
" --meta="+metadAddr+
" --ratelimit=1073741824 --debug")
if c.GetNebulaCluster().IsLogRotateEnabled() && c.GetNebulaCluster().IsBREnabled() {
agentCmd = append(agentCmd, "sh /logrotate.sh; /etc/init.d/cron start;"+
" sleep 30; exec /usr/local/bin/agent"+
fmt.Sprintf(" --agent=$(hostname).%s:%d", c.GetServiceFQDN(), DefaultAgentPortGRPC)+
" --meta="+metadAddr+
" --ratelimit=1073741824 --debug")
} else if c.GetNebulaCluster().IsLogRotateEnabled() {
agentCmd = append(agentCmd, "sh /logrotate.sh; exec cron -f")
} else if c.GetNebulaCluster().IsBREnabled() {
agentCmd = append(agentCmd, "sleep 30; exec /usr/local/bin/agent"+
fmt.Sprintf(" --agent=$(hostname).%s:%d", c.GetServiceFQDN(), DefaultAgentPortGRPC)+
" --meta="+metadAddr+
" --ratelimit=1073741824 --debug")
}
}

container := corev1.Container{
Name: AgentSidecarContainerName,
Image: defaultAgentImage,
ImagePullPolicy: corev1.PullAlways,
Command: agentCmd,
Ports: []corev1.ContainerPort{
Name: AgentSidecarContainerName,
Image: defaultAgentImage,
Command: agentCmd,
}

if c.GetNebulaCluster().IsBREnabled() {
if c.Type() != GraphdComponentType {
container.VolumeMounts = []corev1.VolumeMount{
{
Name: dataVolume(componentType),
MountPath: "/usr/local/nebula/data",
SubPath: "data",
},
}
}

container.Ports = []corev1.ContainerPort{
{
Name: agentPortNameGRPC,
ContainerPort: int32(DefaultAgentPortGRPC),
},
},
}
}

if c.Type() != GraphdComponentType {
container.VolumeMounts = []corev1.VolumeMount{
if c.GetNebulaCluster().IsLogRotateEnabled() {
logRotate := c.GetNebulaCluster().Spec.LogRotate
container.Env = []corev1.EnvVar{
{
Name: "LOGROTATE_ROTATE",
Value: strconv.Itoa(int(logRotate.Rotate)),
},
{
Name: dataVolume(componentType),
MountPath: "/usr/local/nebula/data",
SubPath: "data",
Name: "LOGROTATE_SIZE",
Value: logRotate.Size,
},
}

container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: logVolume(componentType),
MountPath: "/usr/local/nebula/logs",
SubPath: "logs",
})
}

return container
Expand Down Expand Up @@ -310,7 +344,7 @@ func generateContainers(c NebulaClusterComponentter, cm *corev1.ConfigMap) []cor

containers = append(containers, baseContainer)

if nc.IsBREnabled() {
if nc.IsBREnabled() || nc.IsLogRotateEnabled() {
agentContainer := generateAgentContainer(c, false)
containers = append(containers, agentContainer)
}
Expand Down
31 changes: 28 additions & 3 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ type NebulaClusterSpec struct {
// +optional
EnableBR *bool `json:"enableBR,omitempty"`

// optional
//BrAgentVersion *string `json:"brAgentVersion,omitempty"`
// +optional
LogRotate *LogRotate `json:"logRotate,omitempty"`

// +optional
Exporter *ExporterSpec `json:"exporter,omitempty"`
}

// NebulaClusterStatus defines the observed state of NebulaCluster
Expand Down Expand Up @@ -193,6 +196,26 @@ type WorkloadReference struct {
Version string `json:"version,omitempty"`
}

type LogRotate struct {
// +kubebuilder:default=5
// +optional
Rotate int32 `json:"rotate,omitempty"`

// +kubebuilder:default="200M"
// +optional
Size string `json:"size,omitempty"`
}

// ExporterSpec defines the desired state of Exporter
type ExporterSpec struct {
PodSpec `json:",inline"`

// Maximum number of parallel scrape requests
// +kubebuilder:default=40
// +optional
MaxRequests int32 `json:"maxRequests,omitempty"`
}

type LicenseSpec struct {
// Name of the license secret name.
SecretName string `json:"secretName,omitempty"`
Expand Down Expand Up @@ -281,7 +304,6 @@ type PodSpec struct {
// +optional
EnvVars []corev1.EnvVar `json:"env,omitempty"`

// +kubebuilder:default=vesoft/graphd
// +optional
Image string `json:"image,omitempty"`

Expand Down Expand Up @@ -317,6 +339,9 @@ type PodSpec struct {

// +optional
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`

// +optional
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`
}

// StorageClaim contains details of storage
Expand Down
46 changes: 46 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

Loading