perf: remove go-nanoid and rxgo
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"flink-kube-operator/pkg"
|
||||
|
||||
"github.com/reactivex/rxgo/v2"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
||||
@@ -13,11 +12,10 @@ import (
|
||||
|
||||
var FinalizerChannel chan (types.UID) = make(chan (types.UID))
|
||||
|
||||
func (crd Crd) manageFinalizer(jobEventObservable rxgo.Observable) {
|
||||
func (crd Crd) manageFinalizer(jobEventChannel chan FlinkJobCrdEvent) {
|
||||
|
||||
finalizerName := "flink-operator.logicamp.tech/finalizer"
|
||||
for j := range jobEventObservable.Observe() {
|
||||
jobEvent := j.V.(*FlinkJobCrdEvent)
|
||||
for jobEvent := range jobEventChannel {
|
||||
pkg.Logger.Debug("[crd] [manage-finalizer] main loop", zap.String("name", jobEvent.Job.Name))
|
||||
go func() {
|
||||
if jobEvent.Job.GetDeletionTimestamp() != nil {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"os"
|
||||
|
||||
"github.com/reactivex/rxgo/v2"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/rest"
|
||||
@@ -49,10 +48,10 @@ func New() *Crd {
|
||||
runtimeClient: runtimeClient,
|
||||
}
|
||||
|
||||
jobEventCh := make(chan rxgo.Item)
|
||||
jobEventCh := make(chan FlinkJobCrdEvent)
|
||||
|
||||
// add finalizer to new resources
|
||||
go crd.manageFinalizer(rxgo.FromChannel(jobEventCh))
|
||||
go crd.manageFinalizer(jobEventCh)
|
||||
|
||||
// Watch for FlinkJob creation
|
||||
crd.watchFlinkJobs(jobEventCh)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"flink-kube-operator/pkg"
|
||||
|
||||
"github.com/reactivex/rxgo/v2"
|
||||
"go.uber.org/zap"
|
||||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -15,7 +14,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
)
|
||||
|
||||
func (crd Crd) watchFlinkJobs(ch chan rxgo.Item) rxgo.Observable {
|
||||
func (crd Crd) watchFlinkJobs(ch chan FlinkJobCrdEvent) {
|
||||
|
||||
go func() {
|
||||
pkg.Logger.Debug("[crd] starting watch")
|
||||
@@ -45,14 +44,12 @@ func (crd Crd) watchFlinkJobs(ch chan rxgo.Item) rxgo.Observable {
|
||||
}
|
||||
|
||||
go func() {
|
||||
ch <- rxgo.Item{
|
||||
V: &FlinkJobCrdEvent{
|
||||
EventType: event.Type,
|
||||
Job: job,
|
||||
},
|
||||
ch <- FlinkJobCrdEvent{
|
||||
EventType: event.Type,
|
||||
Job: job,
|
||||
}
|
||||
}()
|
||||
pkg.Logger.Debug("[crd] [watch] change in", zap.String("name", job.Name))
|
||||
pkg.Logger.Debug("[crd] [watch] change in", zap.String("name", job.Name), zap.String("operation", string(event.Type)))
|
||||
switch event.Type {
|
||||
case watch.Bookmark:
|
||||
case watch.Modified:
|
||||
@@ -68,5 +65,4 @@ func (crd Crd) watchFlinkJobs(ch chan rxgo.Item) rxgo.Observable {
|
||||
|
||||
}()
|
||||
|
||||
return rxgo.FromChannel(ch)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package jar
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -10,7 +12,6 @@ import (
|
||||
"flink-kube-operator/pkg"
|
||||
|
||||
api "github.com/logi-camp/go-flink-client"
|
||||
gonanoid "github.com/matoous/go-nanoid/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -46,7 +47,9 @@ func (jarFile *JarFile) Upload(flinkClient *api.Client) (fileName string, err er
|
||||
}
|
||||
|
||||
func (jarFile *JarFile) Download() error {
|
||||
fileName, _ := gonanoid.New()
|
||||
randBytes := make([]byte, 16)
|
||||
rand.Read(randBytes)
|
||||
fileName := hex.EncodeToString(randBytes)
|
||||
jarFile.filePath = "/tmp/" + fileName + ".jar"
|
||||
out, err := os.Create(jarFile.filePath)
|
||||
if err != nil {
|
||||
|
||||
@@ -96,8 +96,6 @@ func (mgr *Manager) cycle(client *api.Client, crdInstance *crd.Crd) {
|
||||
|
||||
}
|
||||
|
||||
pkg.Logger.Debug("[manager] [cycle] finding job", zap.Any("name", managedJob.def.Name))
|
||||
|
||||
jobManagerJobOverview, jobFound := lo.Find(jobManagerJobOverviews.Jobs, func(job api.JobOverview) bool {
|
||||
jobId := managedJob.GetJobId()
|
||||
if jobId != nil {
|
||||
|
||||
Reference in New Issue
Block a user