feat(crd): add kube api and crds
This commit is contained in:
38
internal/crd/new.go
Normal file
38
internal/crd/new.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package crd
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
type Crd struct {
|
||||
client dynamic.NamespaceableResourceInterface
|
||||
}
|
||||
|
||||
func New() {
|
||||
// Get Kubernetes config
|
||||
config, err := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
|
||||
if err != nil {
|
||||
config, err = rest.InClusterConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create dynamic client
|
||||
dynamicClient, err := dynamic.NewForConfig(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get FlinkJob resource interface
|
||||
flinkJobClient := dynamicClient.Resource(flinkJobGVR)
|
||||
|
||||
crd := Crd{
|
||||
client: flinkJobClient,
|
||||
}
|
||||
|
||||
// Watch for FlinkJob creation
|
||||
go crd.watchFlinkJobs()
|
||||
}
|
||||
Reference in New Issue
Block a user