From a84aa16b2c36c7672f6f4e775c3d5b17a12ca936 Mon Sep 17 00:00:00 2001 From: otto <965391514@qq.com> Date: Tue, 15 Nov 2022 16:50:50 +0800 Subject: [PATCH] u --- Jenkinsfile | 64 ---------------------------------------- README.md | 6 ++-- cmd/server/main.go | 1 + cmd/server/wire_gen.go | 7 ++++- go.mod | 10 +++---- go.sum | 16 +++++----- job.yaml | 44 +++++---------------------- pkg/gift/gift.go | 4 +-- pkg/room/room.go | 4 +-- test/configs/config | 19 ++++++++++++ test/configs/config.yaml | 42 ++++++++++++++++++++++++++ test/job_test.go | 59 ++++++++++++++++++++++++++++++++++++ 12 files changed, 155 insertions(+), 121 deletions(-) delete mode 100644 Jenkinsfile create mode 100644 test/configs/config create mode 100644 test/configs/config.yaml create mode 100644 test/job_test.go diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index f054143..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,64 +0,0 @@ -def buildService(serverName){ - docker.withRegistry('https://registry.internal.jumaiyx.cn', 'docker-registry-internal-backend') { - def img = docker.build("jm/$serverName:${env.BUILD_ID}",".") - img.push() - } -} - -pipeline { - agent any - - environment { - // 服务名 - SERVER_NAME = 'feedback' - // 镜像名称,对应K8S_FILE里面Deployment.containers的name - IMAGE_NAME = 'feedback' - // git路径 - GIT_URL = 'http://git.gz.internal.jumaiyx.cn/job/room-server-clear.git' - // 分支 - GIT_BRANCH = '*/master' - // kubectl执行文件 - K8S_FILE = 'feedback-dev.yaml' - // k8s deployment名称,对应K8S_FILE里面Deployment的name - K8S_DEPLOYMENT = 'feedback-deployment' - } - - stages { - stage('git代码拉取') { - steps { - checkout([$class: 'GitSCM', branches: [[name: "${env.GIT_BRANCH}"]], extensions: [], userRemoteConfigs: [[url: "${env.GIT_URL}"]]]) - echo 'git代码拉取 成功' - } - } - stage('docker镜像打包') { - steps { - echo "镜像版本:${env.BUILD_ID}" - buildService("${env.SERVER_NAME}") - echo 'docker镜像打包' - } - } - stage('传入k8s-master') { - steps { - //sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: "${env.K8S_FILE}")], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) - echo '将yaml传入k8s-master' - } - } - stage('部署服务') { - steps { - //sh "ssh root@192.168.1.156 kubectl apply -f /usr/local/k8s/${env.K8S_FILE}" - echo '部署服务' - //sh '''if if (( ${env.BUILD_ID} == 1 )) - //then - // ssh root@192.168.1.156 kubectl apply -f /usr/local/k8s/${env.K8S_FILE} - // echo '部署服务' - //fi''' - } - } - stage('更新image') { - steps { - sh "ssh root@192.168.1.156 kubectl set image Deployment/${env.K8S_DEPLOYMENT} ${env.IMAGE_NAME}=registry.internal.jumaiyx.cn/jm/${env.SERVER_NAME}:${env.BUILD_ID} -n dev" - echo '部署服务' - } - } - } -} diff --git a/README.md b/README.md index fdb6b05..1869755 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ ```sh docker login -u devops-internal -p yVZUucBSMTJ8HDct https://registry.internal.jumaiyx.cn -docker build -t registry.internal.jumaiyx.cn/jm/message:latest . -docker tag registry.internal.jumaiyx.cn/jm/message:latest registry.internal.jumaiyx.cn/jm/message:v1.0.0 -docker push registry.internal.jumaiyx.cn/jm/message:v1.0.0 +docker build -t registry.internal.jumaiyx.cn/job/room-hot-compute:latest . +docker tag registry.internal.jumaiyx.cn/job/room-hot-compute:latest registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0 +docker push registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0 ``` diff --git a/cmd/server/main.go b/cmd/server/main.go index ba06b7c..fe59955 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -35,4 +35,5 @@ func main() { ctx := context.TODO() l.WithContext(ctx) biz.Check(ctx) + } diff --git a/cmd/server/wire_gen.go b/cmd/server/wire_gen.go index 7949a73..5d848b8 100644 --- a/cmd/server/wire_gen.go +++ b/cmd/server/wire_gen.go @@ -10,6 +10,7 @@ import ( "git.gz.internal.jumaiyx.cn/jm/jmproto/conf" "git.gz.internal.jumaiyx.cn/job/room-hot-compute/internal/biz" "git.gz.internal.jumaiyx.cn/job/room-hot-compute/internal/data" + "git.gz.internal.jumaiyx.cn/job/room-hot-compute/pkg/gift" "git.gz.internal.jumaiyx.cn/job/room-hot-compute/pkg/room" "git.gz.internal.jumaiyx.cn/pkg/log" ) @@ -22,11 +23,15 @@ func wireApp(server *conf.Server, confData *conf.Data, logger log.Logger) (*biz. if err != nil { return nil, nil, err } + giftClient, err := gift.NewGiftService(logger) + if err != nil { + return nil, nil, err + } dataData, cleanup, err := data.NewData(confData, logger) if err != nil { return nil, nil, err } - bizBiz := biz.NewBiz(logger, roomClient, dataData) + bizBiz := biz.NewBiz(logger, roomClient, giftClient, dataData) return bizBiz, func() { cleanup() }, nil diff --git a/go.mod b/go.mod index 9067c51..70fe91c 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,16 @@ module git.gz.internal.jumaiyx.cn/job/room-hot-compute go 1.18 require ( - git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221114080632-fdff5af719f3 + git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221115073332-c5d64953ace0 git.gz.internal.jumaiyx.cn/pkg/config v0.0.0-20221014090146-8fd721834886 - git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221111084006-d3558f68d33b + git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221115074539-90a2644b4f64 git.gz.internal.jumaiyx.cn/pkg/kubediscovery v0.0.0-20221104101240-01cad3403ec0 git.gz.internal.jumaiyx.cn/pkg/log v0.0.0-20221029084114-f67ca5716ca1 github.com/go-redis/redis/v8 v8.11.5 github.com/google/wire v0.5.0 github.com/pkg/errors v0.9.1 + k8s.io/api v0.25.4 + k8s.io/apimachinery v0.25.4 ) require ( @@ -55,14 +57,12 @@ require ( golang.org/x/text v0.4.0 // indirect golang.org/x/time v0.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20221111202108-142d8a6fa32e // indirect + google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 // indirect google.golang.org/grpc v1.50.1 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.25.4 // indirect - k8s.io/apimachinery v0.25.4 // indirect k8s.io/client-go v0.25.4 // indirect k8s.io/klog/v2 v2.80.1 // indirect k8s.io/kube-openapi v0.0.0-20221110221610-a28e98eb7c70 // indirect diff --git a/go.sum b/go.sum index 933304b..f86ff6f 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,15 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221114074402-8ee109365a6b h1:PeQrex+iaICUQCmPhhcyryTjPDur4HwLbtxViXfdoBw= -git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221114074402-8ee109365a6b/go.mod h1:RuwVCwjm2L1MfZAePy5exPb/0OKHglXM+Q5lXrcdGxs= -git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221114080632-fdff5af719f3 h1:ZAnktqr9aXVILpDrCBKLIizI9HU9CWuLz+Q8snJUoXk= -git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221114080632-fdff5af719f3/go.mod h1:RuwVCwjm2L1MfZAePy5exPb/0OKHglXM+Q5lXrcdGxs= +git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221115073332-c5d64953ace0 h1:xoBeBJykjioV0wo/d5hOmMXDztgwFIU5SvrpRYFMZjM= +git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20221115073332-c5d64953ace0/go.mod h1:RuwVCwjm2L1MfZAePy5exPb/0OKHglXM+Q5lXrcdGxs= git.gz.internal.jumaiyx.cn/pkg/config v0.0.0-20221014090146-8fd721834886 h1:LP4psj3ygJEKL6748ZQPNwYnYPmbo8dDwtwU08coRiw= git.gz.internal.jumaiyx.cn/pkg/config v0.0.0-20221014090146-8fd721834886/go.mod h1:yEnzjNrnPNIr0Zq926QiJrbyReS+VZqX5bmkYhnSV7I= git.gz.internal.jumaiyx.cn/pkg/id-encode v0.0.0-20221018014421-fe47b648265b h1:Bb+j4SrJMb00+QKQO1FcCDDOxzTnoBZCi2n0DrT39lE= git.gz.internal.jumaiyx.cn/pkg/id-encode v0.0.0-20221018014421-fe47b648265b/go.mod h1:+1j9TQXFahHrK3TYJjXLuuDNCqKRscAWR2fD1ZhZE0c= -git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221111084006-d3558f68d33b h1:dfhLVPDgTb8R5a5zs4/Rin6e6kdfvuGK0/m4BpNvLJw= -git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221111084006-d3558f68d33b/go.mod h1:PjyxKfTWowQjJcim7h5DB+9pE7gI0U7BYx2z200hVyc= +git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221115073038-b4deb8b66870 h1:bdr+ZSnt3TKRWZMzEazTImMfX6JH4QZ9ic7mIrvbh9U= +git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221115073038-b4deb8b66870/go.mod h1:PjyxKfTWowQjJcim7h5DB+9pE7gI0U7BYx2z200hVyc= +git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221115074539-90a2644b4f64 h1:9SsbZJ5M29DkH2k8iYjM4GpOnegxN2WXgakq0SxO4Hk= +git.gz.internal.jumaiyx.cn/pkg/k8s-client v0.0.0-20221115074539-90a2644b4f64/go.mod h1:PjyxKfTWowQjJcim7h5DB+9pE7gI0U7BYx2z200hVyc= git.gz.internal.jumaiyx.cn/pkg/kafka v0.0.0-20221010085437-f3a4ed57181c h1:C/1lKDrxi2xM2BPGG843kEcmZivhOdEr7Eg86bDIBVY= git.gz.internal.jumaiyx.cn/pkg/kafka v0.0.0-20221010085437-f3a4ed57181c/go.mod h1:TujX5RTIJ6vz8QYG1R6JwssH5DHGrAVpdGBaWG+uVqY= git.gz.internal.jumaiyx.cn/pkg/kubediscovery v0.0.0-20221104101240-01cad3403ec0 h1:G3Hb4Bz9Ku3hSkIIZZu33iN+CNqPEnjVbsOa+MVnat4= @@ -290,8 +290,8 @@ google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= -google.golang.org/genproto v0.0.0-20221111202108-142d8a6fa32e h1:azcyH5lGzGy7pkLCbhPe0KkKxsM7c6UA/FZIXImKE7M= -google.golang.org/genproto v0.0.0-20221111202108-142d8a6fa32e/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= +google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 h1:jCw9YRd2s40X9Vxi4zKsPRvSPlHWNqadVkpbMsCPzPQ= +google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/job.yaml b/job.yaml index 5838b46..f83dde0 100644 --- a/job.yaml +++ b/job.yaml @@ -1,44 +1,16 @@ -apiVersion: apps/v1 -kind: Deployment +apiVersion: batch/v1 +kind: Job metadata: - name: feedback-deployment + name: room-hot-compute-job namespace: dev - labels: - app: feedback spec: - replicas: 2 # 节点资源 - selector: - matchLabels: - app: feedback + ttlSecondsAfterFinished: 10 + activeDeadlineSeconds: 10 template: - metadata: # 资源的元数据/属性 - labels: # 设定资源的标签 - app: feedback spec: containers: - - image: registry.internal.jumaiyx.cn/jm/feedback:1 # 自动化版本往后配置 - name: feedback - imagePullPolicy: Always - ports: - - name: grpc - containerPort: 9000 - protocol: TCP + - name: room-hot-compute-job + image: registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0 + restartPolicy: Never imagePullSecrets: - name: registry-harbor ---- -apiVersion: v1 -kind: Service -metadata: - name: feedback-service # 改名字对应服务发现serviceName - namespace: dev - labels: - name: feedback -spec: - type: ClusterIP - ports: - - name: grpc - port: 9000 - targetPort: grpc - protocol: TCP - selector: - app: feedback \ No newline at end of file diff --git a/pkg/gift/gift.go b/pkg/gift/gift.go index b35a4ae..bdae9f3 100644 --- a/pkg/gift/gift.go +++ b/pkg/gift/gift.go @@ -3,13 +3,13 @@ package gift import ( "context" v1 "git.gz.internal.jumaiyx.cn/jm/jmproto/gift/v1" - k8s_client "git.gz.internal.jumaiyx.cn/pkg/k8s-client" + "git.gz.internal.jumaiyx.cn/pkg/k8s-client" "git.gz.internal.jumaiyx.cn/pkg/kubediscovery" "git.gz.internal.jumaiyx.cn/pkg/log" ) func NewGiftService(log log.Logger) (v1.GiftClient, error) { - discovery, err := kubediscovery.Discovery(context.TODO(), log, "gift-service", kubediscovery.Namespace(k8s_client.DevNamespace)) + discovery, err := kubediscovery.Discovery(context.TODO(), log, "gift-service", kubediscovery.Namespace(k8sclient.DevNamespace)) if err != nil { log.Errorf("Connect room service failed:%v", err) return nil, err diff --git a/pkg/room/room.go b/pkg/room/room.go index ed71d44..ead0c1c 100644 --- a/pkg/room/room.go +++ b/pkg/room/room.go @@ -3,13 +3,13 @@ package room import ( "context" v1 "git.gz.internal.jumaiyx.cn/jm/jmproto/room/v1" - k8s_client "git.gz.internal.jumaiyx.cn/pkg/k8s-client" + "git.gz.internal.jumaiyx.cn/pkg/k8s-client" "git.gz.internal.jumaiyx.cn/pkg/kubediscovery" "git.gz.internal.jumaiyx.cn/pkg/log" ) func NewRoomService(log log.Logger) (v1.RoomClient, error) { - discovery, err := kubediscovery.Discovery(context.TODO(), log, "room-service", kubediscovery.Namespace(k8s_client.DevNamespace)) + discovery, err := kubediscovery.Discovery(context.TODO(), log, "room-service", kubediscovery.Namespace(k8sclient.DevNamespace)) if err != nil { log.Errorf("Connect room service failed:%v", err) return nil, err diff --git a/test/configs/config b/test/configs/config new file mode 100644 index 0000000..2e8027a --- /dev/null +++ b/test/configs/config @@ -0,0 +1,19 @@ +apiVersion: v1 +clusters: +- cluster: + certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1Ea3lOekF4TXpRek9Wb1hEVE15TURreU5EQXhNelF6T1Zvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBS1VGClBZdjVCdlRYLzlXdjZhWU9vWmM5cUtnclVnQjRz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ubernetes +contexts: +- context: + cluster: kubernetes + user: kubernetes-admin + name: kubernetes-admin@kubernetes +current-context: kubernetes-admin@kubernetes +kind: Config +preferences: {} +users: +- name: kubernetes-admin + user: + client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJTFV6blJtKzZqUkV3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBNU1qY3dNVE0wTXpsYUZ3MHlNekE1TWpjd01UTTBOREJhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTNYOFZrc2x3N3AxQUF3aG4KbW5nRHU3NWRUUUpXUm1EN014a3ZPN0ZiWFFXVTVHUDg3bHpEV2pMeUt2L1NqZTZ5a1VTTkE5Z21kTmRrOTY0RgpnYWpyRnRHSUZXVzM2NVFXeitRT25ZVWFHQk9VRHQ2VFloOWlSRXJIRjhsR3NRVW0vVi9NemttMXpkY284ZEtHCm5VbktDWDhyMW5yVm53UkRiRTE2VEozcFRhK2tXdmVHYlFoRW5PZHpBMkJFTDl3cWR4bUljNm1GMnFla0ZDVXoKMlF1cGtMR3JOMlBEVGd2YmdwcS9pbTdldUIyYXNLczE2RjByMElrMk83VHhoK2twZkQrazVTLzdUdTEyWGttVwpkNWIyZHlVMFlCZFZDRUJFV1JiK3ROU3oxQXlVdEZQbEkxRmdabWZaajdKRGFkYzlDMG9ML2hoOFA0UzU3NFlECnFjaEZxUUlEQVFBQm95Y3dKVEFPQmdOVkhROEJBZjhFQkFNQ0JhQXdFd1lEVlIwbEJBd3dDZ1lJS3dZQkJRVUgKQXdJd0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFJ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mUlE4Yzl4YlBHcjlMV1oyeTNqQWZ1ZlFjK3p5bmlrZml1T1ZCRmZZM0NRenAvUTUzQitLa0x0Cnk1SVMzZFA4eEF0NVl1TmE4WDBtSVFLQmdRQ2RBSkFaQlNGZi9yN05uVEJnY3M2MEo2cG55TW1BSitoSkN5WnoKYVpIUzgrOXl4SFhPaThQYlphdHhmMmJYQ2tEUFp2ZFk3MGErUEswTmJSdzhGUUZRbXF6ckFDVTNCOXJ5NDUraAplbkRXR0Racy9Rakd3QytYOHZNbUFvNHdBanhHbVJ2b01kWjFtN0RNbW1lTzZKQ1ZrNnNRd1BRclNVVk9PRGdVCmgyRWJNUUtCZ0RQamNEdjN6SjJJVjFrY01kbjNEMWVyQjBFR0I1M2NYeHFoa0pET3Rqd3RUV3V2dHNIYzI0R3gKNmFQODI1QllUV2NQNEJ6dEFIN1A5RkE2QmlBa0t3T3lrWFR5dDg2RTBUZUM5L3FtSW9EY255aHdReHVCZlB3UQo2bVhxeVFLZFBOTnVoKzlReDBEcGxHMTkzVTFid0pya3k3b3hKc0dackg1OUdGK3VTT3J0Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg== \ No newline at end of file diff --git a/test/configs/config.yaml b/test/configs/config.yaml new file mode 100644 index 0000000..08ab35b --- /dev/null +++ b/test/configs/config.yaml @@ -0,0 +1,42 @@ +server: + name: room + http: + addr: 0.0.0.0:8000 + timeout: 30 + grpc: + addr: 0.0.0.0:9000 + timeout: 30 +data: + database: + source: "host=192.168.1.156 user=metachat password=metachat dbname=feedback port=15433 sslmode=disable TimeZone=Asia/Shanghai" +# source: postgresql://metachat:metachat@127.0.0.1:15432/room + redis: + addr: 192.168.1.156:16378 + password: MM5ZsXL0 + read_timeout: 1 + write_timeout: 1 + +etcd: + host: "127.0.0.1:20000" + +log: + level: "debug" + name: "room" + kafka: + addr: + - "127.0.0.1:9092" +amqp: + host: 192.168.1.156:5672 + username: jm + password: jm123456 + +id_encode: + uid: + salt: "test" + min_length: 8 + +rtctoken: + app_id: 6eeb2e6be9a141d1b0db920f36a5a9f3 + app_certificate: 80438856882e4563841d56f3cefeb763 + privilege_expiration: 3600 + token_expiration: 3600 \ No newline at end of file diff --git a/test/job_test.go b/test/job_test.go new file mode 100644 index 0000000..2a3f9e8 --- /dev/null +++ b/test/job_test.go @@ -0,0 +1,59 @@ +package test + +import ( + "context" + k8sclient "git.gz.internal.jumaiyx.cn/pkg/k8s-client" + "git.gz.internal.jumaiyx.cn/pkg/log" + v1 "k8s.io/api/batch/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" +) + +// pods=$(kubectl get pods --selector=job-name=room-hot-compute-job --output=jsonpath='{.items[*].metadata.name}') +// echo $pods +func TestCreateJob(t *testing.T) { + l := log.DefaultLogger() + job, err := k8sclient.NewJob(k8sclient.DevNamespace, l) + if err != nil { + t.Fatal(err) + } + ctx := context.TODO() + ttl := int32(60) + ttls := int64(60) + _, err = job.Create(ctx, &v1.Job{ + ObjectMeta: metav1.ObjectMeta{ + Name: "room-hot-compute-job", + Namespace: k8sclient.DevNamespace, + }, + Spec: v1.JobSpec{ + ActiveDeadlineSeconds: &ttls, + TTLSecondsAfterFinished: &ttl, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Name: "room-hot-compute-job", + Labels: map[string]string{ + "app": "room-job", + }, + }, + Spec: corev1.PodSpec{ + RestartPolicy: corev1.RestartPolicyNever, + Containers: []corev1.Container{ + { + Name: "room-hot-compute-job", + Image: "registry.internal.jumaiyx.cn/job/room-hot-compute:v1.0.0", + }, + }, + ImagePullSecrets: []corev1.LocalObjectReference{ + { + Name: k8sclient.DockerRegistryHarbor, + }, + }, + }, + }, + }, + }) + if err != nil { + t.Fatal(err) + } +}