Skip to content

Commit

Permalink
Merge branch 'master' into ensure-pods-unchanged-when-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
weekface committed Oct 15, 2019
2 parents 0c1ddf8 + 39c63b9 commit 91e54d6
Show file tree
Hide file tree
Showing 12 changed files with 13,586 additions and 178 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ check-setup:
@which retool >/dev/null 2>&1 || go get github.com/twitchtv/retool
@GO111MODULE=off retool sync

check: check-setup lint tidy check-static
check: check-setup lint tidy check-static check-crd

check-static:
@ # Not running vet and fmt through metalinter becauase it ends up looking at vendor
Expand All @@ -111,6 +111,9 @@ check-static:
--enable ineffassign \
$$($(PACKAGE_DIRECTORIES))

check-crd:
./hack/crd-groups.sh verify

# TODO: staticcheck is too slow currently
staticcheck:
@echo "gometalinter staticcheck"
Expand Down
34 changes: 34 additions & 0 deletions cmd/to-crdgen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 (
"flag"
"fmt"
"github.com/pingcap/tidb-operator/pkg/to-crdgen/cmd"
"github.com/spf13/pflag"
"os"
)

func main() {
flags := pflag.NewFlagSet("to-crdgen", pflag.ExitOnError)
flag.CommandLine.Parse([]string{})
pflag.CommandLine = flags

command := cmd.NewToCrdGenRootCmd()
if err := command.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e // indirect
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/ant31/crd-validation v0.0.0-20180702145049-30f8a35d0ac2
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
Expand Down Expand Up @@ -33,6 +34,7 @@ require (
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-openapi/spec v0.19.2
github.com/go-sql-driver/mysql v1.4.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
Expand Down Expand Up @@ -116,13 +118,14 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.2.4
k8s.io/api v0.0.0-20181128191700-6db15a15d2d3
k8s.io/apiextensions-apiserver v0.0.0-20190118124337-a384d17938fe // indirect
k8s.io/apiextensions-apiserver v0.0.0-20190118124337-a384d17938fe
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/code-generator v0.0.0-20191003035328-700b1226c0bd
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf
k8s.io/kubernetes v1.12.5
k8s.io/metrics v0.0.0-20190118124808-33c1aed8dc65 // indirect
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/ant31/crd-validation v0.0.0-20180702145049-30f8a35d0ac2 h1:CDDf61yprxfS7bmBPyhH8pxaobD2VbO3d7laAxJbZos=
github.com/ant31/crd-validation v0.0.0-20180702145049-30f8a35d0ac2/go.mod h1:X0noFIik9YqfhGYBLEHg8LJKEwy7QIitLQuFMpKLcPk=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 h1:HD4PLRzjuCVW79mQ0/pdsalOLHJ+FaEoqJLxfltpb2U=
Expand Down
62 changes: 62 additions & 0 deletions hack/crd-groups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

# crd-groups generates crd or verify crd in CI

if [ "$#" -lt 1 ] || [ "${1}" == "--help" ]; then
cat <<EOF
Usage: $(basename $0) <action>
<action> the action tu run ( generate, verify )
Examples:
$(basename $0) generate
EOF
exit 0
fi

ACTION="$1"
shift 1

GO_PKG="github.com/pingcap/tidb-operator"
CI_GO_PATH="/go"
scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
to_crdgen="$scriptdir/../cmd/to-crdgen"
crd_target="$scriptdir/../manifests/crd.yaml"
crd_verify_target="$scriptdir/../manifests/crd-verify.yaml"

GO111MODULE=on go get k8s.io/code-generator/cmd/openapi-gen@kubernetes-1.12.5

function generate_crd {
$1/bin/openapi-gen --go-header-file=$scriptdir/boilerplate.go.txt \
-i $GO_PKG/pkg/apis/pingcap.com/v1alpha1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1 \
-p apis/pingcap.com/v1alpha1 -O openapi_generated -o $scriptdir/../pkg

go install $to_crdgen

$1/bin/to-crdgen generate tidbcluster > $2
$1/bin/to-crdgen generate backup >> $2
$1/bin/to-crdgen generate restore >> $2
$1/bin/to-crdgen generate backupschedule >> $2
}

if test $ACTION == 'generate' ;then
generate_crd $GOPATH $crd_target
elif [ $ACTION == 'verify' ];then

if [[ $GOPATH == /go* ]] ;
then
generate_crd $CI_GO_PATH $crd_verify_target
else
generate_crd $GOPATH $crd_verify_target
fi

r="$(diff "$crd_target" "$crd_verify_target")"
if [[ -n $r ]]; then
echo $crd_target is not latest
exit 1
fi
echo crds are latest
fi

cd $scriptdir/..
go mod tidy
Loading

0 comments on commit 91e54d6

Please sign in to comment.