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

nephio-controller-manager initial start #91

Closed
1 of 2 tasks
johnbelamaric opened this issue Apr 4, 2023 · 29 comments
Closed
1 of 2 tasks

nephio-controller-manager initial start #91

johnbelamaric opened this issue Apr 4, 2023 · 29 comments
Assignees
Labels
area/package-management SIG Automation Package Management Subproject sig/automation
Milestone

Comments

@johnbelamaric
Copy link
Member

johnbelamaric commented Apr 4, 2023

Create the controller manager for the following Nephio components on management cluster and create a single binary

  • Specializers (IPAM, VLAN)
  • NF Topology
  • Status Aggregator

Tasks for this issue are

  • Crete a design proposal with a digram explaning the purpose and components of the nephio-controller-manager
  • Implement the nephio-controller-manager

Document and create the initial binary
Unit test coverage.

@johnbelamaric johnbelamaric added this to the sprint1 milestone Apr 4, 2023
@johnbelamaric johnbelamaric moved this to In Progress in Nephio R1 Apr 4, 2023
@johnbelamaric
Copy link
Member Author

/label area/package-management
/label sig/automation

@nephio-prow
Copy link
Contributor

nephio-prow bot commented Apr 4, 2023

@johnbelamaric: The label(s) /label area/package-management , /label sig/automation cannot be applied. These labels are supported: ``. Is this label configured under labels -> additional_labels or `labels -> restricted_labels` in `plugin.yaml`?

In response to this:

/label area/package-management
/label sig/automation

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@johnbelamaric
Copy link
Member Author

@radoslawc see above ^

@johnbelamaric johnbelamaric added area/package-management SIG Automation Package Management Subproject sig/automation labels Apr 4, 2023
@johnbelamaric
Copy link
Member Author

/area package-managment
/sig automation

trying these prow commands...

@nephio-prow
Copy link
Contributor

nephio-prow bot commented Apr 4, 2023

@johnbelamaric: The label(s) area/package-managment cannot be applied, because the repository doesn't have them.

In response to this:

/area package-managment
/sig automation

trying these prow commands...

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@johnbelamaric
Copy link
Member Author

/area package-management

helps if I can spell correctly

@johnbelamaric
Copy link
Member Author

Nice, that worked :)

@johnbelamaric
Copy link
Member Author

@ssharmasandeep We would want a one-pager design/diagram explaining what this is and what it contains, along with code to build the actual binary - the specific reconcilers are mostly not-yet-available, although the IPAM specializer should be.

See the kubernetes-controller-manager and porch-controllers binaries for examples of similar things in other projects.

@gvbalaji gvbalaji modified the milestones: sprint1, sprint2 Apr 11, 2023
@gvbalaji gvbalaji modified the milestones: sprint2, sprint3 Apr 25, 2023
@ssharmasandeep
Copy link
Contributor

ssharmasandeep commented Apr 25, 2023

@johnbelamaric please review. I have started to put together the following with https://github.com/nephio-project/edge-status-aggregator to start with.

The content of the nephio-controller-manager will be,

  • main.go: The main package will declare an interface called Reconciler, which will have the method SetupWithManager along with other methods like InitDefaults, and BindFlags.
  • controllers: These will be the NF topology, Specialisers and Status aggregator controllers. Each controller will implement the Reconcilers interface.
  • Dockerfile: To create a docker image of the nephio-controller-manager. It will build a single binary For example go build -o nephio-controller-manager -v .
  • Makefile:

Purpose of this controller: The purpose of this controller is to create a single binary for all the nephio management controllers.

Implementation Flow:

  • main.go will import all the controller packages that will be part of the controller-manager.
  • The package main will define an interface which will be implemented by all the controllers part of it.
  • A map will be created in the package main, which will have controller name to controller's Reconciler mapping.
  • Example var ( reconcilers = map[string]Reconciler{ "nfdeploy": &nfdeploy.NfDeployReconciler{}, } )
  • The logic in package main will basically allocate controllerruntime NewManager with manager options.
  • Then the logic will loop over each controller Reconciler interface and call the SetupWIthManager for each controller.

Each Controller will implement the SetupWIthManager

  • Add GV to the scheme of manager created in package main.
  • Allocate a controllerruntime NewControllerManagedBy(mgr) for the controller, manager by the main manager.
  • This just describes the interface of each controller, on how it integrates with the main manager.

The implementation plan is to create the main framework, and then add each controller to it by implementing the Reconciler interface.

Started creating the framework with https://github.com/nephio-project/edge-status-aggregator to start with, once it is working then adding the rest of the controller will be a repeat of this for each controller.

In the last meeting you had asked me to put the doc in some repo, I will do it if this looks fine or after addressing your review comments.

@johnbelamaric
Copy link
Member Author

This looks good to me, I don't think we need a doc beyond this.

@gvbalaji
Copy link

Thanks @ssharmasandeep . This is a good readme for the manager when we merge .

@henderiw
Copy link
Contributor

yes looks good.

Here is some code I use to setup various controllers within a given manager, if it is useful. It even uses generic Events, but I don't believe we need it here.

// Setup package controllers.
func Setup(ctx context.Context, mgr ctrl.Manager, opts *shared.Options) error {
ipamproxyClient := clientproxy.New(ctx, &clientproxy.Config{
Registrator: opts.Registrator,
})
opts.IpamClientProxy = ipamproxyClient

eventChs := map[schema.GroupVersionKind]chan event.GenericEvent{}
for _, setup := range []func(ctrl.Manager, *shared.Options) (schema.GroupVersionKind, chan event.GenericEvent, error){
	networkinstance.Setup,
	prefix.Setup,
	allocation.Setup,
} {
	gvk, geCh, err := setup(mgr, opts)
	if err != nil {
		return err
	}
	eventChs[gvk] = geCh
}
for _, setup := range []func(ctrl.Manager, *shared.Options) error{
	injector.Setup,
} {
	if err := setup(mgr, opts); err != nil {
		return err
	}
}

ipamproxyClient.AddEventChs(eventChs)

return nil

}

This is the injector which will become specialised:

// SetupWithManager sets up the controller with the Manager.
func Setup(mgr ctrl.Manager, options *shared.Options) error {
ge := make(chan event.GenericEvent)
r := &reconciler{
kind: "ipam",
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
porchClient: options.PorchClient,
IpamClientProxy: options.IpamClientProxy,

	pollInterval: options.Poll,
	finalizer:    resource.NewAPIFinalizer(mgr.GetClient(), finalizer),
}

return ctrl.NewControllerManagedBy(mgr).
	For(&porchv1alpha1.PackageRevision{}).
	Watches(&source.Channel{Source: ge}, &handler.EnqueueRequestForObject{}).
	Complete(r)

}

@johnbelamaric
Copy link
Member Author

Any update here, @ssharmasandeep ?

@ssharmasandeep
Copy link
Contributor

@johnbelamaric I started to code the framework with https://github.com/nephio-project/edge-status-aggregator , but there is no tangible status as of now. I will try my best to create a PR this week.

@gvbalaji gvbalaji modified the milestones: sprint3, sprint4 May 9, 2023
@ssharmasandeep
Copy link
Contributor

@henderiw Please point me to the controllers which we have to include in the controller manager. I have the framework ready, which I tested with the nephio-poc controller.
I tried to look it up in nephio-project but was not able to find the controllers.
Also, I need to understand the configmap requirement you mentioned in last week's call. Let's catch up after the call today ?
-Sandeep

@henderiw
Copy link
Contributor

henderiw commented May 9, 2023

#177
provides an operator for the specializers only. This also provides a mechanism to add multiple controllers as I shared before.

@ssharmasandeep
Copy link
Contributor

I have added the specializers to the controller manager as per the flow that was sent earlier to this ticket.
@henderiw the logic is similar to what you suggested above, but I had to move around a little code in order to integrate the specialzers. I will raise the PR once I know the location to checkin this code ( by tomorrow), for now please look at https://github.com/ssharmasandeep/nephio-controller-manager.git and let me know if the changes done to specializers look ok ?

@johnbelamaric

  1. Where should this operator be checked in? Or are we going to make the current nephio repo as this manager?
  2. I will add the Dockerfile/Makefile and raise PR by tomorrow, after unit testing.
  3. Please confirm the following list is all we need,
    specializer controller ( this is added)
    edge-status-aggregator (this is added)
    repo-controller
    bootstrap-controller

ignore the nephio-poc-controller, it will not be part of the PR.

-Sandeep

@henderiw
Copy link
Contributor

henderiw commented May 10, 2023 via email

@johnbelamaric
Copy link
Member Author

  • Where should this operator be checked in? Or are we going to make the current nephio repo as this manager?

I was thinking a nephio-controller-manager directory (and go.mod) in the nephio repo.

@johnbelamaric
Copy link
Member Author

Vish noted this the other day, perhaps we should take some inspiration from it: https://github.com/golang-standards/project-layout

So may something like:

nephio/
  cmd/
    pkg/
      go.mod
    nephio-controller-manager/
      go.mod
    another-binary/
      go.mod
  controllers
    pkg/
      go.mod
    controller-a
      go.mod
    controller-b
      go.mod
    specializer-a
      go.mod
  krm-functions/
    pkg/ (probably should rename lib this, but not urgent, could be post R1)
      go.mod
    function-a
      go.mod
    function-b
      go.mod

@henderiw
Copy link
Contributor

is it not better to make an operators directory if we decide to have multiple operators at some point.

nephio/
operators
controllers
krm-functions

@johnbelamaric
Copy link
Member Author

The cmd directory usually is used for building binaries. But if we want to put "operator" binaries in operators instead, I am good with that.

@henderiw
Copy link
Contributor

yes I know but I would like to have the ability to create multiple operators and within the operator we could have a local structure.

@henderiw
Copy link
Contributor

some comments on the remote code

  • do we believe global var is a good practice?
  • the ctx I would from the mgr as he is the owner of the ctx.
  • Is it not better to have a setup method that does the specifics for each controller and attach them to the manager and that's it.

@ssharmasandeep
Copy link
Contributor

ssharmasandeep commented May 11, 2023

do we believe global var is a good practice?
Sandeep: No, should be avoided.. I will fix it.
the ctx I would from the mgr as he is the owner of the ctx.
Sandeep: agree, will make the required change.
Is it not better to have a setup method that does the specifics for each controller and attach them to the manager and that's it.
Sandeep: That is the intention of the setupwithmanager method implemented by each controller.

@ssharmasandeep
Copy link
Contributor

So looks like we agreed on the following structure.. I will follow this.
nephio/
operators
controllers
krm-functions

@henderiw
Copy link
Contributor

@ssharmasandeep #197 have a look. I added a prototype and I want all the controllers to use it as it eases integration.
it allows controllers to register and enable them independently.

Have a look.

@johnbelamaric
Copy link
Member Author

#208

@johnbelamaric
Copy link
Member Author

merged

@github-project-automation github-project-automation bot moved this from In Progress to Done in Nephio R1 May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/package-management SIG Automation Package Management Subproject sig/automation
Projects
Status: Done
Development

No branches or pull requests

4 participants