-
Notifications
You must be signed in to change notification settings - Fork 337
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(kuma-cp) virtual host modifications #909
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e830db9
feat(kuma-cp) virtual host modifications
jakubdyszkiewicz a2d18c7
Merge remote-tracking branch 'origin/master' into feat/proxy-template…
jakubdyszkiewicz 2fb6d2c
Merge remote-tracking branch 'origin/master' into feat/proxy-template…
jakubdyszkiewicz 25c130d
packages sums
jakubdyszkiewicz 6f89c8b
Merge remote-tracking branch 'origin/master' into feat/proxy-template…
jakubdyszkiewicz 8bfe10c
fix test after service -> kuma.io/service
jakubdyszkiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package modifications | ||
|
||
import ( | ||
envoy_api "github.com/envoyproxy/go-control-plane/envoy/api/v2" | ||
envoy_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route" | ||
envoy_resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2" | ||
"github.com/golang/protobuf/proto" | ||
"github.com/pkg/errors" | ||
|
||
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1" | ||
core_xds "github.com/kumahq/kuma/pkg/core/xds" | ||
util_proto "github.com/kumahq/kuma/pkg/util/proto" | ||
) | ||
|
||
type virtualHostModificator mesh_proto.ProxyTemplate_Modifications_VirtualHost | ||
|
||
func (c *virtualHostModificator) apply(resources *core_xds.ResourceSet) error { | ||
virtualHost := &envoy_route.VirtualHost{} | ||
if err := util_proto.FromYAML([]byte(c.Value), virtualHost); err != nil { | ||
return err | ||
} | ||
|
||
for _, resource := range resources.Resources(envoy_resource.RouteType) { | ||
if c.routeConfigurationMatches(resource) { | ||
routeCfg := resource.Resource.(*envoy_api.RouteConfiguration) | ||
switch c.Operation { | ||
case mesh_proto.OpAdd: | ||
c.add(routeCfg, virtualHost) | ||
case mesh_proto.OpRemove: | ||
c.remove(routeCfg) | ||
case mesh_proto.OpPatch: | ||
c.patch(routeCfg, virtualHost) | ||
default: | ||
return errors.Errorf("invalid operation: %s", c.Operation) | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *virtualHostModificator) patch(routeCfg *envoy_api.RouteConfiguration, vHostPatch *envoy_route.VirtualHost) { | ||
for _, vHost := range routeCfg.VirtualHosts { | ||
if c.virtualHostMatches(vHost) { | ||
proto.Merge(vHost, vHostPatch) | ||
} | ||
} | ||
} | ||
|
||
func (c *virtualHostModificator) remove(routeCfg *envoy_api.RouteConfiguration) { | ||
var vHosts []*envoy_route.VirtualHost | ||
for _, vHost := range routeCfg.VirtualHosts { | ||
if !c.virtualHostMatches(vHost) { | ||
vHosts = append(vHosts, vHost) | ||
} | ||
} | ||
routeCfg.VirtualHosts = vHosts | ||
} | ||
|
||
func (c *virtualHostModificator) add(routeCfg *envoy_api.RouteConfiguration, vHost *envoy_route.VirtualHost) { | ||
routeCfg.VirtualHosts = append(routeCfg.VirtualHosts, vHost) | ||
} | ||
|
||
func (c *virtualHostModificator) virtualHostMatches(vHost *envoy_route.VirtualHost) bool { | ||
if c.Match.GetName() != "" && c.Match.GetName() != vHost.Name { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (c *virtualHostModificator) routeConfigurationMatches(routeCfg *core_xds.Resource) bool { | ||
if c.Match.GetOrigin() != "" && c.Match.GetOrigin() != routeCfg.Origin { | ||
return false | ||
} | ||
if c.Match.GetRouteConfigurationName() != "" && c.Match.GetRouteConfigurationName() != routeCfg.Name { | ||
return false | ||
} | ||
return true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍