@@ -25,11 +25,11 @@ import (
2525
2626 "github.com/kubermatic/machine-controller/pkg/apis/cluster/v1alpha1"
2727
28- certificatesv1beta1 "k8s.io/api/certificates/v1beta1 "
28+ certificatesv1 "k8s.io/api/certificates/v1 "
2929 kerrors "k8s.io/apimachinery/pkg/api/errors"
30- v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131 "k8s.io/apimachinery/pkg/util/sets"
32- certificatesv1beta1client "k8s.io/client-go/kubernetes/typed/certificates/v1beta1 "
32+ certificatesv1client "k8s.io/client-go/kubernetes/typed/certificates/v1 "
3333 "k8s.io/klog"
3434 "sigs.k8s.io/controller-runtime/pkg/client"
3535 "sigs.k8s.io/controller-runtime/pkg/controller"
@@ -54,11 +54,11 @@ type reconciler struct {
5454 client.Client
5555 // Have to use the typed client because csr approval is a subresource
5656 // the dynamic client does not approve
57- certClient certificatesv1beta1client .CertificateSigningRequestInterface
57+ certClient certificatesv1client .CertificateSigningRequestInterface
5858}
5959
6060func Add (mgr manager.Manager ) error {
61- certClient , err := certificatesv1beta1client .NewForConfig (mgr .GetConfig ())
61+ certClient , err := certificatesv1client .NewForConfig (mgr .GetConfig ())
6262 if err != nil {
6363 return fmt .Errorf ("failed to create certificate client: %v" , err )
6464 }
@@ -68,7 +68,7 @@ func Add(mgr manager.Manager) error {
6868 if err != nil {
6969 return fmt .Errorf ("failed to construct controller: %v" , err )
7070 }
71- return c .Watch (& source.Kind {Type : & certificatesv1beta1 .CertificateSigningRequest {}}, & handler.EnqueueRequestForObject {})
71+ return c .Watch (& source.Kind {Type : & certificatesv1 .CertificateSigningRequest {}}, & handler.EnqueueRequestForObject {})
7272}
7373
7474func (r * reconciler ) Reconcile (ctx context.Context , request reconcile.Request ) (reconcile.Result , error ) {
@@ -79,13 +79,13 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
7979 return reconcile.Result {}, err
8080}
8181
82- var allowedUsages = []certificatesv1beta1 .KeyUsage {certificatesv1beta1 .UsageDigitalSignature ,
83- certificatesv1beta1 .UsageKeyEncipherment ,
84- certificatesv1beta1 .UsageServerAuth }
82+ var allowedUsages = []certificatesv1 .KeyUsage {certificatesv1 .UsageDigitalSignature ,
83+ certificatesv1 .UsageKeyEncipherment ,
84+ certificatesv1 .UsageServerAuth }
8585
8686func (r * reconciler ) reconcile (ctx context.Context , request reconcile.Request ) error {
8787 // Get the CSR object
88- csr := & certificatesv1beta1 .CertificateSigningRequest {}
88+ csr := & certificatesv1 .CertificateSigningRequest {}
8989 if err := r .Get (ctx , request .NamespacedName , csr ); err != nil {
9090 if kerrors .IsNotFound (err ) {
9191 return nil
@@ -96,7 +96,7 @@ func (r *reconciler) reconcile(ctx context.Context, request reconcile.Request) e
9696
9797 // If CSR is approved, skip it
9898 for _ , condition := range csr .Status .Conditions {
99- if condition .Type == certificatesv1beta1 .CertificateApproved {
99+ if condition .Type == certificatesv1 .CertificateApproved {
100100 klog .V (4 ).Infof ("CSR %s already approved, skipping reconciling" , csr .ObjectMeta .Name )
101101 return nil
102102 }
@@ -138,13 +138,13 @@ func (r *reconciler) reconcile(ctx context.Context, request reconcile.Request) e
138138
139139 // Approve CSR
140140 klog .V (4 ).Infof ("Approving CSR %s" , csr .ObjectMeta .Name )
141- approvalCondition := certificatesv1beta1 .CertificateSigningRequestCondition {
142- Type : certificatesv1beta1 .CertificateApproved ,
141+ approvalCondition := certificatesv1 .CertificateSigningRequestCondition {
142+ Type : certificatesv1 .CertificateApproved ,
143143 Reason : "machine-controller NodeCSRApprover controller approved node serving cert" ,
144144 }
145145 csr .Status .Conditions = append (csr .Status .Conditions , approvalCondition )
146146
147- if _ , err := r .certClient .UpdateApproval (ctx , csr , v1 .UpdateOptions {}); err != nil {
147+ if _ , err := r .certClient .UpdateApproval (ctx , csr . Name , csr , metav1 .UpdateOptions {}); err != nil {
148148 return fmt .Errorf ("failed to approve CSR %q: %v" , csr .Name , err )
149149 }
150150
@@ -153,7 +153,7 @@ func (r *reconciler) reconcile(ctx context.Context, request reconcile.Request) e
153153}
154154
155155// validateCSRObject valides the CSR object and returns name of the node that requested the certificate
156- func (r * reconciler ) validateCSRObject (csr * certificatesv1beta1 .CertificateSigningRequest ) (string , error ) {
156+ func (r * reconciler ) validateCSRObject (csr * certificatesv1 .CertificateSigningRequest ) (string , error ) {
157157 // Get and validate the node name
158158 if ! strings .HasPrefix (csr .Spec .Username , nodeUserPrefix ) {
159159 return "" , fmt .Errorf ("username must have the '%s' prefix" , nodeUserPrefix )
@@ -186,7 +186,7 @@ func (r *reconciler) validateCSRObject(csr *certificatesv1beta1.CertificateSigni
186186
187187// validateX509CSR validates the certificate request by comparing CN with username,
188188// and organization with groups.
189- func (r * reconciler ) validateX509CSR (csr * certificatesv1beta1 .CertificateSigningRequest , certReq * x509.CertificateRequest , machine v1alpha1.Machine ) error {
189+ func (r * reconciler ) validateX509CSR (csr * certificatesv1 .CertificateSigningRequest , certReq * x509.CertificateRequest , machine v1alpha1.Machine ) error {
190190 // Validate Subject CommonName
191191 if certReq .Subject .CommonName != csr .Spec .Username {
192192 return fmt .Errorf ("commonName '%s' is different then CSR username '%s'" , certReq .Subject .CommonName , csr .Spec .Username )
@@ -245,7 +245,7 @@ func (r *reconciler) getMachineForNode(ctx context.Context, nodeName string) (v1
245245 return v1alpha1.Machine {}, false , fmt .Errorf ("failed to get machine for given node name '%s'" , nodeName )
246246}
247247
248- func isUsageInUsageList (usage certificatesv1beta1 .KeyUsage , usageList []certificatesv1beta1 .KeyUsage ) bool {
248+ func isUsageInUsageList (usage certificatesv1 .KeyUsage , usageList []certificatesv1 .KeyUsage ) bool {
249249 for _ , usageListItem := range usageList {
250250 if usage == usageListItem {
251251 return true
0 commit comments