integrate introducer
All checks were successful
Gitea/syncthingcsi/pipeline/head This commit looks good

This commit is contained in:
dave 2024-08-02 13:33:50 -07:00
parent 0344aef011
commit be87ff8342
3 changed files with 39 additions and 70 deletions

View File

@ -11,4 +11,4 @@ FROM alpine
COPY --from=build /code/syncthing-csi /syncthing-csi
COPY --from=build /code/syncthing-csi-introducer /syncthing-csi-introducer
ENTRYPOINT ["/syncthing-csi"]

View File

@ -1,47 +0,0 @@
package main
import (
"flag"
"fmt"
"git.davepedu.com/dave/syncthingcsi/pkg/introducer"
"git.davepedu.com/dave/syncthingcsi/pkg/util"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
"os"
)
func main() {
var (
version = flag.Bool("version", false, "show version")
outside = flag.Bool("outside", false, "use kubeconfig instead of in-cluster config")
)
klog.InitFlags(nil)
flag.Parse()
if *version {
fmt.Println("0.0.1")
os.Exit(0)
}
var client *kubernetes.Clientset
var clerr error
if *outside {
client, clerr = util.GetKubeClientKubeconfig()
} else {
client, clerr = util.GetKubeClientInCluster()
}
if clerr != nil {
klog.Fatalln("couldn't create kubeclient:", clerr)
}
namespace := os.Getenv("KUBERNETES_NAMESPACE")
if namespace == "" {
klog.Fatalln("must set KUBERNETES_NAMESPACE")
}
itd := introducer.NewIntroducer(client, namespace)
if err := itd.Run(); err != nil {
klog.Fatalln(err)
}
}

View File

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"git.davepedu.com/dave/syncthingcsi/pkg/driverutil"
"git.davepedu.com/dave/syncthingcsi/pkg/introducer"
"git.davepedu.com/dave/syncthingcsi/pkg/util"
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
@ -13,13 +14,17 @@ import (
)
var (
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "csi endpoint")
version = flag.Bool("version", false, "show version")
outside = flag.Bool("outside", false, "use kubeconfig instead of in-cluster config")
modeIntroducer = flag.Bool("introducer", false, "run in introducer mode")
modeController = flag.Bool("controller", false, "run in controller mode")
// mode flags
modeCsi = flag.Bool("csi", false, "run in csi mode (default)")
modeController = flag.Bool("controller", false, "run in controller mode")
modeIntroducer = flag.Bool("introducer", false, "run in introducer mode")
// common flags
version = flag.Bool("version", false, "show version")
outside = flag.Bool("outside", false, "use kubeconfig instead of in-cluster config")
// csi flags
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "csi endpoint")
)
func main() {
@ -36,19 +41,9 @@ func main() {
os.Exit(3)
}
if *modeIntroducer {
//mainIntroducer()
} else if *modeController {
//mainController()
} else {
mainCsi()
}
}
func mainCsi() {
nodeID := os.Getenv("KUBERNETES_NODE_NAME")
if nodeID == "" {
klog.Fatal("must set KUBERNETES_NODE_NAME")
namespace := os.Getenv("KUBERNETES_NAMESPACE")
if namespace == "" {
klog.Fatalln("must set KUBERNETES_NAMESPACE")
}
var client *kubernetes.Clientset
@ -62,9 +57,19 @@ func mainCsi() {
klog.Fatalln("couldn't create kubeclient:", clerr)
}
namespace := os.Getenv("KUBERNETES_NAMESPACE")
if namespace == "" {
klog.Fatalln("must set KUBERNETES_NAMESPACE")
if *modeIntroducer {
mainIntroducer(client, namespace)
} else if *modeController {
//mainController(client, namespace)
} else {
mainCsi(client, namespace)
}
}
func mainCsi(client *kubernetes.Clientset, namespace string) {
nodeID := os.Getenv("KUBERNETES_NODE_NAME")
if nodeID == "" {
klog.Fatal("must set KUBERNETES_NODE_NAME")
}
stApikey := driverutil.GetSyncthingApiKey()
@ -74,3 +79,14 @@ func mainCsi() {
klog.Fatalln(err)
}
}
func mainIntroducer(client *kubernetes.Clientset, namespace string) {
itd := introducer.NewIntroducer(client, namespace)
if err := itd.Run(); err != nil {
klog.Fatalln(err)
}
}
func mainController(client *kubernetes.Clientset, namespace string) {
}