Skip to content

Commit

Permalink
optimize code for AERAKI_ENABLE_ENVOY_FILTER_NS_SCOPE for aeraki
Browse files Browse the repository at this point in the history
Signed-off-by: chentanjun <tanjunchen20@gmail.com>
  • Loading branch information
tanjunchen committed Apr 19, 2023
1 parent d5d0afc commit 9786e2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/aeraki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {

args.PodName = env.RegisterStringVar("POD_NAME", args.ServerID, "").Get()
args.RootNamespace = env.RegisterStringVar("AERAKI_NAMESPACE", args.RootNamespace, "").Get()
args.EnableEnvoyFilterNSScope = env.RegisterBoolVar("AERAKI_ENABLE_ENVOY_FILTER_NS_SCOPE",
args.EnableEnvoyFilterNSScope = env.RegisterBoolVar(constants.DefaultAerakiEnableEnvoyFilterNsScopeName,
args.EnableEnvoyFilterNSScope, "").Get()
args.IstiodAddr = env.RegisterStringVar("AERAKI_ISTIOD_ADDR", args.IstiodAddr, "").Get()
args.AerakiXdsAddr = env.RegisterStringVar("AERAKI_XDS_ADDR", constants.DefaultAerakiXdsAddr, "").Get()
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ const (
DefaultAerakiXdsPort = ":15010"
// DefaultAerakiXdsAddr is the default value for Aeraki xds address
DefaultAerakiXdsAddr = "aeraki.istio-system"
// DefaultAerakiEnableEnvoyFilterNsScopeName is the name for Aeraki to place envoyFilters scope
// False(Default): The generated envoyFilters will be placed under Istio root namespace
// True: The generated envoyFilters will be placed under the service namespace
DefaultAerakiEnableEnvoyFilterNsScopeName = "AERAKI_ENABLE_ENVOY_FILTER_NS_SCOPE"
)
11 changes: 8 additions & 3 deletions pkg/envoyfilter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ func (c *Controller) pushEnvoyFilters2APIServer() error {
return fmt.Errorf("failed to generate EnvoyFilter: %v", err)
}

existingEnvoyFilters, _ := c.istioClientset.NetworkingV1alpha3().EnvoyFilters("").List(context.TODO(), v1.ListOptions{
LabelSelector: "manager=" + constants.AerakiFieldManager,
})
listNamespace := ""
if c.namespaceScoped {
listNamespace = c.namespace
controllerLog.Infof("listing EnvoyFilter from namespace=%s due to %s=true",
listNamespace, constants.DefaultAerakiEnableEnvoyFilterNsScopeName)
}
existingEnvoyFilters, _ := c.istioClientset.NetworkingV1alpha3().EnvoyFilters(listNamespace).List(context.TODO(),
v1.ListOptions{LabelSelector: "manager=" + constants.AerakiFieldManager})

// Deleted envoyFilters
for i := range existingEnvoyFilters.Items {
Expand Down

0 comments on commit 9786e2f

Please sign in to comment.