added csr approver
This commit is contained in:
parent
b0e048ba9d
commit
bc750389dc
14 changed files with 852 additions and 310 deletions
104
cmd/pve-csr-approver-manager/main.go
Normal file
104
cmd/pve-csr-approver-manager/main.go
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/klog/klogr"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"git.giftfish.de/ston1th/cloud-controller-manager-pve/pkg/approver"
|
||||
pve "git.giftfish.de/ston1th/pve-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
flag.Parse()
|
||||
log := klogr.New()
|
||||
opts, err := pve.ClientOptionsFromEnv()
|
||||
if err != nil {
|
||||
log.Error(err, "could not create pve client")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
pveClient := pve.NewClient(opts...)
|
||||
|
||||
cfg, err := rest.InClusterConfig()
|
||||
if err != nil {
|
||||
log.Error(err, "could not configure kubernetes client")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cl, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
log.Error(err, "could not create kubernetes client")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
factory := informers.NewSharedInformerFactory(cl, time.Second*30)
|
||||
certInformerV1beta1 := factory.Certificates().V1beta1().CertificateSigningRequests().Informer()
|
||||
fV1beta1 := func(obj interface{}) {
|
||||
if req, ok := obj.(*certificatesv1beta1.CertificateSigningRequest); ok {
|
||||
if err := approver.ApproveV1beta1(log, pveClient, cl.CertificatesV1beta1().CertificateSigningRequests(), req); err != nil {
|
||||
log.Error(err, "csr approval failed", "name", req.ObjectMeta.Name)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
certInformerV1beta1.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
fV1beta1(obj)
|
||||
},
|
||||
UpdateFunc: func(_, obj interface{}) {
|
||||
fV1beta1(obj)
|
||||
},
|
||||
})
|
||||
stop := make(chan struct{})
|
||||
factory.Start(stop)
|
||||
|
||||
//watchListV1 := cache.NewListWatchFromClient(
|
||||
// cl.CertificatesV1Client.RESTClient(),
|
||||
// "certificatesigningrequests",
|
||||
// v1.NamespaceAll,
|
||||
// fields.Everything(),
|
||||
//)
|
||||
//fV1 := func(obj interface{}) {
|
||||
// if req, ok := obj.(*certificates.CertificateSigningRequest); ok {
|
||||
// if err := approver.ApproveV1(pveClient, cl.CertificatesV1Client.CertificateSigningRequests(), req); err != nil {
|
||||
// log.Error(err, "csr approval failed", "name", req.ObjectMeta.Name)
|
||||
// return
|
||||
// }
|
||||
// log.Info("csr approval successful", "name", req.ObjectMeta.Name)
|
||||
// }
|
||||
//}
|
||||
//_, controllerV1 := cache.NewInformer(
|
||||
// watchListV1,
|
||||
// &certificates.CertificateSigningRequest{},
|
||||
// time.Second*30,
|
||||
// cache.ResourceEventHandlerFuncs{
|
||||
// AddFunc: func(obj interface{}) {
|
||||
// fV1(obj)
|
||||
// },
|
||||
// UpdateFunc: func(_, obj interface{}) {
|
||||
// fV1(obj)
|
||||
// },
|
||||
// },
|
||||
//)
|
||||
//stopV1 := make(chan struct{})
|
||||
//go controllerV1.Run(stopV1)
|
||||
log.Info("csr approver started")
|
||||
|
||||
sigs := make(chan os.Signal)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigs
|
||||
close(stop)
|
||||
log.Info("csr approver stopped")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue