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: add the ability to group instances between node definitions #8

Merged
merged 2 commits into from
Jul 28, 2024
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
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ the configuration options available:
| YAML Key | Environment Variable | Description |
|---|---|---|
| `nodes.instances` | `KHEPER_NODES_INSTANCES` | The number of node instances to create. (default: 1) |
| `nodes.group` | `KHEPER_NODES_GROUP` | The name of the group to which the node instance belongs. |
| `nodes.hostname` | `KHEPER_NODES_HOSTNAME` | The RFC 1123 hostname of the node. This can be a `sequential` hostname or a specific hostname. when `sequential` is specified, a sequential hostname will be generated starting with `00000000-0000-4000-8000-000000000001` and incrementing by 1 hexadecimal digit for each node. (default: **sequential**) |
| `nodes.id` | `KHEPER_NODES_ID` | The unique ID of the node. This can be a `sequential`, `unique`, or a specific UUID. When `sequential` is specified, a sequential UUID will be generated starting with `00000000-0000-4000-8000-000000000001` and incrementing by 1 hexadecimal digit for each node. When `unique` is specified, a unique UUID will be generated. (default: **sequential**) |
| `nodes.versions` | `KHEPER_NODES_VERSIONS` | The Kong Gateway semantic versions of the node. This version can be represented as 3 or 4 integers separated by dots (e.g. 1.2.3 or 1.2.3.4). Each version in the slice will be "round-robin" across the nodes based on the number of instances. (default: **3.7.0.0**) |
Expand Down Expand Up @@ -285,8 +286,15 @@ The Kheper Mock Data Plane Node Application provides an Admin API to manage and

```json
[
"example-host1.com",
"example-host2.com"
{
"hostname": "example-host1.com"
},
{
"groups": [
"kong-gateway-oss",
],
"hostname":"example-host2.com"
}
]
```

Expand All @@ -302,13 +310,15 @@ The Kheper Mock Data Plane Node Application provides an Admin API to manage and
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"cipher_suite": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"group": "kong-gateway-oss",
"hostname": "node1.example-host.com",
"tls_version": "TLSv1.2",
"version": "1.2.3"
},
{
"id": "223e4567-e89b-12d3-a456-426614174001",
"cipher_suite": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"group": "kong-gateway-oss",
"hostname": "node2.example-host.com",
"tls_version": "TLSv1.2",
"version": "1.2.3.1"
Expand All @@ -328,6 +338,7 @@ The Kheper Mock Data Plane Node Application provides an Admin API to manage and
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"cipher_suite": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"group": "kong-gateway-oss",
"hostname": "node1.example-host.com",
"tls_version": "TLSv1.2",
"version": "1.2.3",
Expand Down
12 changes: 6 additions & 6 deletions docs/openapi.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mikefero/kheper

go 1.22.4
go 1.22.5

require (
github.com/gavv/httpexpect/v2 v2.16.0
Expand Down Expand Up @@ -72,7 +72,7 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
71 changes: 37 additions & 34 deletions internal/api/spec.go

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

39 changes: 25 additions & 14 deletions internal/api/types.go

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

5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type Node struct {
Connection Connection `yaml:"connection" mapstructure:"connection"`
// Instances is the number of nodes to create.
Instances int `yaml:"instances" mapstructure:"instances"`
// Group is the name of the group to which the node instance belongs.
Group *string `yaml:"group" mapstructure:"group"`
// Hostname is the RFC 1123 hostname of the node. If 'sequential' is specified
// a sequential hostname will be generated; otherwise, the hostname will be
// used as-is.
Expand Down Expand Up @@ -170,6 +172,9 @@ func NewConfig() (*Config, error) {
// Bind environment variables to viper that do not have a corresponding
// default value
viper.SetEnvPrefix("kheper")
if err := viper.BindEnv("nodes.group"); err != nil {
return nil, fmt.Errorf("unable to bind nodes.group environment variable: %w", err)
}
if err := viper.BindEnv("nodes.connection.host"); err != nil {
return nil, fmt.Errorf("unable to bind nodes.connection.host environment variable: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestConfig(t *testing.T) {
timeouts:
write: 10s
nodes:
group: test
connection:
host: localhost
port: 3737
Expand All @@ -135,6 +136,7 @@ nodes:
actual, err := config.NewConfig()
require.NoError(t, err)

group := "test"
expected := &config.Config{
Server: config.Server{
Port: 4747,
Expand Down Expand Up @@ -162,6 +164,7 @@ nodes:
Key: "key",
},
Instances: 1,
Group: &group,
Hostname: "sequential",
ID: "sequential",
Versions: []string{"3.7.0.0"},
Expand Down Expand Up @@ -248,6 +251,7 @@ nodes:
t.Setenv("KHEPER_DEFAULTS_RECONNECTION_INTERVAL", "1s")
t.Setenv("KHEPER_DEFAULTS_RECONNECTION_JITTER", "2s")
t.Setenv("KHEPER_NODES_INSTANCES", "5")
t.Setenv("KHEPER_NODES_GROUP", "kheper")
t.Setenv("KHEPER_NODES_HOSTNAME", "kheper.local")
t.Setenv("KHEPER_NODES_ID", "unique")
t.Setenv("KHEPER_NODES_CONNECTION_PROTOCOL", "jsonrpc")
Expand All @@ -259,6 +263,7 @@ nodes:
t.Fatalf("unable to create config: %v", err)
}

group := "kheper"
expected := &config.Config{
Server: config.Server{
Port: 4747,
Expand Down Expand Up @@ -287,6 +292,7 @@ nodes:
TLSVersion: "TLS1.2",
},
Instances: 5,
Group: &group,
Hostname: "kheper.local",
ID: "unique",
Versions: []string{"3.6.0.0", "3.5.0.0"},
Expand Down
Loading