Skip to content

Commit

Permalink
feat: e2e add static custom config (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
veezhang authored Oct 18, 2023
1 parent cc3881f commit a6e1992
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 3 deletions.
85 changes: 82 additions & 3 deletions tests/e2e/envfuncsext/nebulacluster-ready-func.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ limitations under the License.
package envfuncsext

import (
"bufio"
"context"
stderrors "errors"
"fmt"
"regexp"
"strings"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"sigs.k8s.io/e2e-framework/pkg/envconf"
Expand Down Expand Up @@ -121,10 +125,14 @@ func defaultNebulaClusterReadyFuncForStatus(ctx context.Context, cfg *envconf.Co
func defaultNebulaClusterReadyFuncForGraphd(ctx context.Context, cfg *envconf.Config, nc *appsv1alpha1.NebulaCluster) (bool, error) {
isReady := true

{ // Graphd StatefulSet checks
{
if !isComponentStatefulSetExpected(ctx, cfg, nc.GraphdComponent()) {
isReady = false
}

if !isComponentConfigMapExpected(ctx, cfg, nc.GraphdComponent()) {
isReady = false
}
}

return isReady, nil
Expand All @@ -133,10 +141,14 @@ func defaultNebulaClusterReadyFuncForGraphd(ctx context.Context, cfg *envconf.Co
func defaultNebulaClusterReadyFuncForMetad(ctx context.Context, cfg *envconf.Config, nc *appsv1alpha1.NebulaCluster) (bool, error) {
isReady := true

{ // Metad Resource checks
{
if !isComponentStatefulSetExpected(ctx, cfg, nc.MetadComponent()) {
isReady = false
}

if !isComponentConfigMapExpected(ctx, cfg, nc.MetadComponent()) {
isReady = false
}
}

return isReady, nil
Expand All @@ -145,10 +157,14 @@ func defaultNebulaClusterReadyFuncForMetad(ctx context.Context, cfg *envconf.Con
func defaultNebulaClusterReadyFuncForStoraged(ctx context.Context, cfg *envconf.Config, nc *appsv1alpha1.NebulaCluster) (bool, error) {
isReady := true

{ // Storaged Resource checks
{
if !isComponentStatefulSetExpected(ctx, cfg, nc.StoragedComponent()) {
isReady = false
}

if !isComponentConfigMapExpected(ctx, cfg, nc.StoragedComponent()) {
isReady = false
}
}

return isReady, nil
Expand Down Expand Up @@ -266,3 +282,66 @@ func isComponentStatefulSetExpected(ctx context.Context, cfg *envconf.Config, co

return true
}

func isComponentConfigMapExpected(ctx context.Context, cfg *envconf.Config, component appsv1alpha1.NebulaClusterComponent) bool {
componentConfigExpected := component.GetConfig()
if len(componentConfigExpected) == 0 {
return true
}

cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: component.GetName(),
Namespace: component.GetNamespace(),
},
}

if err := cfg.Client().Resources().Get(ctx, cm.Name, cm.Namespace, cm); err != nil {
klog.InfoS("Check Component Resource but ConfigMap not found",
"namespace", cm.Namespace,
"name", cm.Name,
)
return false
}

// extract configuration
componentConfig := make(map[string]string)
paramValuePattern := regexp.MustCompile(`--(\w+)=(.+)`)
scanner := bufio.NewScanner(strings.NewReader(cm.Data[component.GetConfigMapKey()]))
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
line := scanner.Text()
if !strings.HasPrefix(line, "--") {
continue
}

matches := paramValuePattern.FindStringSubmatch(line)
if len(matches) != 3 {
continue
}

componentConfig[matches[1]] = matches[2]
}
if err := scanner.Err(); err != nil {
klog.ErrorS(err, "failed to parse configuration",
"namespace", cm.Namespace,
"name", cm.Name,
)
return false
}

matchers := make(map[string]any, len(componentConfigExpected))
for k, v := range componentConfigExpected {
matchers[k] = e2ematcher.ValidatorEq(v)
}

if err := e2ematcher.Struct(componentConfig, matchers); err != nil {
klog.ErrorS(err, "Waiting for NebulaCluster to be ready but ConfigMap not expected",
"namespace", cm.Namespace,
"name", cm.Name,
)
return false
}

return true
}
99 changes: 99 additions & 0 deletions tests/e2e/nebulacluster_custom_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package e2e

import (
"github.com/vesoft-inc/nebula-operator/tests/e2e/e2ematcher"
"sigs.k8s.io/e2e-framework/third_party/helm"

"github.com/vesoft-inc/nebula-operator/tests/e2e/envfuncsext"
)

const (
LabelCustomConfig = "custom config"
LabelCustomConfigStatic = "static"
LabelCustomConfigDynamic = "dynamic"
)

var testCasesCustomConfig []ncTestCase

func init() {
testCasesCustomConfig = append(testCasesCustomConfig, testCasesCustomConfigStatic...)
testCasesCustomConfig = append(testCasesCustomConfig, testCasesCustomConfigDynamic...)
}

// test cases about static custom config
var testCasesCustomConfigStatic = []ncTestCase{
{
Name: "custom config for static",
Labels: map[string]string{
LabelKeyCategory: LabelCustomConfig,
LabelKeyGroup: LabelCustomConfigStatic,
},
InstallWaitNCOptions: []envfuncsext.NebulaClusterOption{
envfuncsext.WithNebulaClusterReadyFuncs(
envfuncsext.NebulaClusterReadyFuncForFields(false, map[string]any{
"Spec": map[string]any{
"Graphd": map[string]any{
"Replicas": e2ematcher.ValidatorEq(2),
},
"Metad": map[string]any{
"Replicas": e2ematcher.ValidatorEq(3),
},
"Storaged": map[string]any{
"Replicas": e2ematcher.ValidatorEq(3),
},
},
}),
envfuncsext.DefaultNebulaClusterReadyFunc,
),
},
LoadLDBC: true,
UpgradeCases: []ncTestUpgradeCase{
{
Name: "update configs",
UpgradeFunc: nil,
UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
envfuncsext.WithNebulaClusterHelmRawOptions(
helm.WithArgs(
"--set-string", "nebula.graphd.config.max_sessions_per_ip_per_user=100",
"--set-string", "nebula.metad.config.default_parts_num=30",
"--set-string", "nebula.storaged.config.minimum_reserved_bytes=134217728",
),
),
},
UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
envfuncsext.WithNebulaClusterReadyFuncs(
envfuncsext.NebulaClusterReadyFuncForFields(false, map[string]any{
"Spec": map[string]any{
"Graphd": map[string]any{
"Replicas": e2ematcher.ValidatorEq(2),
"Config": map[string]any{
"max_sessions_per_ip_per_user": e2ematcher.ValidatorEq("100"),
},
},
"Metad": map[string]any{
"Replicas": e2ematcher.ValidatorEq(3),
"Config": map[string]any{
"default_parts_num": e2ematcher.ValidatorEq("30"),
},
},
"Storaged": map[string]any{
"Replicas": e2ematcher.ValidatorEq(3),
"Config": map[string]any{
"minimum_reserved_bytes": e2ematcher.ValidatorEq("134217728"),
},
},
},
}),
// TODO: check whether the change is really successful via host:port/flags api
envfuncsext.DefaultNebulaClusterReadyFunc,
),
},
},
},
},
}

// test cases about dynamic custom config
var testCasesCustomConfigDynamic = []ncTestCase{
// TODO
}
1 change: 1 addition & 0 deletions tests/e2e/nebulacluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var ncGlobalTestCases []ncTestCase

func init() {
ncGlobalTestCases = append(ncGlobalTestCases, testCasesBasic...)
ncGlobalTestCases = append(ncGlobalTestCases, testCasesCustomConfig...)
}

type (
Expand Down

0 comments on commit a6e1992

Please sign in to comment.