Skip to content

Commit cf8510a

Browse files
authored
Merge pull request #109 from inteon/use_issuer_lib
Refactor this issuer to use issuer-lib
2 parents 3cdde74 + 886a24f commit cf8510a

17 files changed

+353
-1007
lines changed
File renamed without changes.

api/v1beta1/googlecasclusterissuer_types.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"github.com/cert-manager/issuer-lib/api/v1alpha1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25-
2624
// +kubebuilder:object:root=true
2725
// +kubebuilder:resource:scope=Cluster
2826
// +kubebuilder:printcolumn:name="ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
@@ -35,9 +33,19 @@ type GoogleCASClusterIssuer struct {
3533
metav1.ObjectMeta `json:"metadata,omitempty"`
3634

3735
Spec GoogleCASIssuerSpec `json:"spec,omitempty"`
38-
Status GoogleCASIssuerStatus `json:"status,omitempty"`
36+
Status v1alpha1.IssuerStatus `json:"status,omitempty"`
37+
}
38+
39+
func (vi *GoogleCASClusterIssuer) GetStatus() *v1alpha1.IssuerStatus {
40+
return &vi.Status
3941
}
4042

43+
func (vi *GoogleCASClusterIssuer) GetIssuerTypeIdentifier() string {
44+
return "googlecasclusterissuers.cas-issuer.jetstack.io"
45+
}
46+
47+
var _ v1alpha1.Issuer = &GoogleCASClusterIssuer{}
48+
4149
// +kubebuilder:object:root=true
4250
// GoogleCASClusterIssuerList contains a list of GoogleCASClusterIssuer
4351
type GoogleCASClusterIssuerList struct {

api/v1beta1/googlecasissuer_types.go

Lines changed: 12 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ package v1beta1
1818

1919
import (
2020
cmmetav1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
21+
"github.com/cert-manager/issuer-lib/api/v1alpha1"
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
)
2324

24-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26-
2725
// GoogleCASIssuerSpec defines the desired state of GoogleCASIssuer
2826
type GoogleCASIssuerSpec struct {
29-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
30-
// Important: Run "make" to regenerate code after modifying this file
31-
3227
// Project is the Google Cloud Project ID
3328
Project string `json:"project,omitempty"`
3429

@@ -54,15 +49,6 @@ type GoogleCASIssuerSpec struct {
5449
CertificateTemplate string `json:"certificateTemplate,omitempty"`
5550
}
5651

57-
// GoogleCASIssuerStatus defines the observed state of GoogleCASIssuer
58-
type GoogleCASIssuerStatus struct {
59-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
60-
// Important: Run "make" to regenerate code after modifying this file
61-
62-
// +optional
63-
Conditions []GoogleCASIssuerCondition `json:"conditions,omitempty"`
64-
}
65-
6652
// +kubebuilder:object:root=true
6753
// +kubebuilder:printcolumn:name="ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
6854
// +kubebuilder:printcolumn:name="reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
@@ -74,9 +60,19 @@ type GoogleCASIssuer struct {
7460
metav1.ObjectMeta `json:"metadata,omitempty"`
7561

7662
Spec GoogleCASIssuerSpec `json:"spec,omitempty"`
77-
Status GoogleCASIssuerStatus `json:"status,omitempty"`
63+
Status v1alpha1.IssuerStatus `json:"status,omitempty"`
64+
}
65+
66+
func (vi *GoogleCASIssuer) GetStatus() *v1alpha1.IssuerStatus {
67+
return &vi.Status
68+
}
69+
70+
func (vi *GoogleCASIssuer) GetIssuerTypeIdentifier() string {
71+
return "googlecasissuers.cas-issuer.jetstack.io"
7872
}
7973

74+
var _ v1alpha1.Issuer = &GoogleCASIssuer{}
75+
8076
// +kubebuilder:object:root=true
8177
// GoogleCASIssuerList contains a list of GoogleCASIssuer
8278
type GoogleCASIssuerList struct {
@@ -85,60 +81,6 @@ type GoogleCASIssuerList struct {
8581
Items []GoogleCASIssuer `json:"items"`
8682
}
8783

88-
// +kubebuilder:validation:Enum=Ready
89-
type GoogleCASIssuerConditionType string
90-
91-
const (
92-
// IssuerConditionReady indicates that a CAS Issuer is ready for use.
93-
// This is defined as:
94-
IssuerConditionReady GoogleCASIssuerConditionType = "Ready"
95-
)
96-
97-
// ConditionStatus represents a condition's status.
98-
// +kubebuilder:validation:Enum=True;False;Unknown
99-
type ConditionStatus string
100-
101-
// These are valid condition statuses. "ConditionTrue" means a resource is in
102-
// the condition; "ConditionFalse" means a resource is not in the condition;
103-
// "ConditionUnknown" means kubernetes can't decide if a resource is in the
104-
// condition or not. In the future, we could add other intermediate
105-
// conditions, e.g. ConditionDegraded.
106-
const (
107-
// ConditionTrue represents the fact that a given condition is true
108-
ConditionTrue ConditionStatus = "True"
109-
110-
// ConditionFalse represents the fact that a given condition is false
111-
ConditionFalse ConditionStatus = "False"
112-
113-
// ConditionUnknown represents the fact that a given condition is unknown
114-
ConditionUnknown ConditionStatus = "Unknown"
115-
)
116-
117-
// IssuerCondition contains condition information for a CAS Issuer.
118-
type GoogleCASIssuerCondition struct {
119-
// Type of the condition, currently ('Ready').
120-
Type GoogleCASIssuerConditionType `json:"type"`
121-
122-
// Status of the condition, one of ('True', 'False', 'Unknown').
123-
// +kubebuilder:validation:Enum=True;False;Unknown
124-
Status ConditionStatus `json:"status"`
125-
126-
// LastTransitionTime is the timestamp corresponding to the last status
127-
// change of this condition.
128-
// +optional
129-
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
130-
131-
// Reason is a brief machine readable explanation for the condition's last
132-
// transition.
133-
// +optional
134-
Reason string `json:"reason,omitempty"`
135-
136-
// Message is a human readable description of the details of the last
137-
// transition, complementing reason.
138-
// +optional
139-
Message string `json:"message,omitempty"`
140-
}
141-
14284
func init() {
14385
SchemeBuilder.Register(&GoogleCASIssuer{}, &GoogleCASIssuerList{})
14486
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 0 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/root.go

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cmd
1818

1919
import (
2020
"flag"
21+
"time"
2122

2223
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
2324
"github.com/spf13/cobra"
@@ -31,8 +32,7 @@ import (
3132
"sigs.k8s.io/controller-runtime/pkg/webhook"
3233

3334
issuersv1beta1 "github.com/jetstack/google-cas-issuer/api/v1beta1"
34-
"github.com/jetstack/google-cas-issuer/pkg/controller/certificaterequest"
35-
"github.com/jetstack/google-cas-issuer/pkg/controller/issuer"
35+
controllers "github.com/jetstack/google-cas-issuer/pkg/controllers"
3636
)
3737

3838
var (
@@ -99,34 +99,12 @@ func root() error {
9999
ctx := ctrl.SetupSignalHandler()
100100

101101
// Start Controllers
102-
if err = (&issuer.GoogleCASIssuerReconciler{
103-
Kind: "GoogleCASIssuer",
104-
Client: mgr.GetClient(),
105-
Log: ctrl.Log.WithName("controller").WithName("GoogleCASIssuer"),
106-
Recorder: mgr.GetEventRecorderFor("cas-issuer-googlecasissuer-controller"),
107-
Scheme: mgr.GetScheme(),
108-
}).SetupWithManager(mgr); err != nil {
102+
if err = (&controllers.GoogleCAS{
103+
MaxRetryDuration: 30 * time.Second,
104+
}).SetupWithManager(ctx, mgr); err != nil {
109105
setupLog.Error(err, "unable to create controller", "controller", "GoogleCASIssuer")
110106
return err
111107
}
112-
if err = (&issuer.GoogleCASIssuerReconciler{
113-
Kind: "GoogleCASClusterIssuer",
114-
Client: mgr.GetClient(),
115-
Log: ctrl.Log.WithName("controller").WithName("GoogleCASClusterIssuer"),
116-
Recorder: mgr.GetEventRecorderFor("cas-issuer-googlecasclusterissuer-controller"),
117-
Scheme: mgr.GetScheme(),
118-
}).SetupWithManager(mgr); err != nil {
119-
setupLog.Error(err, "unable to create controller", "controller", "GoogleCASClusterIssuer")
120-
return err
121-
}
122-
if err = (&certificaterequest.CertificateRequestReconciler{
123-
Client: mgr.GetClient(),
124-
Log: ctrl.Log.WithName("controller").WithName("CertificateRequest"),
125-
Recorder: mgr.GetEventRecorderFor("cas-issuer-certificaterequest-controller"),
126-
}).SetupWithManager(mgr); err != nil {
127-
setupLog.Error(err, "unable to create controller", "controller", "CertificateRequest")
128-
return err
129-
}
130108
// +kubebuilder:scaffold:builder
131109

132110
setupLog.Info("starting manager")

deploy/charts/google-cas-issuer/templates/clusterrole.yaml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,73 @@ rules:
2020
- get
2121
- list
2222
- watch
23+
2324
- apiGroups:
2425
- cas-issuer.jetstack.io
2526
resources:
2627
- googlecasclusterissuers
2728
verbs:
28-
- create
29-
- delete
3029
- get
3130
- list
32-
- patch
33-
- update
3431
- watch
3532
- apiGroups:
3633
- cas-issuer.jetstack.io
3734
resources:
3835
- googlecasclusterissuers/status
3936
verbs:
40-
- get
4137
- patch
42-
- update
4338
- apiGroups:
4439
- cas-issuer.jetstack.io
4540
resources:
4641
- googlecasissuers
4742
verbs:
48-
- create
49-
- delete
5043
- get
5144
- list
52-
- patch
53-
- update
5445
- watch
5546
- apiGroups:
5647
- cas-issuer.jetstack.io
5748
resources:
5849
- googlecasissuers/status
5950
verbs:
60-
- get
6151
- patch
62-
- update
6352
- apiGroups:
6453
- cert-manager.io
6554
resources:
6655
- certificaterequests
6756
verbs:
6857
- get
6958
- list
70-
- update
7159
- watch
7260
- apiGroups:
7361
- cert-manager.io
7462
resources:
7563
- certificaterequests/status
7664
verbs:
65+
- patch
66+
67+
- apiGroups:
68+
- certificates.k8s.io
69+
resources:
70+
- certificatesigningrequests
71+
verbs:
7772
- get
73+
- list
74+
- watch
75+
- apiGroups:
76+
- certificates.k8s.io"
77+
resources:
78+
- certificatesigningrequests/status
79+
verbs:
7880
- patch
79-
- update
81+
- apiGroups:
82+
- certificates.k8s.io
83+
resources:
84+
- signers
85+
verbs:
86+
- sign
87+
resourceNames:
88+
- googlecasclusterissuers.cas-issuer.jetstack.io/*
89+
8090
---
8191
{{- if .Values.app.approval.enabled }}
8292
apiVersion: rbac.authorization.k8s.io/v1

0 commit comments

Comments
 (0)