-
Notifications
You must be signed in to change notification settings - Fork 20
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
test: support running integration test with envoy bin #810
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright The HTNN Authors. | ||
// | ||
// 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 dataplane | ||
|
||
import "os" | ||
|
||
var ( | ||
binaryPath = "" | ||
) | ||
|
||
func init() { | ||
binaryPath = os.Getenv("TEST_ENVOY_BINARY_PATH") | ||
} | ||
|
||
func isBinaryMode() bool { | ||
return binaryPath != "" | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |||||||
"encoding/json" | ||||||||
"math/rand" | ||||||||
"os" | ||||||||
"strconv" | ||||||||
|
||||||||
"gopkg.in/yaml.v3" | ||||||||
) | ||||||||
|
@@ -34,6 +35,8 @@ type bootstrap struct { | |||||||
httpFilterGolang map[string]interface{} | ||||||||
accessLogFormat string | ||||||||
clusters []map[string]interface{} | ||||||||
|
||||||||
dp *DataPlane | ||||||||
} | ||||||||
|
||||||||
func Bootstrap() *bootstrap { | ||||||||
|
@@ -44,6 +47,10 @@ func Bootstrap() *bootstrap { | |||||||
} | ||||||||
} | ||||||||
|
||||||||
func (b *bootstrap) SetDataPlane(dp *DataPlane) { | ||||||||
b.dp = dp | ||||||||
} | ||||||||
|
||||||||
func (b *bootstrap) AddBackendRoute(s string) *bootstrap { | ||||||||
var n map[string]interface{} | ||||||||
err := yaml.Unmarshal([]byte(s), &n) | ||||||||
|
@@ -150,15 +157,19 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) { | |||||||
staticResources := root["static_resources"].(map[string]interface{}) | ||||||||
clusters := staticResources["clusters"].([]interface{}) | ||||||||
|
||||||||
port := "9999" | ||||||||
portEnv := os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT") | ||||||||
if portEnv != "" { | ||||||||
port := 9999 | ||||||||
portEnv, _ := strconv.Atoi(os.Getenv("TEST_ENVOY_CONTROL_PLANE_PORT")) | ||||||||
if portEnv != 0 { | ||||||||
port = portEnv | ||||||||
} | ||||||||
for _, c := range clusters { | ||||||||
if c.(map[string]interface{})["name"] == "config_server" { | ||||||||
load := c.(map[string]interface{})["load_assignment"].(map[string]interface{})["endpoints"].([]interface{})[0].(map[string]interface{})["lb_endpoints"].([]interface{})[0].(map[string]interface{})["endpoint"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{}) | ||||||||
load["port_value"] = port | ||||||||
|
||||||||
if isBinaryMode() { | ||||||||
load["address"] = "0.0.0.0" | ||||||||
} | ||||||||
break | ||||||||
} | ||||||||
} | ||||||||
|
@@ -168,6 +179,26 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) { | |||||||
newClusters = append(newClusters, c) | ||||||||
} | ||||||||
staticResources["clusters"] = append(clusters, newClusters...) | ||||||||
|
||||||||
addr := root["admin"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{}) | ||||||||
addr["port_value"] = b.dp.AdminAPIPort() | ||||||||
addr = staticResources["listeners"].([]interface{})[0].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{}) | ||||||||
addr["port_value"] = b.dp.Port() | ||||||||
|
||||||||
if isBinaryMode() { | ||||||||
for _, l := range root["static_resources"].(map[string]interface{})["listeners"].([]interface{}) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use
Suggested change
|
||||||||
listener := l.(map[string]interface{}) | ||||||||
hcm := listener["filter_chains"].([]interface{})[0].(map[string]interface{})["filters"].([]interface{})[0].(map[string]interface{})["typed_config"].(map[string]interface{}) | ||||||||
httpFilters := hcm["http_filters"].([]interface{}) | ||||||||
for _, hf := range httpFilters { | ||||||||
Comment on lines
+192
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like
Suggested change
|
||||||||
cfg := hf.(map[string]interface{})["typed_config"].(map[string]interface{}) | ||||||||
if cfg["@type"] == "type.googleapis.com/envoy.extensions.filters.http.golang.v3alpha.Config" { | ||||||||
cfg["library_path"] = b.dp.soPath | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
return root, nil | ||||||||
} | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the following method, but yours is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, thanks! My code style is more concise.