Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipeline refactor and cluster watch #731

Merged
merged 18 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apistructs/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const (
ClusterStatusOffline string = "offline"
)

const (
ClusterActionCreate = "create"
ClusterActionUpdate = "update"
ClusterActionDelete = "delete"
)

// token / client-cert&client-key / proxy(dialer)
const (
ManageToken = "token"
Expand Down
24 changes: 4 additions & 20 deletions ...uler/executor/plugins/k8sspark/ptrutil.go → apistructs/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package k8sspark
package apistructs

func stringptr(s string) *string {
return &s
}

func int32ptr(n int32) *int32 {
return &n
}

func int64ptr(n int64) *int64 {
return &n
}

func float32ptr(n float32) *float32 {
return &n
}

func float64ptr(n float64) *float64 {
return &n
}
const (
AliyunRegistry = "aliyun-registry"
)
4 changes: 4 additions & 0 deletions erda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ services:
GIT_INNER_USER_NAME: "18000000000"
GIT_INNER_USER_PASSWORD: "123456"
PIPELINE_STORAGE_URL: "file:///devops/storage"
POD_IP:
valueFrom:
fieldRef:
fieldPath: status.podIP
resources:
cpu: ${request_cpu:1}
max_cpu: 1
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Chronokeeper/anyxml v0.0.0-20160530174208-54457d8e98c6 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet v2.1.2+incompatible // indirect
github.com/googlecloudplatform/flink-operator v0.0.0-00010101000000-000000000000
github.com/GoogleCloudPlatform/spark-on-k8s-operator v0.0.0-20201215015655-2e8b733f5ad0
github.com/Masterminds/semver v1.5.0
github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee // indirect
Expand Down Expand Up @@ -50,6 +51,7 @@ require (
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gin-gonic/gin v1.5.0
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-logr/zapr v0.4.0 // indirect
github.com/go-openapi/loads v0.19.4
github.com/go-openapi/spec v0.19.8
github.com/go-playground/validator v9.31.0+incompatible
Expand Down Expand Up @@ -128,7 +130,10 @@ require (
github.com/xormplus/core v0.0.0-20181016121923-6bfce2eb8867
github.com/xormplus/xorm v0.0.0-20181212020813-da46657160ff
github.com/ziutek/mymysql v1.5.4 // indirect
go.uber.org/atomic v1.8.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/ratelimit v0.2.0
go.uber.org/zap v1.17.0 // indirect
golang.org/x/net v0.0.0-20210421230115-4e50805a0758
golang.org/x/sys v0.0.0-20210421221651-33663a62ff08 // indirect
golang.org/x/text v0.3.6
Expand Down Expand Up @@ -162,6 +167,7 @@ require (
)

replace (
github.com/googlecloudplatform/flink-operator => github.com/googlecloudplatform/flink-on-k8s-operator v0.0.0-20200909223554-f302312417ee
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.5
github.com/google/gnostic => github.com/googleapis/gnostic v0.4.0
github.com/influxdata/influxql => github.com/erda-project/influxql v1.1.0-ex
Expand Down
18 changes: 13 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgk
github.com/cheggaaa/pb/v3 v3.0.1/go.mod h1:SqqeMF/pMOIu3xgGoxtPYhMNQP258xE4x/XRTYua+KU=
github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
github.com/chengjoey/flink-on-k8s-operator v0.0.1 h1:a4zrgATUtbQXFrfz0OAH1C9crs4fojzp2k25oNlgfl0=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github.com/chengjoey/flink-on-k8s-operator v0.0.1/go.mod h1:iltjjRPXWoa06VGEyxokBud/9kONhWOyzKm037QEwRQ=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down Expand Up @@ -451,8 +453,9 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/zapr v0.1.0 h1:h+WVe9j6HAA01niTJPA/kKH0i7e0rLZBCwauQFcRE54=
github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
github.com/go-logr/zapr v0.4.0 h1:uc1uML3hRYL9/ZZPdgHS/n8Nzo+eaYL/Efxkkamf7OM=
github.com/go-logr/zapr v0.4.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
Expand Down Expand Up @@ -703,6 +706,8 @@ github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTV
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk=
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
github.com/googlecloudplatform/flink-on-k8s-operator v0.0.0-20200909223554-f302312417ee h1:cuih4RpKlFWojZpyXrFRxlfSXUxRmyFyWqQ0T6RwE1E=
github.com/googlecloudplatform/flink-on-k8s-operator v0.0.0-20200909223554-f302312417ee/go.mod h1:ZCaJ6lcYClcb7jC2tNRZggURn37MktmUxKUMIMNgHgI=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20180424202546-8dffc02ea1cb/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
Expand Down Expand Up @@ -1599,8 +1604,9 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.8.0 h1:CUhrE4N1rqSE6FM9ecihEjRkLQu8cDfgDyoOs83mEY4=
go.uber.org/atomic v1.8.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/automaxprocs v1.2.0/go.mod h1:YfO3fm683kQpzETxlTGZhGIVmXAhaw3gxeBADbpZtnU=
go.uber.org/automaxprocs v1.3.0/go.mod h1:9CWT6lKIep8U41DDaPiH6eFscnTyjfTANNQNx6LrIcA=
go.uber.org/dig v1.8.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
Expand All @@ -1611,8 +1617,9 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA=
go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
Expand All @@ -1623,8 +1630,9 @@ go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
golang.org/x/build v0.0.0-20190927031335-2835ba2e683f/go.mod h1:fYw7AShPAhGMdXqA9gRadk/CcMsvLlClpE5oBwnS3dM=
golang.org/x/crypto v0.0.0-20180426230345-b49d69b5da94/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -2141,7 +2149,6 @@ honnef.co/go/tools v0.0.1-2019.2.2/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=
honnef.co/go/tools v0.0.1-2020.1.5/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
howett.net/plist v0.0.0-20201203080718-1454fab16a06 h1:QDxUo/w2COstK1wIBYpzQlHX/NqaQTcf9jyz347nI58=
Expand Down Expand Up @@ -2241,4 +2248,5 @@ sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
volcano.sh/volcano v0.0.0-20200615125001-3c3aaf766110/go.mod h1:Tz7NJmAIjXm7J2MhOKL+aRRmPrzRDhaY4i+ZF5WtFEQ=
volcano.sh/volcano v0.4.0/go.mod h1:2sNJRhY/oNg0MYdBYORxozuDhvgZxoyeOvKJww/Tl8A=
20 changes: 13 additions & 7 deletions modules/pipeline/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ type Conf struct {
BuildCacheExpireIn time.Duration `env:"BUILD_CACHE_EXPIRE_IN" default:"168h"`

// bundle
GittarAddr string `env:"GITTAR_ADDR" required:"false"`
OpenAPIAddr string `env:"OPENAPI_ADDR" required:"false"`
EventboxAddr string `env:"EVENTBOX_ADDR" required:"false"`
DiceHubAddr string `env:"DICEHUB_ADDR" required:"false"`
SchedulerAddr string `env:"SCHEDULER_ADDR" required:"false"`
HepaAddr string `env:"HEPA_ADDR" required:"false"`
CollectorAddr string `env:"COLLECTOR_ADDR" required:"false"`
GittarAddr string `env:"GITTAR_ADDR" required:"false"`
OpenAPIAddr string `env:"OPENAPI_ADDR" required:"false"`
EventboxAddr string `env:"EVENTBOX_ADDR" required:"false"`
DiceHubAddr string `env:"DICEHUB_ADDR" required:"false"`
SchedulerAddr string `env:"SCHEDULER_ADDR" required:"false"`
HepaAddr string `env:"HEPA_ADDR" required:"false"`
CollectorAddr string `env:"COLLECTOR_ADDR" required:"false"`
ClusterManagerAddr string `env:"CLUSTER_MANAGER_ADDR" required:"false"`

// public url
GittarPublicURL string `env:"GITTAR_PUBLIC_URL" required:"true"`
Expand Down Expand Up @@ -213,6 +214,11 @@ func CollectorAddr() string {
return cfg.CollectorAddr
}

// ClusterManagerAddr return cluster-manager address
func ClusterManagerAddr() string {
return cfg.ClusterManagerAddr
}

// GittarPublicURL 返回 gittar 的公网地址.
func GittarPublicURL() string {
return cfg.GittarPublicURL
Expand Down
41 changes: 41 additions & 0 deletions modules/pipeline/endpoints/clusterinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2021 Terminus, Inc.
//
// This program is free software: you can use, redistribute, and/or modify
// it under the terms of the GNU Affero General Public License, version 3
// or later ("AGPL"), as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package endpoints

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/sirupsen/logrus"

"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/pkg/http/httpserver"
)

func (e *Endpoints) clusterHook(ctx context.Context, r *http.Request, vars map[string]string) (httpserver.Responser, error) {
req := apistructs.ClusterEvent{}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
errStr := fmt.Sprintf("failed to decode clusterhook request, err: %v", err)
logrus.Error(errStr)
return httpserver.ErrResp(http.StatusBadRequest, "", errStr)
}
if err := e.pipelineSvc.ClusterHook(req); err != nil {
errStr := fmt.Sprintf("failed to handle cluster event, err: %v", err)
logrus.Error(errStr)
return httpserver.ErrResp(http.StatusBadRequest, "", errStr)
}
return httpserver.OkResp(nil)
}
4 changes: 4 additions & 0 deletions modules/pipeline/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/erda-project/erda/modules/pipeline/dbclient"
"github.com/erda-project/erda/modules/pipeline/pipengine/reconciler"
"github.com/erda-project/erda/modules/pipeline/pkg/clusterinfo"
"github.com/erda-project/erda/modules/pipeline/services/actionagentsvc"
"github.com/erda-project/erda/modules/pipeline/services/appsvc"
"github.com/erda-project/erda/modules/pipeline/services/buildartifactsvc"
Expand Down Expand Up @@ -237,5 +238,8 @@ func (e *Endpoints) Routes() []httpserver.Endpoint {
// reports
{Path: "/api/pipeline-reportsets/{pipelineID}", Method: http.MethodGet, Handler: e.queryPipelineReportSet},
{Path: "/api/pipeline-reportsets", Method: http.MethodGet, Handler: e.pagingPipelineReportSets},

// cluster info
{Path: clusterinfo.ClusterHookApiPath, Method: http.MethodPost, Handler: e.clusterHook},
}
}
11 changes: 11 additions & 0 deletions modules/pipeline/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/erda-project/erda/modules/pipeline/pipengine"
"github.com/erda-project/erda/modules/pipeline/pipengine/pvolumes"
"github.com/erda-project/erda/modules/pipeline/pipengine/reconciler"
"github.com/erda-project/erda/modules/pipeline/pkg/clusterinfo"
"github.com/erda-project/erda/modules/pipeline/services/actionagentsvc"
"github.com/erda-project/erda/modules/pipeline/services/appsvc"
"github.com/erda-project/erda/modules/pipeline/services/buildartifactsvc"
Expand Down Expand Up @@ -133,6 +134,11 @@ func do() (*httpserver.Server, error) {
CronNotExecuteCompensate: pipelineSvc.CronNotExecuteCompensateById,
}

// init cluster info before pipeline scheduler task executors init
if err := clusterinfo.Initialize(bdl); err != nil {
return nil, err
}

r, err := reconciler.New(js, etcdctl, bdl, dbClient, actionAgentSvc, extMarketSvc, pipelineFun)
if err != nil {
return nil, fmt.Errorf("failed to init reconciler, err: %v", err)
Expand Down Expand Up @@ -190,6 +196,11 @@ func do() (*httpserver.Server, error) {
return nil, err
}

// register cluster hook after pipeline service start
if err := clusterinfo.RegisterClusterHook(bdl); err != nil {
return nil, err
}

return server, nil
}

Expand Down
Loading