updated to latest k8s version
This commit is contained in:
parent
974555da9e
commit
bbbd20b5f2
12 changed files with 668 additions and 525 deletions
|
|
@ -9,13 +9,12 @@ import (
|
|||
pve "git.giftfish.de/ston1th/pve-go"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
|
||||
certificatesv1 "k8s.io/api/certificates/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
typedcertificatesv1beta1 "k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/apis/certificates"
|
||||
typedcertificatesv1 "k8s.io/client-go/kubernetes/typed/certificates/v1"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller"
|
||||
|
|
@ -28,20 +27,19 @@ type CSRReconciler struct {
|
|||
Log logr.Logger
|
||||
Scheme *runtime.Scheme
|
||||
PVEClient *pve.Client
|
||||
CSRClient *typedcertificatesv1beta1.CertificatesV1beta1Client
|
||||
CSRClient *typedcertificatesv1.CertificatesV1Client
|
||||
}
|
||||
|
||||
func (r *CSRReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
WithOptions(options).
|
||||
For(&certificatesv1beta1.CertificateSigningRequest{}).
|
||||
For(&certificatesv1.CertificateSigningRequest{}).
|
||||
Complete(r)
|
||||
}
|
||||
|
||||
func (r *CSRReconciler) Reconcile(req ctrl.Request) (res ctrl.Result, err error) {
|
||||
ctx := context.Background()
|
||||
func (r *CSRReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error) {
|
||||
log := r.Log
|
||||
csr := &certificatesv1beta1.CertificateSigningRequest{}
|
||||
csr := &certificatesv1.CertificateSigningRequest{}
|
||||
if err = r.Get(ctx, req.NamespacedName, csr); err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
err = nil
|
||||
|
|
@ -56,13 +54,13 @@ func (r *CSRReconciler) Reconcile(req ctrl.Request) (res ctrl.Result, err error)
|
|||
return
|
||||
}
|
||||
|
||||
var conditionv1beta1 = certificatesv1beta1.CertificateSigningRequestCondition{
|
||||
Type: certificatesv1beta1.CertificateApproved,
|
||||
var conditionv1 = certificatesv1.CertificateSigningRequestCondition{
|
||||
Type: certificatesv1.CertificateApproved,
|
||||
Reason: "AutoApproved",
|
||||
Message: "Auto approving kubelet client certificate in PVE Cluster",
|
||||
}
|
||||
|
||||
func (r *CSRReconciler) approve(ctx context.Context, log logr.Logger, request *certificatesv1beta1.CertificateSigningRequest) error {
|
||||
func (r *CSRReconciler) approve(ctx context.Context, log logr.Logger, request *certificatesv1.CertificateSigningRequest) error {
|
||||
if len(request.Status.Conditions) > 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -79,9 +77,9 @@ func (r *CSRReconciler) approve(ctx context.Context, log logr.Logger, request *c
|
|||
if len(request.Status.Conditions) > 0 {
|
||||
return nil
|
||||
}
|
||||
request.Status.Conditions = append(request.Status.Conditions, conditionv1beta1)
|
||||
request.Status.Conditions = append(request.Status.Conditions, conditionv1)
|
||||
// Submit the updated CSR.
|
||||
if _, err := client.UpdateApproval(ctx, request, metav1.UpdateOptions{}); err != nil {
|
||||
if _, err := client.UpdateApproval(ctx, request.Name, request, metav1.UpdateOptions{}); err != nil {
|
||||
if strings.Contains(err.Error(), "the object has been modified") {
|
||||
// The CSR might have been updated by a third-party, retry until we
|
||||
// succeed.
|
||||
|
|
@ -98,8 +96,8 @@ func (r *CSRReconciler) approve(ctx context.Context, log logr.Logger, request *c
|
|||
}
|
||||
}
|
||||
|
||||
func checkCSR(ctx context.Context, pveClient *pve.Client, request *certificatesv1beta1.CertificateSigningRequest) error {
|
||||
req, err := certificates.ParseCSR(request.Spec.Request)
|
||||
func checkCSR(ctx context.Context, pveClient *pve.Client, request *certificatesv1.CertificateSigningRequest) error {
|
||||
req, err := ParseCSR(request.Spec.Request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -107,7 +105,7 @@ func checkCSR(ctx context.Context, pveClient *pve.Client, request *certificatesv
|
|||
for i, v := range request.Spec.Usages {
|
||||
usages[i] = string(v)
|
||||
}
|
||||
if !certificates.IsKubeletServingCSR(req, sets.NewString(usages...)) {
|
||||
if !IsKubeletServingCSR(req, sets.NewString(usages...)) {
|
||||
return ErrNoKubeletServingCSR
|
||||
}
|
||||
hostname := strings.TrimPrefix(req.Subject.CommonName, "system:node:")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue