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

Support debug and ctop commands in CLI #387

Merged
merged 15 commits into from
Apr 17, 2019
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ coverage.txt
/_tools/
vendor
tests/e2e/e2e.test
.orig
tkc
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ ifeq ($(GO111), 1)
$(error Please upgrade your Go compiler to 1.11 or higher version)
endif

GOENV := GO15VENDOREXPERIMENT="1" GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64
GOOS := $(if $(GOOS),$(GOOS),linux)
GOARCH := $(if $(GOARCH),$(GOARCH),amd64)
GOENV := GO15VENDOREXPERIMENT="1" GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH)
GO := $(GOENV) go build
GOTEST := CGO_ENABLED=0 GO111MODULE=on go test -v -cover

Expand Down Expand Up @@ -120,4 +122,20 @@ check-gosec:
@echo "security checking"
CGO_ENABLED=0 retool do gosec $$($(PACKAGE_DIRECTORIES))

.PHONY: check check-setup check-all build e2e-build
cli:
$(GO) -ldflags '$(LDFLAGS)' -o tkc cmd/tkctl/main.go

debug-docker-push: debug-build-docker
docker push "${DOCKER_REGISTRY}/pingcap/debug-launcher:latest"
docker push "${DOCKER_REGISTRY}/pingcap/tidb-control:latest"
docker push "${DOCKER_REGISTRY}/pingcap/tidb-debug:latest"

debug-build-docker: debug-build
docker build -t "${DOCKER_REGISTRY}/pingcap/debug-launcher:latest" misc/images/debug-launcher
docker build -t "${DOCKER_REGISTRY}/pingcap/tidb-control:latest" misc/images/tidb-control
docker build -t "${DOCKER_REGISTRY}/pingcap/tidb-debug:latest" misc/images/tidb-debug

debug-build:
$(GO) -ldflags '$(LDFLAGS)' -o misc/images/debug-launcher/bin/debug-launcher misc/cmd/debug-launcher/main.go

.PHONY: check check-setup check-all build e2e-build debug-build cli
60 changes: 60 additions & 0 deletions ci/release_cli_binary_and_debug_image.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
def call(BUILD_BRANCH, RELEASE_TAG) {

env.GOPATH = "/go"
env.GOROOT = "/usr/local/go"
env.PATH = "${env.GOROOT}/bin:${env.GOPATH}/bin:/bin:${env.PATH}:/home/jenkins/bin"

def GITHASH
def TKC_CLI_PACKAGE = "tkc-${GOOS}-${GOARCH}-${RELEASE_TAG}"

catchError {
node('k8s_centos7_build') {
def WORKSPACE = pwd()

dir("${WORKSPACE}/operator"){
stage('Build and release CLI to qiniu'){
checkout([$class: 'GitSCM', branches: [[name: "${BUILD_BRANCH}"]], userRemoteConfigs:[[url: "${BUILD_URL}", credentialsId: "${CREDENTIALS_ID}"]]])
GITHASH = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
def GOARCH = "amd64"
["linux", "darwin", "windows"].each {
sh """
GOOS=${it} GOARCH=${GOARCH} make cli
tar -zcf ${TKC_CLI_PACKAGE}.tgz tkc
sha256sum ${TKC_CLI_PACKAGE}.tgz > ${TKC_CLI_PACKAGE}.sha256

upload.py ${TKC_CLI_PACKAGE}.tgz ${TKC_CLI_PACKAGE}.tgz
upload.py ${TKC_CLI_PACKAGE}.sha256 ${TKC_CLI_PACKAGE}.sha256
"""
}
}

stage('Build and push debug images'){
withDockerServer([uri: "${env.DOCKER_HOST}"]) {
DOCKER_REGISTRY="" make debug-docker-push
DOCKER_REGISTRY="uhub.service.ucloud.cn" make debug-docker-push
}
}
}
}
currentBuild.result = "SUCCESS"
}
stage('Summary') {
echo("echo summary info ########")
def DURATION = ((System.currentTimeMillis() - currentBuild.startTimeInMillis) / 1000 / 60).setScale(2, BigDecimal.ROUND_HALF_UP)
def slackmsg = "[${env.JOB_NAME.replaceAll('%2F','/')}-${env.BUILD_NUMBER}] `${currentBuild.result}`" + "\n" +
"Elapsed Time: `${DURATION}` Mins" + "\n" +
"tidb-operator Branch: `${BUILD_BRANCH}`, Githash: `${GITHASH.take(7)}`" + "\n" +
"Display URL:" + "\n" +
"${env.RUN_DISPLAY_URL}"

if(currentBuild.result != "SUCCESS"){
slackSend channel: '#cloud_jenkins', color: 'danger', teamDomain: 'pingcap', tokenCredentialId: 'slack-pingcap-token', message: "${slackmsg}"
} else {
slackmsg = "${slackmsg}" + "\n" +
"tkc cli tool build and debug image build failed for BRANCH:${BUILD_BRANCH} and TAG:${RELEASE_TAG}`"
slackSend channel: '#cloud_jenkins', color: 'good', teamDomain: 'pingcap', tokenCredentialId: 'slack-pingcap-token', message: "${slackmsg}"
}
}
}

return this
16 changes: 9 additions & 7 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package main

import (
"context"
"flag"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -120,21 +121,22 @@ func main() {
}

tcController := tidbcluster.NewController(kubeCli, cli, informerFactory, kubeInformerFactory, autoFailover, pdFailoverPeriod, tidbFailoverPeriod)
stop := make(chan struct{})
defer close(stop)
go informerFactory.Start(stop)
go kubeInformerFactory.Start(stop)

onStarted := func(stopCh <-chan struct{}) {
tcController.Run(workers, stopCh)
controllerCtx, cancel := context.WithCancel(context.Background())
defer cancel()
go informerFactory.Start(controllerCtx.Done())
go kubeInformerFactory.Start(controllerCtx.Done())

onStarted := func(ctx context.Context) {
tcController.Run(workers, ctx.Done())
}
onStopped := func() {
glog.Fatalf("leader election lost")
}

// leader election for multiple tidb-cloud-manager
go wait.Forever(func() {
leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{
leaderelection.RunOrDie(controllerCtx, leaderelection.LeaderElectionConfig{
Lock: &rl,
LeaseDuration: leaseDuration,
RenewDeadline: renewDuration,
Expand Down
40 changes: 40 additions & 0 deletions cmd/tkctl/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019. PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"os"

"github.com/pingcap/tidb-operator/pkg/tkctl/cmd"
"github.com/spf13/pflag"

"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/util/logs"
)

func main() {
flags := pflag.NewFlagSet("tkc", pflag.ExitOnError)
pflag.CommandLine = flags

command := cmd.NewTkcCommand(genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr})

logs.InitLogs()
defer logs.FlushLogs()

if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
62 changes: 45 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,83 @@ module github.com/pingcap/tidb-operator

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
github.com/coreos/bbolt v1.3.1-coreos.6 // indirect
github.com/coreos/etcd v0.0.0-20180530235116-2b3aa7e1d49d // indirect
github.com/coreos/go-semver v0.2.0 // indirect
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 // indirect
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dnephin/govet v0.0.0-20171012192244-4a96d43e39d3
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v0.7.3-0.20171023200535-7848b8beb9d3
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.3.3 // indirect
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect
github.com/emicklei/go-restful v2.8.0+incompatible
github.com/evanphx/json-patch v4.1.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-openapi/spec v0.18.0 // indirect
github.com/go-sql-driver/mysql v1.4.0
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
github.com/golang/protobuf v1.1.0 // indirect
github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2 // indirect
github.com/gorilla/websocket v1.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.4.1 // indirect
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 // indirect
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c // indirect
github.com/hpcloud/tail v1.0.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/jinzhu/copier v0.0.0-20180308034124-7e38e58719c3
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/json-iterator/go v1.1.5 // indirect
github.com/juju/errors v0.0.0-20180806074554-22422dad46e1
github.com/juju/loggo v0.0.0-20180524022052-584905176618 // indirect
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/onsi/ginkgo v1.6.0
github.com/onsi/gomega v1.4.1
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pingcap/check v0.0.0-20171206051426-1c287c953996 // indirect
github.com/pingcap/errors v0.11.0
github.com/pingcap/kvproto v0.0.0-20180606093822-b7ba8ea1c0b4
github.com/pingcap/pd v2.1.0-beta+incompatible
github.com/pkg/errors v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v0.8.0
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e // indirect
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 // indirect
github.com/sirupsen/logrus v1.0.6 // indirect
github.com/renstrom/dedent v1.1.0 // indirect
github.com/russross/blackfriday v1.5.2+incompatible // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.0.6
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/spf13/pflag v1.0.1 // indirect
github.com/stretchr/testify v1.2.2 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
github.com/ugorji/go v1.1.1 // indirect
github.com/unrolled/render v0.0.0-20180807193321-4206df6ff701 // indirect
Expand All @@ -66,12 +87,10 @@ require (
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1 // indirect
golang.org/x/crypto v0.0.0-20180807104621-f027049dab0a // indirect
golang.org/x/net v0.0.0-20180808004115-f9ce57c11b24
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 // indirect
golang.org/x/sys v0.0.0-20180807162357-acbc56fc7007 // indirect
golang.org/x/text v0.3.0 // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
google.golang.org/appengine v1.1.0 // indirect
google.golang.org/genproto v0.0.0-20180731170733-daca94659cb5 // indirect
google.golang.org/grpc v1.12.0 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
Expand All @@ -80,13 +99,22 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3 // indirect
gopkg.in/square/go-jose.v2 v2.3.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.2.1
k8s.io/api v0.0.0-20180308224125-73d903622b73
k8s.io/apiextensions-apiserver v0.0.0-20180426153726-e8ab413e0ae1 // indirect
k8s.io/apimachinery v0.0.0-20180228050457-302974c03f7e
k8s.io/apiserver v0.0.0-20180807214737-1b22bcf04547
k8s.io/client-go v0.0.0-20180424211516-33f2870a2b83
k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c // indirect
k8s.io/kubernetes v1.10.2
k8s.io/api v0.0.0-20181128191700-6db15a15d2d3
k8s.io/apiextensions-apiserver v0.0.0-20190118124337-a384d17938fe // indirect
k8s.io/apimachinery v0.0.0-20181128191346-49ce2735e507
k8s.io/apiserver v0.0.0-20190118115647-a748535592ba
k8s.io/cli-runtime v0.0.0-20190118125240-caee4253d968
k8s.io/client-go v2.0.0-alpha.0.0.20190115164855-701b91367003+incompatible
k8s.io/klog v0.2.0 // indirect
k8s.io/kube-openapi v0.0.0-20190320154901-5e45bb682580 // indirect
k8s.io/kubernetes v1.12.5
k8s.io/metrics v0.0.0-20190118124808-33c1aed8dc65 // indirect
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
sigs.k8s.io/yaml v1.1.0 // indirect
vbom.ml/util v0.0.0-20180919145318-efcd4e0f9787 // indirect
)

replace github.com/renstrom/dedent => github.com/lithammer/dedent v1.1.0
Loading