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 nacos storage #796

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bd58388
feat: support nacos storage
sjcsjc123 Jan 22, 2024
625c61d
recover something
sjcsjc123 Jan 22, 2024
d848bb8
recover something
sjcsjc123 Jan 22, 2024
e8888cb
recover something
sjcsjc123 Jan 22, 2024
d01a220
simple
sjcsjc123 Jan 22, 2024
d8bb8d3
fix bug
sjcsjc123 Jan 23, 2024
5aed7f4
modify nacos image
sjcsjc123 Jan 23, 2024
0ffcc30
update nacos image in Makefile
sjcsjc123 Jan 23, 2024
c0c4e38
add nacos client
sjcsjc123 Jan 23, 2024
8eb8f5b
add ci for nacos storage
sjcsjc123 Jan 23, 2024
9bb4920
delete something
sjcsjc123 Jan 23, 2024
31ca385
fix bug with start fail
sjcsjc123 Jan 23, 2024
b5fd8a7
rename make
sjcsjc123 Jan 23, 2024
85b8274
opt import
sjcsjc123 Jan 23, 2024
370d386
update e2e
sjcsjc123 Jan 24, 2024
01c08fe
opt import
sjcsjc123 Jan 24, 2024
06651de
recover something
sjcsjc123 Jan 24, 2024
35c5db1
modify default falg value
sjcsjc123 Jan 24, 2024
9449862
make ci print simple
sjcsjc123 Jan 24, 2024
ecb2672
update apply
sjcsjc123 Jan 24, 2024
62c421a
update apply
sjcsjc123 Jan 24, 2024
2e72259
add wasm+nacos ci
sjcsjc123 Jan 24, 2024
0c83d5f
update wasm+nacos ci
sjcsjc123 Jan 24, 2024
0715626
fix ci
sjcsjc123 Jan 24, 2024
62cb1dd
fix bug with wasm plugin
sjcsjc123 Jan 24, 2024
8ce8df9
Merge branch 'main' into helm/nacos-storage
sjcsjc123 Jan 27, 2024
cd3527e
Merge branch 'main' into helm/nacos-storage
sjcsjc123 Jan 31, 2024
4b5cd88
fix ci
sjcsjc123 Feb 1, 2024
a3ecec7
Merge branch 'main' into helm/nacos-storage
sjcsjc123 Feb 1, 2024
9349772
fix ci
sjcsjc123 Feb 1, 2024
a3b114b
fix ci
sjcsjc123 Feb 1, 2024
41bd16a
Merge branch 'main' into helm/nacos-storage
johnlanni Feb 3, 2024
598aaf0
Merge branch 'main' into helm/nacos-storage
johnlanni Feb 20, 2024
a8af197
Merge branch 'main' into helm/nacos-storage
sjcsjc123 Feb 28, 2024
6cd64b4
update nacos image
sjcsjc123 Feb 29, 2024
5575512
update nacos image
sjcsjc123 Feb 29, 2024
81810c0
fix ci
sjcsjc123 Feb 29, 2024
daba6c7
fix ci
sjcsjc123 Feb 29, 2024
32a6786
fix ci
sjcsjc123 Mar 1, 2024
0a425dd
fix ci
sjcsjc123 Mar 1, 2024
0f270ce
Merge branch 'main' into helm/nacos-storage
sjcsjc123 Mar 27, 2024
b306f61
Merge branch 'main' into helm/nacos-storage
johnlanni Apr 1, 2024
688442b
Merge branch 'main' into helm/nacos-storage
johnlanni Apr 23, 2024
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
36 changes: 35 additions & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,41 @@ jobs:

- name: "Run Higress E2E Conformance Tests"
run: GOPROXY="https://proxy.golang.org,direct" make higress-conformance-test


higress-conformance-test-nacos:
runs-on: ubuntu-latest
needs: [ build ]
steps:
- uses: actions/checkout@v3

- name: "Setup Go"
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Setup Golang Caches
uses: actions/cache@v3
with:
path: |-
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-go

- name: Setup Submodule Caches
uses: actions/cache@v3
with:
path: |-
.git/modules
key: ${{ runner.os }}-submodules-cache-${{ github.run_id }}
restore-keys: ${{ runner.os }}-submodules-cache

- run: git stash # restore patch

- name: "Run Higress E2E Conformance Nacos Tests"
run: GOPROXY="https://proxy.golang.org,direct" make higress-conformance-test-nacos

publish:
runs-on: ubuntu-latest
needs: [higress-conformance-test,gateway-conformance-test]
Expand Down
17 changes: 17 additions & 0 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ higress-conformance-test: $(tools/kind) delete-cluster create-cluster docker-bui
.PHONY: higress-wasmplugin-test
higress-wasmplugin-test: $(tools/kind) delete-cluster create-cluster docker-build kube-load-image install-dev-wasmplugin run-higress-e2e-test-wasmplugin delete-cluster

# higress-conformance-test-nacos runs ingress nacos tests.
.PHONY: higress-conformance-test-nacos
higress-conformance-test-nacos: $(tools/kind) delete-cluster create-cluster docker-build kube-load-image install-dev-nacos port-forward run-higress-e2e-test-nacos delete-cluster

.PHONY: port-forward
port-forward:
sjcsjc123 marked this conversation as resolved.
Show resolved Hide resolved
kubectl port-forward -n higress-system svc/nacos-service 8848:8848 &

# create-cluster creates a kube cluster with kind.
.PHONY: create-cluster
create-cluster: $(tools/kind)
Expand Down Expand Up @@ -293,3 +301,12 @@ run-higress-e2e-test-wasmplugin:
@echo -e "\n\033[36mWaiting higress-gateway to be ready...\033[0m\n"
kubectl wait --timeout=10m -n higress-system deployment/higress-gateway --for=condition=Available
go test -v -tags conformance ./test/e2e/e2e_test.go -isWasmPluginTest=true -wasmPluginType=$(PLUGIN_TYPE) -wasmPluginName=$(PLUGIN_NAME) --ingress-class=higress --debug=true

.PHONY: run-higress-e2e-test-nacos
run-higress-e2e-test-nacos:
@echo -e "\n\033[36mRunning higress conformance tests...\033[0m"
@echo -e "\n\033[36mWaiting higress-controller to be ready...\033[0m\n"
kubectl wait --timeout=10m -n higress-system deployment/higress-controller --for=condition=Available
@echo -e "\n\033[36mWaiting higress-gateway to be ready...\033[0m\n"
kubectl wait --timeout=10m -n higress-system deployment/higress-gateway --for=condition=Available
go test -v -tags conformance ./test/e2e/e2e_test.go --ingress-class=higress --debug=true --enableApiServer=true
23 changes: 1 addition & 22 deletions helm/core/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,7 @@ metadata:
labels:
{{- include "gateway.labels" . | nindent 4 }}
data:
{{- if .Values.apiserver.enabled }}
kubeconfig: |
apiVersion: v1
kind: Config
clusters:
- name: {{ .Values.clusterName | default "higress" }}
cluster:
server: https://{{ .Values.apiserver.addr }}:{{ .Values.apiserver.securePort }}
insecure-skip-tls-verify: true
users:
- name: higress-admin
user:
client-certificate-data: {{ .Files.Get "files/api/client.crt" | b64enc }}
client-key-data: {{ .Files.Get "files/api/client.key" | b64enc }}
contexts:
- name: higress
context:
cluster: higress
user: higress-admin
preferences: {}
current-context: higress
{{- end }}

# Configuration file for the mesh networks to be used by the Split Horizon EDS.
meshNetworks: |-
{{- if .Values.global.meshNetworks }}
Expand Down
16 changes: 0 additions & 16 deletions helm/core/templates/controller-secret.yaml

This file was deleted.

97 changes: 97 additions & 0 deletions test/e2e/conformance/utils/configcenter/nacos/nacos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nacos

import (
"net/url"
"strconv"
"strings"

cc "github.com/alibaba/higress/test/e2e/conformance/utils/configcenter"
"github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/clients/config_client"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
)

type storage struct {
client config_client.IConfigClient
}

func NewClient(addr string) (cc.Storage, error) {
clientConfig := constant.NewClientConfig(
constant.WithNamespaceId(""),
constant.WithUsername(""),
constant.WithPassword(""),
constant.WithLogLevel("info"),
)

serverUrl, err := url.Parse(addr)
if err != nil {
return nil, err
}
rawPort := serverUrl.Port()
var port uint64
if rawPort != "" {
port, err = strconv.ParseUint(rawPort, 10, 0)
if err != nil || port < 1 || port > 65535 {
return nil, err
}
} else {
port = 80
}
path := serverUrl.Path
if strings.HasSuffix(path, "/") {
path = path[:len(path)-1]
}
serverConfigs := []constant.ServerConfig{
{
IpAddr: serverUrl.Hostname(),
ContextPath: path,
Port: port,
Scheme: serverUrl.Scheme,
},
}

client, err := clients.NewConfigClient(
vo.NacosClientParam{
ClientConfig: clientConfig,
ServerConfigs: serverConfigs,
},
)
if err != nil {
return nil, err
}
return storage{
client: client,
}, nil
}

func (s storage) PublishConfig(dataId, group, content string) error {
_, err := s.client.PublishConfig(vo.ConfigParam{
DataId: dataId,
Group: group,
Content: content,
})
return err
}

func (s storage) DeleteConfig(dataId, group string) error {
_, err := s.client.DeleteConfig(vo.ConfigParam{
DataId: dataId,
Group: group,
})
return err
}
20 changes: 20 additions & 0 deletions test/e2e/conformance/utils/configcenter/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cc

type Storage interface {
PublishConfig(dataId, group, content string) error
DeleteConfig(dataId, group string) error
}
3 changes: 3 additions & 0 deletions test/e2e/conformance/utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ var (
WasmPluginType = flag.String("wasmPluginType", "GO", "Define wasm plugin type, currently supports GO, CPP")
WasmPluginName = flag.String("wasmPluginName", "", "Define wasm plugin name")
IsEnvoyConfigTest = flag.Bool("isEnvoyConfigTest", false, "Determine if run envoy config conformance test")
EnableApiServer = flag.Bool("enableApiServer", false, "Determine if enable api server")
// TODO when apiserver support other mode, we can use string field like: nacos://username:password@ip:port/namespace
Storage = flag.String("storage", "http://127.0.0.1:8848", "Define storage")
)
35 changes: 35 additions & 0 deletions test/e2e/conformance/utils/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

ingress "github.com/alibaba/higress/test/e2e/conformance"
cc "github.com/alibaba/higress/test/e2e/conformance/utils/configcenter"
"github.com/stretchr/testify/require"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -249,3 +250,37 @@ func getContentsFromPathOrURL(location string, timeoutConfig config.TimeoutConfi
}
return bytes.NewBuffer(b), nil
}

// MustPublishConfig publish config to config center
func (a Applier) MustPublishConfig(t *testing.T, timeoutConfig config.TimeoutConfig, location string, cleanup bool, cc cc.Storage) {
data, err := getContentsFromPathOrURL(location, timeoutConfig)
require.NoError(t, err)

decoder := yaml.NewYAMLOrJSONDecoder(data, 4096)

resources, err := a.prepareResources(t, decoder)
if err != nil {
t.Logf("🧳 Manifest: %s", data.String())
require.NoErrorf(t, err, "error parsing manifest")
}

for _, r := range resources {
// TODO: Maybe add s or es
dataId := r.GetKind() + "es"
group := r.GetNamespace()
// convert r to string
var content []byte
content, err = r.MarshalJSON()
require.NoError(t, err)
// publish
err = cc.PublishConfig(dataId, group, string(content))
require.NoError(t, err)
if cleanup {
t.Cleanup(func() {
// delete
err = cc.DeleteConfig(dataId, group)
require.NoError(t, err)
})
}
}
}
34 changes: 30 additions & 4 deletions test/e2e/conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ package suite

import (
"fmt"
"github.com/alibaba/higress/test/e2e/conformance/utils/configcenter/nacos"
"testing"

"github.com/alibaba/higress/test/e2e/conformance/utils/config"
cc "github.com/alibaba/higress/test/e2e/conformance/utils/configcenter"
"github.com/alibaba/higress/test/e2e/conformance/utils/kubernetes"
"github.com/alibaba/higress/test/e2e/conformance/utils/roundtripper"
"github.com/stretchr/testify/require"
"istio.io/istio/pilot/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -38,6 +41,9 @@ type ConformanceTestSuite struct {
SkipTests sets.Set
TimeoutConfig config.TimeoutConfig
SupportedFeatures sets.Set
EnableApiServer bool
Storage string
ConfigCenter cc.Storage
}

// Options can be used to initialize a ConformanceTestSuite.
Expand All @@ -63,6 +69,9 @@ type Options struct {

// IsEnvoyConfigTest indicates whether or not the test is for envoy config
IsEnvoyConfigTest bool

EnableApiServer bool
Storage string
sjcsjc123 marked this conversation as resolved.
Show resolved Hide resolved
}

type WASMOptions struct {
Expand Down Expand Up @@ -112,7 +121,9 @@ func New(s Options) *ConformanceTestSuite {
Applier: kubernetes.Applier{
NamespaceLabels: s.NamespaceLabels,
},
TimeoutConfig: s.TimeoutConfig,
TimeoutConfig: s.TimeoutConfig,
EnableApiServer: s.EnableApiServer,
Storage: s.Storage,
}

// apply defaults
Expand All @@ -132,6 +143,14 @@ func New(s Options) *ConformanceTestSuite {
// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T) {
if suite.EnableApiServer {
t.Logf("📦 Test Setup: Ensuring ApiServer Storage has been accepted")
configClient, err := nacos.NewClient(suite.Storage)
require.NoError(t, err)
require.NotNil(t, configClient)
suite.ConfigCenter = configClient
}

t.Logf("📦 Test Setup: Ensuring IngressClass has been accepted")

suite.Applier.IngressClass = suite.IngressClassName
Expand Down Expand Up @@ -220,9 +239,16 @@ func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) {
suite.Applier.MustDelete(t, suite.Client, suite.TimeoutConfig, manifestLocation)
}

for _, manifestLocation := range test.Manifests {
t.Logf("🧳 Applying Manifests: %s", manifestLocation)
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, manifestLocation, !test.NotCleanup)
if suite.EnableApiServer {
for _, manifestLocation := range test.Manifests {
t.Logf("🧳 Applying ApiServer Storage Manifests")
suite.Applier.MustPublishConfig(t, suite.TimeoutConfig, manifestLocation, !test.NotCleanup, suite.ConfigCenter)
}
} else {
for _, manifestLocation := range test.Manifests {
t.Logf("🧳 Applying Manifests: %s", manifestLocation)
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, manifestLocation, !test.NotCleanup)
}
}

test.Test(t, suite)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func TestHigressConformanceTests(t *testing.T) {
},
GatewayAddress: "localhost",
EnableAllSupportedFeatures: true,
EnableApiServer: *flags.EnableApiServer,
Storage: *flags.Storage,
IsEnvoyConfigTest: *flags.IsEnvoyConfigTest,
})

Expand Down
Loading
Loading