-
Notifications
You must be signed in to change notification settings - Fork 420
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
Refactor flags to improve unit tests #876
Conversation
Hi @MarcelMue. Thanks for your PR. I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
@dibyom Can you check if the direction here is okay? I tried to orient myself a bit towards tektoncd/pipelines - but need to clean up + write new tests still. |
/ok-to-test |
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.
Thanks @MarcelMue This looks much cleaner (and testable) than before.
I have a couple of minor comments and looks like some changes need to be made in test/ to fix the build. Otherwise LGTM!
@@ -111,8 +74,8 @@ type Reconciler struct { | |||
eventListenerLister listers.EventListenerLister | |||
serviceLister corev1lister.ServiceLister | |||
|
|||
// systemNamespace is the namespace where the reconciler is deployed | |||
systemNamespace string | |||
// config is the configuration passed in through flags. |
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.
very minor: config is the configuration options that the Reconciler accepts.
(We could decide to pass these in via configMaps ore something else in the future)
@@ -396,7 +359,7 @@ func (r *Reconciler) reconcileDeployment(ctx context.Context, logger *zap.Sugare | |||
return nil | |||
} | |||
|
|||
func getDeployment(el *v1alpha1.EventListener) *appsv1.Deployment { | |||
func (r *Reconciler) getDeployment(el *v1alpha1.EventListener) *appsv1.Deployment { |
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.
If we make this getDeployment(el *v1alpha1.EventListener, config Config)
the dependency on the Config
is clearer and the function is a bit easier to test (we don't have to setup an entire reconciler struct)
@@ -483,7 +446,7 @@ func getDeployment(el *v1alpha1.EventListener) *appsv1.Deployment { | |||
} | |||
} | |||
|
|||
func getContainer(el *v1alpha1.EventListener) corev1.Container { | |||
func (r *Reconciler) getContainer(el *v1alpha1.EventListener) corev1.Container { |
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.
Same as above, I think its a bit clearer to pass in the Config struct as a Param
One other small thing wold be a more descriptive commit message (something like Pass a Config struct to reconciler instead of directly using flags or something. |
@@ -995,12 +1027,29 @@ func TestReconcile(t *testing.T) { | |||
Services: []*corev1.Service{elService}, | |||
ConfigMaps: []*corev1.ConfigMap{loggingConfigMap}, | |||
}, | |||
}, { | |||
name: "eventlistener with SetSecurityContext false", |
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.
I added this unit test. It is now possible to set a config for each test, ensuring that flags are honored properly.
d97b3ab
to
332cf78
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dibyom The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
This PR refactors the usage of flags for the controller. It now utilizes a config struct which offers multiple benefits, such as easier testing of flag values and more independence between unit tests.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Release Notes