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

Make consul dataplane handle bootstrap param response for V2 resources #242

Merged
merged 7 commits into from
Sep 6, 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
3 changes: 3 additions & 0 deletions .changelog/242.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
Make consul dataplane handle bootstrap param response for Catalog and Mesh V2 resources
```
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issues:
exclude-rules:
# Allow usage of deprecated values.
- linters: [ staticcheck ]
text: 'SA1019:'
path: "(pkg/consuldp/bootstrap.go)"
48 changes: 41 additions & 7 deletions cmd/consul-dataplane/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"dario.cat/mergo"

"github.com/hashicorp/consul-dataplane/pkg/consuldp"
)

Expand All @@ -22,6 +23,7 @@ type FlagOpts struct {
type DataplaneConfigFlags struct {
Consul ConsulFlags `json:"consul,omitempty"`
Service ServiceFlags `json:"service,omitempty"`
Proxy ProxyFlags `json:"proxy,omitempty"`
Logging LogFlags `json:"logging,omitempty"`
XDSServer XDSServerFlags `json:"xdsServer,omitempty"`
DNSServer DNSServerFlags `json:"dnsServer,omitempty"`
Expand Down Expand Up @@ -76,6 +78,24 @@ type ServiceFlags struct {
Partition *string `json:"partition,omitempty"`
}

func (pf ProxyFlags) IsEmpty() bool {
return pf.NodeName == nil &&
pf.NodeID == nil &&
pf.ID == nil &&
pf.IDPath == nil &&
pf.Namespace == nil &&
pf.Partition == nil
}

type ProxyFlags struct {
NodeName *string `json:"nodeName,omitempty"`
NodeID *string `json:"nodeID,omitempty"`
Comment on lines +91 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these needed with v2. All workload ids must be unique within a tenant so it seems like we may not need these any longer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not needed with V2, however, these flags can be used for both v1 and v2. My intention is to deprecate old flags and to have one set of generically named flags that could be used against either API.

ID *string `json:"id,omitempty"`
IDPath *string `json:"idPath,omitempty"`
Namespace *string `json:"namespace,omitempty"`
Partition *string `json:"partition,omitempty"`
}

type XDSServerFlags struct {
BindAddr *string `json:"bindAddress,omitempty"`
BindPort *int `json:"bindPort,omitempty"`
Expand Down Expand Up @@ -247,6 +267,26 @@ func buildDefaultConsulDPFlags() (DataplaneConfigFlags, error) {
// constructRuntimeConfig constructs the final config needed for dataplane to start
// itself after substituting all the user provided inputs
func constructRuntimeConfig(cfg DataplaneConfigFlags, extraArgs []string) (*consuldp.Config, error) {
// Handle deprecated service flags.
var proxyCfg consuldp.ProxyConfig
if !cfg.Proxy.IsEmpty() {
proxyCfg = consuldp.ProxyConfig{
NodeName: stringVal(cfg.Proxy.NodeName),
NodeID: stringVal(cfg.Proxy.NodeID),
ProxyID: stringVal(cfg.Proxy.ID),
Namespace: stringVal(cfg.Proxy.Namespace),
Partition: stringVal(cfg.Proxy.Partition),
}
} else {
proxyCfg = consuldp.ProxyConfig{
NodeName: stringVal(cfg.Service.NodeName),
NodeID: stringVal(cfg.Service.NodeID),
ProxyID: stringVal(cfg.Service.ServiceID),
Namespace: stringVal(cfg.Service.Namespace),
Partition: stringVal(cfg.Service.Partition),
}
}

return &consuldp.Config{
Consul: &consuldp.ConsulConfig{
Addresses: stringVal(cfg.Consul.Addresses),
Expand Down Expand Up @@ -276,13 +316,7 @@ func constructRuntimeConfig(cfg DataplaneConfigFlags, extraArgs []string) (*cons
InsecureSkipVerify: boolVal(cfg.Consul.TLS.InsecureSkipVerify),
},
},
Service: &consuldp.ServiceConfig{
NodeName: stringVal(cfg.Service.NodeName),
NodeID: stringVal(cfg.Service.NodeID),
ServiceID: stringVal(cfg.Service.ServiceID),
Namespace: stringVal(cfg.Service.Namespace),
Partition: stringVal(cfg.Service.Partition),
},
Proxy: &proxyCfg,
Logging: &consuldp.LoggingConfig{
Name: DefaultLogName,
LogJSON: boolVal(cfg.Logging.LogJSON),
Expand Down
Loading