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

FieldManager add namespace for Aeraki #338

Closed
wants to merge 1 commit into from
Closed
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
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.DefaultAerakiEnableEnvoyFilterNsScope,
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: 2 additions & 2 deletions pkg/bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ func createSingletonControllers(args *AerakiArgs, kubeConfig *rest.Config) (mana
if err != nil {
return nil, err
}
err = kube.AddServiceEntryController(mgr)
err = kube.AddServiceEntryController(mgr, args.RootNamespace)
if err != nil {
aerakiLog.Fatalf("could not add ServiceEntryController: %e", err)
}
err = kube.AddNamespaceController(mgr, args.AerakiXdsAddr, args.AerakiXdsPort)
err = kube.AddNamespaceController(mgr, args.RootNamespace, args.AerakiXdsAddr, args.AerakiXdsPort)
if err != nil {
aerakiLog.Fatalf("could not add NamespaceController: %e", err)
}
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"
// DefaultAerakiEnableEnvoyFilterNsScope 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
DefaultAerakiEnableEnvoyFilterNsScope = "AERAKI_ENABLE_ENVOY_FILTER_NS_SCOPE"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just AerakiEnableEnvoyFilterNsScope as it's an Env name, not a default value.

)
16 changes: 9 additions & 7 deletions pkg/controller/kube/namesapce.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ var (
// namespaceController creates bootstrap configMap for sidecar proxies
type namespaceController struct {
controllerclient.Client
AerakiAddr string
AerakiPort string
rootNamespace string
AerakiAddr string
AerakiPort string
}

// Reconcile watch namespace change and create bootstrap configmap for sidecar proxies
Expand All @@ -75,11 +76,12 @@ func (c *namespaceController) Reconcile(ctx context.Context, request reconcile.R
}

// AddNamespaceController adds namespaceController
func AddNamespaceController(mgr manager.Manager, aerakiAddr, aerakiPort string) error {
func AddNamespaceController(mgr manager.Manager, rootNamespace, aerakiAddr, aerakiPort string) error {
namespaceCtrl := &namespaceController{
Client: mgr.GetClient(),
AerakiAddr: aerakiAddr,
AerakiPort: aerakiPort,
Client: mgr.GetClient(),
rootNamespace: rootNamespace,
AerakiAddr: aerakiAddr,
AerakiPort: aerakiPort,
}
c, err := controller.New("aeraki-namespace-controller", mgr,
controller.Options{Reconciler: namespaceCtrl})
Expand All @@ -105,7 +107,7 @@ func (c *namespaceController) createBootstrapConfigMap(ns string) {
"custom_bootstrap.json": GetBootstrapConfig(c.AerakiAddr, c.AerakiPort),
}
if err := c.Client.Create(context.TODO(), cm, &controllerclient.CreateOptions{
FieldManager: constants.AerakiFieldManager,
FieldManager: constants.AerakiFieldManager + "-" + c.rootNamespace,
Copy link
Member

@zhaohuabing zhaohuabing Apr 23, 2023

Choose a reason for hiding this comment

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

There're two problems here:

  • The change of FieldManager will break existing Aeraki deployment since old resources were created with “constants.AerakiFieldManager", the change should be back compatible
  • I prefer geting FiledManager value from a central place rather than passing rootNamespace around everywhere

}); err != nil {
if !errors.IsAlreadyExists(err) {
namespaceLog.Errorf("failed to create configMap: %v", err)
Expand Down
14 changes: 8 additions & 6 deletions pkg/controller/kube/serviceentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ var (
// serviceEntryController allocate VIPs to service entries
type serviceEntryController struct {
controllerclient.Client
serviceIPs map[string]controllerclient.ObjectKey
maxIP int
serviceIPs map[string]controllerclient.ObjectKey
maxIP int
rootNamespace string
}

// Reconcile will try to trigger once mcp push.
Expand All @@ -94,10 +95,11 @@ func (c *serviceEntryController) Reconcile(ctx context.Context, request reconcil
}

// AddServiceEntryController adds serviceEntryController
func AddServiceEntryController(mgr manager.Manager) error {
func AddServiceEntryController(mgr manager.Manager, rootNamespace string) error {
serviceEntryCtrl := &serviceEntryController{
Client: mgr.GetClient(),
serviceIPs: make(map[string]controllerclient.ObjectKey),
Client: mgr.GetClient(),
serviceIPs: make(map[string]controllerclient.ObjectKey),
rootNamespace: rootNamespace,
}
c, err := controller.New("aeraki-service-entry-controller", mgr,
controller.Options{Reconciler: serviceEntryCtrl})
Expand Down Expand Up @@ -158,7 +160,7 @@ func (c *serviceEntryController) autoAllocateIP(key controllerclient.ObjectKey,
func (c *serviceEntryController) updateServiceEntry(s *networking.ServiceEntry, key controllerclient.ObjectKey) {
err := c.Client.Update(context.TODO(), s,
&controllerclient.UpdateOptions{
FieldManager: constants.AerakiFieldManager,
FieldManager: constants.AerakiFieldManager + "-" + c.rootNamespace,
})
if err == nil {
c.serviceIPs[s.Spec.Addresses[0]] = key
Expand Down
14 changes: 6 additions & 8 deletions pkg/envoyfilter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ 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,
})
existingEnvoyFilters, _ := c.istioClientset.NetworkingV1alpha3().EnvoyFilters("").List(context.TODO(),
v1.ListOptions{LabelSelector: "manager=" + constants.AerakiFieldManager + "-" + c.namespace})

// Deleted envoyFilters
for i := range existingEnvoyFilters.Items {
Expand All @@ -157,7 +156,7 @@ func (c *Controller) pushEnvoyFilters2APIServer() error {
newEnvoyFilter.Name, model.Struct2JSON(*newEnvoyFilter.Envoyfilter))
_, err = c.istioClientset.NetworkingV1alpha3().EnvoyFilters(newEnvoyFilter.Namespace).Update(context.TODO(),
c.toEnvoyFilterCRD(newEnvoyFilter, oldEnvoyFilter),
v1.UpdateOptions{FieldManager: constants.AerakiFieldManager})
v1.UpdateOptions{FieldManager: constants.AerakiFieldManager + "-" + c.namespace})
} else {
controllerLog.Infof("envoyFilter: namespace: %s name: %s unchanged", oldEnvoyFilter.Namespace,
oldEnvoyFilter.Name)
Expand All @@ -171,9 +170,8 @@ func (c *Controller) pushEnvoyFilters2APIServer() error {
controllerLog.Infof("creating EnvoyFilter: namespace: %s name: %s %v", wrapper.Namespace, wrapper.Name,
model.Struct2JSON(wrapper.Envoyfilter))
_, err = c.istioClientset.NetworkingV1alpha3().EnvoyFilters(wrapper.Namespace).Create(context.TODO(),
c.toEnvoyFilterCRD(wrapper,
nil),
v1.CreateOptions{FieldManager: constants.AerakiFieldManager})
c.toEnvoyFilterCRD(wrapper, nil),
v1.CreateOptions{FieldManager: constants.AerakiFieldManager + "-" + c.namespace})
}
return err
}
Expand All @@ -185,7 +183,7 @@ func (c *Controller) toEnvoyFilterCRD(newEf *model.EnvoyFilterWrapper,
Name: newEf.Name,
Namespace: newEf.Namespace,
Labels: map[string]string{
"manager": constants.AerakiFieldManager,
"manager": constants.AerakiFieldManager + "-" + c.namespace,
},
},
Spec: *newEf.Envoyfilter,
Expand Down