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

Auto renew ca certificate #150

Merged
merged 6 commits into from
Oct 20, 2022
Merged

Auto renew ca certificate #150

merged 6 commits into from
Oct 20, 2022

Conversation

roivaz
Copy link
Member

@roivaz roivaz commented Oct 19, 2022

Adds a new event handler in the DiscoveryServiceCertificate controller to trigger a reconcile of any certificate that has its issuer certificate modified. After this, it is safe to enable auto-renewal of the discovery service CA certificate.

/kind feature
/assign
/priority important-longterm

Note for reviewers: #149 needs to be merged first and then I will rebase.

@3scale-robot 3scale-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 19, 2022
@3scale-robot 3scale-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple sprints to complete. label Oct 19, 2022
@3scale-robot 3scale-robot added needs-size Indicates a PR or issue lacks a `size/foo` label and requires one. size/M Requires about a day to complete the PR or the issue. and removed needs-size Indicates a PR or issue lacks a `size/foo` label and requires one. labels Oct 19, 2022
@roivaz
Copy link
Member Author

roivaz commented Oct 19, 2022

closes #22

@roivaz
Copy link
Member Author

roivaz commented Oct 19, 2022

@raelga @slopezz already rebased, can be reviewed

Comment on lines +99 to 143
// IssuerChangedHandler returns an EventHandler that generates
// reconcile requests for Secrets
func (r *DiscoveryServiceCertificateReconciler) IssuerChangedHandler() handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(
func(o client.Object) []reconcile.Request {

issuer := o.(*operatorv1alpha1.DiscoveryServiceCertificate)
// Only interested in changes to CA certificates. A change in the CA
// means that the child certificates need to be re-issued
if !issuer.IsCA() {
return []reconcile.Request{}
}

list := &operatorv1alpha1.DiscoveryServiceCertificateList{}
if err := r.Client.List(context.Background(), list); err != nil {
return []reconcile.Request{}
}

reconcileRequests := []reconcile.Request{}

for _, dsc := range list.Items {
if dsc.Spec.Signer.CASigned != nil &&
dsc.Spec.Signer.CASigned.SecretRef.Name == issuer.Spec.SecretRef.Name {

reconcileRequests = append(reconcileRequests,
reconcile.Request{NamespacedName: types.NamespacedName{
Name: dsc.GetName(),
Namespace: dsc.GetNamespace(),
}})
}
}

return reconcileRequests
},
)
}

// SetupWithManager adds the controller to the manager
func (r *DiscoveryServiceCertificateReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&operatorv1alpha1.DiscoveryServiceCertificate{}).
Owns(&corev1.Secret{}).
Watches(&source.Kind{Type: &operatorv1alpha1.DiscoveryServiceCertificate{}}, r.IssuerChangedHandler()).
Complete(r)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the important part, all other changes are just cleanup

@slopezz
Copy link
Member

slopezz commented Oct 19, 2022

/lgtm

@3scale-robot 3scale-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 19, 2022
@3scale-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 4a148b8628515c0a75fad0196f2dea607bd8be59

Copy link
Contributor

@raelga raelga left a comment

Choose a reason for hiding this comment

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

/lgtm

@roivaz
Copy link
Member Author

roivaz commented Oct 20, 2022

/ok-to-test

@3scale-robot 3scale-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 20, 2022
@roivaz
Copy link
Member Author

roivaz commented Oct 20, 2022

/approve

@3scale-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: roivaz

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@3scale-robot 3scale-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 20, 2022
@3scale-robot 3scale-robot merged commit 2080e90 into main Oct 20, 2022
@3scale-robot 3scale-robot deleted the auto-renew-ca-certificate branch October 20, 2022 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple sprints to complete. size/M Requires about a day to complete the PR or the issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants