This hoists the K8s Service reconciliation and makes it level-based.#1328
This hoists the K8s Service reconciliation and makes it level-based.#1328google-prow-robot merged 1 commit intoknative:masterfrom
Conversation
2403d28 to
5fda32c
Compare
🎉 |
This is the next phase of our level-based migration of the Revision controller. It includes the K8s Service for the user Deployment. This is patterned in much the same way as the Deployment refactor in #1322. The most notable difference in this change is that we establish readiness from the Endpoints resource instead of the Service resource directly. In addition, I spent a bit of time cleaning up some of the `revision_test.go` code to more automatically update the informers as resources are reconciled. In particular, after `controller.Reconcile` we need to make sure all of the updates to the underlying objects are reflected in our informers, or a subsequent reconcile may act on stale state. To facilitate this, I added a helper that updates the informers with the Revision/Deployment/Service to be used after a `controller.Reconcile`.
|
The following is the coverage report on pkg/. Say
*TestCoverage feature is being tested, do not rely on any info here yet |
| configuration.NewController(opt, configurationInformer, revisionInformer, cfg), | ||
| revision.NewController(opt, vpaClient, revisionInformer, buildInformer, configMapInformer, | ||
| deploymentInformer, endpointsInformer, vpaInformer, cfg, &revControllerConfig), | ||
| deploymentInformer, coreServiceInformer, endpointsInformer, vpaInformer, |
There was a problem hiding this comment.
The more Informers I see being added, the more I like passing in the map of them so each and every NewController method doesn't need to change when one of them needs something ;)
There was a problem hiding this comment.
benefit of this style
- type safety
- plus it makes dependencies explicit
| return c.KubeClientSet.CoreV1().Services(ns).Create(service) | ||
| } | ||
|
|
||
| func (c *Controller) checkAndUpdateService(ctx context.Context, rev *v1alpha1.Revision, service *corev1.Service) (*corev1.Service, bool, error) { |
There was a problem hiding this comment.
nit, but it might be good to document what the bool here is. I think it means if it an update was attempted or not?
There was a problem hiding this comment.
Use an enum - self documenting
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mattmoor, vaikas-google The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
| configuration.NewController(opt, configurationInformer, revisionInformer, cfg), | ||
| revision.NewController(opt, vpaClient, revisionInformer, buildInformer, configMapInformer, | ||
| deploymentInformer, endpointsInformer, vpaInformer, cfg, &revControllerConfig), | ||
| deploymentInformer, coreServiceInformer, endpointsInformer, vpaInformer, |
There was a problem hiding this comment.
benefit of this style
- type safety
- plus it makes dependencies explicit
| @@ -218,12 +224,8 @@ func NewController( | |||
| }) | |||
|
|
|||
| endpointsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | |||
There was a problem hiding this comment.
I'm guessing the owner of the endpoints is the service - hence no filtering on the revision as an owner?
Does the Filter support label keys?
There was a problem hiding this comment.
The filter is just a function, so we could potentially generalize this to something like our Controller kind filter that takes a label key. WDYT?
| // should not allow, or if our expectations of how the service should look | ||
| // changes (e.g. we update our controller with new sidecars). | ||
| var updated bool | ||
| service, updated, err = c.checkAndUpdateService(ctx, rev, service) |
There was a problem hiding this comment.
I'm guessing there are is no defaulting involved with the service hence why it's safe to perform checkAndUpdateService?
There was a problem hiding this comment.
I haven't seen the dueling controllers that I saw with Deployment, but if this becomes a problem we can relax it as well (until we find a better way of achieving this that works for both).
| return c.KubeClientSet.CoreV1().Services(ns).Create(service) | ||
| } | ||
|
|
||
| func (c *Controller) checkAndUpdateService(ctx context.Context, rev *v1alpha1.Revision, service *corev1.Service) (*corev1.Service, bool, error) { |
There was a problem hiding this comment.
Use an enum - self documenting
This is the next phase of our level-based migration of the Revision controller. It includes the K8s Service for the user Deployment. This is patterned in much the same way as the Deployment refactor in #1322. The most notable difference in this change is that we establish readiness from the Endpoints resource instead of the Service resource directly.
In addition, I spent a bit of time cleaning up some of the
revision_test.gocode to more automatically update the informers as resources are reconciled. In particular, aftercontroller.Reconcilewe need to make sure all of the updates to the underlying objects are reflected in our informers, or a subsequent reconcile may act on stale state. To facilitate this, I added a helper that updates the informers with the Revision/Deployment/Service to be used after acontroller.Reconcile.