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

Normalize all API Gateway references #16316

Merged
merged 1 commit into from
Feb 17, 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
24 changes: 20 additions & 4 deletions agent/structs/config_entry_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ func (e *APIGatewayConfigEntry) Normalize() error {
if cert.Kind == "" {
cert.Kind = InlineCertificate
}
cert.EnterpriseMeta.Normalize()

listener.TLS.Certificates[i] = cert
}
}
Expand Down Expand Up @@ -972,7 +974,23 @@ func (e *BoundAPIGatewayConfigEntry) IsInitializedForGateway(gateway *APIGateway
func (e *BoundAPIGatewayConfigEntry) GetKind() string { return BoundAPIGateway }
func (e *BoundAPIGatewayConfigEntry) GetName() string { return e.Name }
func (e *BoundAPIGatewayConfigEntry) GetMeta() map[string]string { return e.Meta }
func (e *BoundAPIGatewayConfigEntry) Normalize() error { return nil }
func (e *BoundAPIGatewayConfigEntry) Normalize() error {
for i, listener := range e.Listeners {
for j, route := range listener.Routes {
route.EnterpriseMeta.Normalize()

listener.Routes[j] = route
}
for j, cert := range listener.Certificates {
cert.EnterpriseMeta.Normalize()

listener.Certificates[j] = cert
}

e.Listeners[i] = listener
}
return nil
}

func (e *BoundAPIGatewayConfigEntry) Validate() error {
allowedCertificateKinds := map[string]bool{
Expand Down Expand Up @@ -1109,8 +1127,6 @@ func (l *BoundAPIGatewayListener) UnbindRoute(route ResourceReference) bool {
return false
}

func (e *BoundAPIGatewayConfigEntry) GetStatus() Status {
return Status{}
}
func (e *BoundAPIGatewayConfigEntry) GetStatus() Status { return Status{} }
func (e *BoundAPIGatewayConfigEntry) SetStatus(status Status) {}
func (e *BoundAPIGatewayConfigEntry) DefaultStatus() Status { return Status{} }
18 changes: 18 additions & 0 deletions agent/structs/config_entry_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (e *HTTPRouteConfigEntry) Normalize() error {
for i, parent := range e.Parents {
if parent.Kind == "" {
parent.Kind = APIGateway
parent.EnterpriseMeta.Normalize()
e.Parents[i] = parent
}
}
Expand All @@ -87,12 +88,22 @@ func (e *HTTPRouteConfigEntry) Normalize() error {
for j, match := range rule.Matches {
rule.Matches[j] = normalizeHTTPMatch(match)
}

for j, service := range rule.Services {
rule.Services[j] = normalizeHTTPService(service)
}
e.Rules[i] = rule
}

return nil
}

func normalizeHTTPService(service HTTPService) HTTPService {
service.EnterpriseMeta.Normalize()

return service
}
Comment on lines +101 to +105
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason this follows a different pattern than everywhere else? Aside from that nit, LGTM assuming that EnterpriseMeta.Normalize() mutates the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does mutate the struct -- verified it and double checked that normalize takes a pointer receiver 😅.

I just did this pattern since this is how the rest of the HTTPRoute normalization/validation code is done since there are substantially more subsections to cover than the other resources.


func normalizeHTTPMatch(match HTTPMatch) HTTPMatch {
method := string(match.Method)
method = strings.ToUpper(method)
Expand Down Expand Up @@ -494,9 +505,16 @@ func (e *TCPRouteConfigEntry) Normalize() error {
for i, parent := range e.Parents {
if parent.Kind == "" {
parent.Kind = APIGateway
parent.EnterpriseMeta.Normalize()
e.Parents[i] = parent
}
}

for i, service := range e.Services {
service.EnterpriseMeta.Normalize()
e.Services[i] = service
}

return nil
}

Expand Down