-
Notifications
You must be signed in to change notification settings - Fork 21
Upgrade to controller-runtime 0.8.3 #9
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
Changes from all commits
f5667b9
1ea3940
f7f2e38
a3b2d62
5260912
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ import ( | |
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| cmutil "github.com/jetstack/cert-manager/pkg/api/util" | ||
| cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1" | ||
| cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1" | ||
|
|
@@ -48,7 +47,6 @@ var ( | |
| // CertificateRequestReconciler reconciles a CertificateRequest object | ||
| type CertificateRequestReconciler struct { | ||
| client.Client | ||
| Log logr.Logger | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. controller-runtime now sets up a logger for each controller and gives it a name based on the |
||
| Scheme *runtime.Scheme | ||
| SignerBuilder signer.SignerBuilder | ||
| ClusterResourceNamespace string | ||
|
|
@@ -58,9 +56,8 @@ type CertificateRequestReconciler struct { | |
| // +kubebuilder:rbac:groups=cert-manager.io,resources=certificaterequests/status,verbs=get;update;patch | ||
| // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch | ||
|
|
||
| func (r *CertificateRequestReconciler) Reconcile(req ctrl.Request) (result ctrl.Result, err error) { | ||
| ctx := context.Background() | ||
| log := r.Log.WithValues("certificaterequest", req.NamespacedName) | ||
| func (r *CertificateRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| log := ctrl.LoggerFrom(ctx) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. controller-runtime now sets up a logger for each controller and gives it a name based on the Kind of resource that it being reconciled. See kubernetes-sigs/controller-runtime#1203 |
||
|
|
||
| // Get the CertificateRequest | ||
| var certificateRequest cmapi.CertificateRequest | ||
|
|
@@ -119,14 +116,14 @@ func (r *CertificateRequestReconciler) Reconcile(req ctrl.Request) (result ctrl. | |
|
|
||
| // Ignore but log an error if the issuerRef.Kind is unrecognised | ||
| issuerGVK := sampleissuerapi.GroupVersion.WithKind(certificateRequest.Spec.IssuerRef.Kind) | ||
| issuer, err := r.Scheme.New(issuerGVK) | ||
| issuerRO, err := r.Scheme.New(issuerGVK) | ||
| if err != nil { | ||
| err = fmt.Errorf("%w: %v", errIssuerRef, err) | ||
| log.Error(err, "Unrecognised kind. Ignoring.") | ||
| setReadyCondition(cmmeta.ConditionFalse, cmapi.CertificateRequestReasonFailed, err.Error()) | ||
| return ctrl.Result{}, nil | ||
| } | ||
|
|
||
| issuer := issuerRO.(client.Object) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Case a |
||
| // Create a Namespaced name for Issuer and a non-Namespaced name for ClusterIssuer | ||
| issuerName := types.NamespacedName{ | ||
| Name: certificateRequest.Spec.IssuerRef.Name, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ func (o *fakeSigner) Sign([]byte) ([]byte, error) { | |
| func TestCertificateRequestReconcile(t *testing.T) { | ||
| type testCase struct { | ||
| name types.NamespacedName | ||
| objects []runtime.Object | ||
| objects []client.Object | ||
| signerBuilder signer.SignerBuilder | ||
| clusterResourceNamespace string | ||
| expectedResult ctrl.Result | ||
|
|
@@ -49,7 +49,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| tests := map[string]testCase{ | ||
| "success-issuer": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -96,7 +96,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "success-cluster-issuer": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -146,7 +146,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "issuer-ref-foreign-group": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -159,7 +159,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "certificaterequest-already-ready": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -177,7 +177,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "certificaterequest-missing-ready-condition": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -193,7 +193,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "issuer-ref-unknown-kind": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -213,7 +213,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "issuer-not-found": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -234,7 +234,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "clusterissuer-not-found": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -255,7 +255,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "issuer-not-ready": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -290,7 +290,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "issuer-secret-not-found": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -328,7 +328,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "signer-builder-error": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -375,7 +375,7 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
| }, | ||
| "signer-error": { | ||
| name: types.NamespacedName{Namespace: "ns1", Name: "cr1"}, | ||
| objects: []runtime.Object{ | ||
| objects: []client.Object{ | ||
| cmgen.CertificateRequest( | ||
| "cr1", | ||
| cmgen.SetCertificateRequestNamespace("ns1"), | ||
|
|
@@ -429,15 +429,20 @@ func TestCertificateRequestReconcile(t *testing.T) { | |
|
|
||
| for name, tc := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| fakeClient := fake.NewFakeClientWithScheme(scheme, tc.objects...) | ||
| fakeClient := fake.NewClientBuilder(). | ||
| WithScheme(scheme). | ||
| WithObjects(tc.objects...). | ||
| Build() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| controller := CertificateRequestReconciler{ | ||
| Client: fakeClient, | ||
| Log: logrtesting.TestLogger{T: t}, | ||
| Scheme: scheme, | ||
| ClusterResourceNamespace: tc.clusterResourceNamespace, | ||
| SignerBuilder: tc.signerBuilder, | ||
| } | ||
| result, err := controller.Reconcile(reconcile.Request{NamespacedName: tc.name}) | ||
| result, err := controller.Reconcile( | ||
| ctrl.LoggerInto(context.TODO(), &logrtesting.TestLogger{T: t}), | ||
| reconcile.Request{NamespacedName: tc.name}, | ||
| ) | ||
| if tc.expectedError != nil { | ||
| assertErrorIs(t, tc.expectedError, err) | ||
| } else { | ||
|
|
||
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.
See https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.7.0 and kubernetes-sigs/controller-runtime#1144