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: support config license_manager_url #196

Merged
merged 2 commits into from
May 14, 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
4 changes: 2 additions & 2 deletions apis/apps/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the apps v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=apps.nebula-graph.io
// +kubebuilder:object:generate=true
// +groupName=apps.nebula-graph.io
package v1alpha1

import (
Expand Down
14 changes: 9 additions & 5 deletions apis/apps/v1alpha1/nebulacluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,16 @@ func generateContainers(c NebulaClusterComponentter, cm *corev1.ConfigMap) []cor
}

metadAddress := strings.Join(nc.GetMetadEndpoints(MetadPortNameThrift), ",")
flags := " --meta_server_addrs=" + metadAddress +
" --local_ip=$(hostname)." + c.GetServiceFQDN() +
" --ws_ip=$(hostname)." + c.GetServiceFQDN() +
" --daemonize=false" + dataPath
if c.Type() == MetadComponentType && nc.Spec.Metad.LicenseManagerURL != nil {
flags += " --license_manager_url=" + *nc.Spec.Metad.LicenseManagerURL
}

cmd = append(cmd, fmt.Sprintf("exec /usr/local/nebula/bin/nebula-%s", componentType)+
fmt.Sprintf(" --flagfile=/usr/local/nebula/etc/nebula-%s.conf", componentType)+
" --meta_server_addrs="+metadAddress+
" --local_ip=$(hostname)."+c.GetServiceFQDN()+
" --ws_ip=$(hostname)."+c.GetServiceFQDN()+
" --daemonize=false"+dataPath)
fmt.Sprintf(" --flagfile=/usr/local/nebula/etc/nebula-%s.conf", componentType)+flags)

mounts := c.GenerateVolumeMounts()
if cm != nil {
Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_graphd.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ func (c *graphdComponent) GenerateVolumeClaim() ([]corev1.PersistentVolumeClaim,
func (c *graphdComponent) GenerateWorkload(
gvk schema.GroupVersionKind,
cm *corev1.ConfigMap,
enableEvenPodsSpread bool) (*unstructured.Unstructured, error) {
enableEvenPodsSpread bool,
) (*unstructured.Unstructured, error) {
return generateWorkload(c, gvk, cm, enableEvenPodsSpread)
}

Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_metad.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ func (c *metadComponent) GenerateVolumeClaim() ([]corev1.PersistentVolumeClaim,
func (c *metadComponent) GenerateWorkload(
gvk schema.GroupVersionKind,
cm *corev1.ConfigMap,
enableEvenPodsSpread bool) (*unstructured.Unstructured, error) {
enableEvenPodsSpread bool,
) (*unstructured.Unstructured, error) {
return generateWorkload(c, gvk, cm, enableEvenPodsSpread)
}

Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_storaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ func (c *storagedComponent) GenerateVolumeClaim() ([]corev1.PersistentVolumeClai
func (c *storagedComponent) GenerateWorkload(
gvk schema.GroupVersionKind,
cm *corev1.ConfigMap,
enableEvenPodsSpread bool) (*unstructured.Unstructured, error) {
enableEvenPodsSpread bool,
) (*unstructured.Unstructured, error) {
return generateWorkload(c, gvk, cm, enableEvenPodsSpread)
}

Expand Down
3 changes: 3 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ type MetadSpec struct {

// License defines a nebula license load into Secret
License *LicenseSpec `json:"license,omitempty"`

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

// StoragedSpec defines the desired state of Storaged
Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebularestore_types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package v1alpha1

import (
"github.com/vesoft-inc/nebula-go/v3/nebula"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/vesoft-inc/nebula-go/v3/nebula"
)

// +genclient
Expand Down
5 changes: 5 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.

3 changes: 2 additions & 1 deletion charts/nebula-cluster/templates/nebula-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ spec:
resources: {{ toYaml .Values.nebula.metad.resources | nindent 6 }}
image: {{ .Values.nebula.metad.image }}
version: {{ .Values.nebula.version }}
licenseManagerURL: {{ .Values.nebula.metad.licenseManagerURL }}
env: {{ toYaml .Values.nebula.metad.env | nindent 6 }}
config: {{ toYaml .Values.nebula.metad.config | nindent 6 }}
logVolumeClaim:
Expand All @@ -72,7 +73,7 @@ spec:
requests:
storage: {{ .Values.nebula.metad.dataStorage }}
{{- if .Values.nebula.storageClassName }}
storageClassName: {{ .Values.nebula.storageClassName }}
storageClassName: {{ .Values }}
{{- end }}
labels: {{ toYaml .Values.nebula.metad.podLabels | nindent 6 }}
annotations: {{ toYaml .Values.nebula.metad.podAnnotations | nindent 6 }}
Expand Down
1 change: 1 addition & 0 deletions charts/nebula-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nebula:
memory: "1Gi"
logStorage: "500Mi"
dataStorage: "2Gi"
licenseManagerURL: ""
license: {}
podLabels: {}
podAnnotations: {}
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6435,6 +6435,8 @@ spec:
secretName:
type: string
type: object
licenseManagerURL:
type: string
livenessProbe:
properties:
exec:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/apps.nebula-graph.io_nebularestores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ spec:
additionalProperties:
type: string
type: object
nullable: true
type: object
clusterName:
type: string
Expand All @@ -107,6 +108,7 @@ spec:
- status
- type
type: object
nullable: true
type: array
partitions:
additionalProperties:
Expand All @@ -122,14 +124,17 @@ spec:
- port
type: object
type: array
nullable: true
type: object
phase:
type: string
timeCompleted:
format: date-time
nullable: true
type: string
timeStarted:
format: date-time
nullable: true
type: string
type: object
type: object
Expand Down
2 changes: 0 additions & 2 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
Expand Down Expand Up @@ -26,7 +25,6 @@ webhooks:
resources:
- statefulsets
sideEffects: None

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
1 change: 1 addition & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tools
// +build tools

/*
Expand Down
22 changes: 20 additions & 2 deletions pkg/controller/component/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ func (e *nebulaExporter) generateDeployment(nc *v1alpha1.NebulaCluster) *appsv1.
container := corev1.Container{
Name: "ng-exporter",
Image: nc.GetExporterImage(),
Args: []string{"--listen-address=0.0.0.0:9100", fmt.Sprintf("--namespace=%s", namespace),
fmt.Sprintf("--cluster=%s", ncName), fmt.Sprintf("--max-request=%d", nc.Spec.Exporter.MaxRequests)},
Args: []string{
"--listen-address=0.0.0.0:9100", fmt.Sprintf("--namespace=%s", namespace),
fmt.Sprintf("--cluster=%s", ncName), fmt.Sprintf("--max-request=%d", nc.Spec.Exporter.MaxRequests),
},
Env: nc.GetExporterEnvVars(),
Ports: []corev1.ContainerPort{
{
Expand Down Expand Up @@ -175,3 +177,19 @@ func (e *nebulaExporter) generateDeployment(nc *v1alpha1.NebulaCluster) *appsv1.

return deployment
}

type FakeNebulaExporter struct {
err error
}

func NewFakeNebulaExporter() *FakeNebulaExporter {
return &FakeNebulaExporter{}
}

func (f *FakeNebulaExporter) SetReconcileError(err error) {
f.err = err
}

func (f *FakeNebulaExporter) Reconcile(_ *v1alpha1.NebulaCluster) error {
return f.err
}
6 changes: 4 additions & 2 deletions pkg/controller/component/graphd_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func NewGraphdCluster(
clientSet kube.ClientSet,
dm discovery.Interface,
um UpdateManager,
enableEvenPodsSpread bool) ReconcileManager {
enableEvenPodsSpread bool,
) ReconcileManager {
return &graphdCluster{
clientSet: clientSet,
dm: dm,
Expand Down Expand Up @@ -134,7 +135,8 @@ func (c *graphdCluster) syncGraphdWorkload(nc *v1alpha1.NebulaCluster) error {
func (c *graphdCluster) syncNebulaClusterStatus(
nc *v1alpha1.NebulaCluster,
newWorkload,
oldWorkload *unstructured.Unstructured) error {
oldWorkload *unstructured.Unstructured,
) error {
if oldWorkload == nil {
return nil
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/controller/component/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package component
import (
"encoding/json"
"fmt"
"k8s.io/klog/v2"
"strings"

appsv1 "k8s.io/api/apps/v1"
Expand All @@ -28,6 +27,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog/v2"

"github.com/vesoft-inc/nebula-operator/apis/apps/v1alpha1"
"github.com/vesoft-inc/nebula-operator/pkg/annotation"
Expand All @@ -49,7 +49,8 @@ const (
func syncComponentStatus(
component v1alpha1.NebulaClusterComponentter,
status *v1alpha1.ComponentStatus,
workload *unstructured.Unstructured) error {
workload *unstructured.Unstructured,
) error {
if workload == nil {
return nil
}
Expand Down Expand Up @@ -155,7 +156,8 @@ func syncConfigMap(
component v1alpha1.NebulaClusterComponentter,
cmClient kube.ConfigMap,
template,
cmKey string) (*corev1.ConfigMap, string, bool, error) {
cmKey string,
) (*corev1.ConfigMap, string, bool, error) {
cmHash := hash.Hash(template)
cm := component.GenerateConfigMap()
cfg := component.GetConfig()
Expand Down Expand Up @@ -219,7 +221,8 @@ func updateDynamicFlags(endpoints []string, newAnnotations, oldAnnotations map[s

func getContainerImage(
obj *unstructured.Unstructured,
containerName string) string {
containerName string,
) string {
if obj == nil {
return ""
}
Expand All @@ -235,7 +238,8 @@ func getContainerImage(
func isUpdating(
component v1alpha1.NebulaClusterComponentter,
podClient kube.Pod,
obj *unstructured.Unstructured) (bool, error) {
obj *unstructured.Unstructured,
) (bool, error) {
if extender.IsUpdating(obj) {
return true, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/component/metad_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func NewMetadCluster(
clientSet kube.ClientSet,
dm discovery.Interface,
um UpdateManager,
enableEvenPodsSpread bool) ReconcileManager {
enableEvenPodsSpread bool,
) ReconcileManager {
return &metadCluster{
clientSet: clientSet,
dm: dm,
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func NewStoragedCluster(
dm discovery.Interface,
sm ScaleManager,
um UpdateManager,
enableEvenPodsSpread bool) ReconcileManager {
enableEvenPodsSpread bool,
) ReconcileManager {
return &storagedCluster{
clientSet: clientSet,
dm: dm,
Expand Down Expand Up @@ -173,7 +174,8 @@ func (c *storagedCluster) syncStoragedWorkload(nc *v1alpha1.NebulaCluster) error

func (c *storagedCluster) syncNebulaClusterStatus(
nc *v1alpha1.NebulaCluster,
oldWorkload *unstructured.Unstructured) error {
oldWorkload *unstructured.Unstructured,
) error {
if oldWorkload == nil {
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/component/storaged_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ func (ss *storageScaler) removeHost(
mc nebula.MetaInterface,
nc *v1alpha1.NebulaCluster,
spaceID nebulago.GraphSpaceID,
hosts []*nebulago.HostAddr) error {
hosts []*nebulago.HostAddr,
) error {
if nc.Status.Storaged.LastBalanceJob != nil && nc.Status.Storaged.LastBalanceJob.SpaceID == spaceID {
return mc.BalanceStatus(nc.Status.Storaged.LastBalanceJob.JobID, nc.Status.Storaged.LastBalanceJob.SpaceID)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/nebulacluster/nebula_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func NewDefaultNebulaClusterControl(
exporter component.ReconcileManager,
metaReconciler component.ReconcileManager,
pvcReclaimer reclaimer.PVCReclaimer,
conditionUpdater ClusterConditionUpdater) ControlInterface {
conditionUpdater ClusterConditionUpdater,
) ControlInterface {
return &defaultNebulaClusterControl{
nebulaClient: nebulaClient,
graphdCluster: graphdCluster,
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/nebulacluster/nebula_cluster_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,22 @@ func newFakeNebulaClusterControl() ( // nolint: gocritic
*component.FakeMetadCluster,
*component.FakeStoragedCluster,
*reclaimer.FakeMetaReconciler,
*reclaimer.FakePVCReclaimer) {
*reclaimer.FakePVCReclaimer,
) {
cli := fake.NewClientBuilder().Build()
fakeNebulaClient := kube.NewFakeNebulaCluster(cli)
graphdCluster := component.NewFakeGraphdCluster()
metadCluster := component.NewFakeMetadCluster()
storagedCluster := component.NewFakeStoragedCluster()
exporter := component.NewFakeNebulaExporter()
metaReconciler := reclaimer.NewFakeMetaReconciler()
pvcReclaimer := reclaimer.NewFakePVCReclaimer()
control := NewDefaultNebulaClusterControl(
fakeNebulaClient,
graphdCluster,
metadCluster,
storagedCluster,
exporter,
metaReconciler,
pvcReclaimer,
&nebulaClusterConditionUpdater{})
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/nebulacluster/nebula_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
return ctrl.Result{}, fmt.Errorf("openkruise scheme not registered")
}

// TODO: check lm license key valid
if err := r.syncNebulaCluster(nebulaCluster.DeepCopy()); err != nil {
isReconcileError := func(err error) (b bool) {
defer func() {
Expand Down
Loading