Skip to content

Commit

Permalink
Update client generation tools, remove k8s dependency, fix lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: WillardHu <[email protected]>
  • Loading branch information
WillardHu committed Jan 17, 2025
1 parent f5f870c commit 8d8d949
Show file tree
Hide file tree
Showing 44 changed files with 327 additions and 227 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.9

- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.9

- uses: actions/cache@v2
with:
Expand All @@ -78,7 +78,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.9

- uses: actions/cache@v2
with:
Expand All @@ -102,7 +102,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.9

- uses: actions/cache@v2
with:
Expand All @@ -114,7 +114,7 @@ jobs:
# since this ubuntu-latest os has already kind/kubectl/jq(see https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2004-Readme.md),
# but kind v0.19.0 has different api with v0.18.0, so here to reinstall kind v0.18.0
sudo apt-get install -y jq
go get sigs.k8s.io/kind@$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/97518847 | jq -r .tag_name)
go install sigs.k8s.io/kind@$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/97518847 | jq -r .tag_name)
kind version
type kubectl || {
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Expand All @@ -137,7 +137,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.9

- uses: actions/cache@v2
with:
Expand All @@ -158,7 +158,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.22.9

- uses: actions/cache@v2
with:
Expand Down
56 changes: 46 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,49 @@ run:
# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
issues:
# Which dirs to exclude: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
# Default: []
exclude-dirs:
- vendor
- fake
- externalversions
exclude-dirs-use-default: true

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
# The formats used to render issues.
# Formats:
# - `colored-line-number`
# - `line-number`
# - `json`
# - `colored-tab`
# - `tab`
# - `html`
# - `checkstyle`
# - `code-climate`
# - `junit-xml`
# - `junit-xml-extended`
# - `github-actions`
# - `teamcity`
# - `sarif`
# Output path can be either `stdout`, `stderr` or path to the file to write to.
#
# For the CLI flag (`--out-format`), multiple formats can be specified by separating them by comma.
# The output can be specified for each of them by separating format name and path by colon symbol.
# Example: "--out-format=checkstyle:report.xml,json:stdout,colored-line-number"
# The CLI flag (`--out-format`) override the configuration file.
#
# Default:
# formats:
# - format: colored-line-number
# path: stdout
formats:
- format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand All @@ -41,13 +69,21 @@ linters-settings:
misspell:
ignore-words:
- mosquitto
revive:
rules:
- name: unused-parameter
severity: warning
disabled: true
- name: unused-receiver
severity: warning
disabled: true

linters:
disable-all: true
enable:
- goconst
- gofmt
- golint
- revive
- gosimple
- govet
- misspell
Expand Down
4 changes: 2 additions & 2 deletions build/gm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Add cross buildx improvement
# _speed_buildx_for_go_
FROM golang:1.16-alpine3.15 AS builder
FROM golang:1.22.9-alpine3.19 AS builder
LABEL stage=builder

ARG GO_LDFLAGS
Expand All @@ -31,7 +31,7 @@ RUN make build WHAT=gm GO_LDFLAGS=$GO_LDFLAGS OUT_DIR=_output
# ALT: just using go build
# RUN CGO_ENABLED=0 go build -o _output/bin/sedna-gm -ldflags "$GO_LDFLAGS -w -s" cmd/sedna-gm/sedna-gm.go

FROM alpine:3.11
FROM alpine:3.19

COPY --from=builder /code/_output/bin/sedna-gm /usr/local/bin/sedna-gm

Expand Down
4 changes: 2 additions & 2 deletions build/lc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Add cross buildx improvement
# LC has built sqlite3 which requires CGO with CGO_ENABLED=1
# _speed_buildx_for_cgo_alpine_
FROM golang:1.16-alpine3.15 AS builder
FROM golang:1.22.9-alpine3.19 AS builder
LABEL stage=builder

ARG GO_LDFLAGS
Expand All @@ -30,7 +30,7 @@ COPY . .
RUN make build WHAT=lc GO_LDFLAGS=$GO_LDFLAGS OUT_DIR=_output


FROM alpine:3.11
FROM alpine:3.19

COPY --from=builder /code/_output/bin/sedna-lc /usr/local/bin/sedna-lc

Expand Down
27 changes: 18 additions & 9 deletions hack/generate-groups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ shift 4
# To support running this script from anywhere, we have to first cd into this directory
# so we can install the tools.
cd "$(dirname "${0}")"
GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
GOFLAGS=-mod=vendor go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
)

function codegen::join() { local IFS="$1"; shift; echo "$*"; }
Expand All @@ -65,25 +65,34 @@ done

if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
echo "Generating deepcopy funcs"
"${GOPATH}/bin/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@"
"${GOPATH}/bin/deepcopy-gen" --output-file zz_generated.deepcopy.go "${FQ_APIS[@]}" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
"${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
"${GOPATH}/bin/client-gen" \
--clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" \
--input-base "" \
--input "$(codegen::join , "${FQ_APIS[@]}")" \
--output-pkg "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" \
--output-dir "pkg/client/${CLIENTSET_PKG_NAME:-clientset}" \
"$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${GOPATH}/bin/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
"${GOPATH}/bin/lister-gen" \
--output-pkg "${OUTPUT_PKG}/listers" "$@" \
--output-dir "pkg/client/listers" \
"${FQ_APIS[@]}" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${GOPATH}/bin/informer-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-package "${OUTPUT_PKG}/informers" \
"$@"
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-pkg "${OUTPUT_PKG}/informers" \
--output-dir "pkg/client/informers" \
"${FQ_APIS[@]}" "$@"
fi
2 changes: 1 addition & 1 deletion hack/make-rules/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export PATH=$PATH:$(go env GOPATH)/bin

install_golangci-lint() {
echo "installing golangci-lint."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.34.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
if [[ $? -ne 0 ]]; then
echo "failed to install golangci-lint, exiting."
exit 1
Expand Down
30 changes: 15 additions & 15 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source ${SEDNA_ROOT}/hack/lib/init.sh

${SEDNA_ROOT}/hack/generate-groups.sh "deepcopy,client,informer,lister" \
${SEDNA_GO_PACKAGE}/pkg/client ${SEDNA_GO_PACKAGE}/pkg/apis \
"sedna:v1alpha1" \
--go-header-file ${SEDNA_ROOT}/hack/boilerplate/boilerplate.generatego.txt
${SEDNA_GO_PACKAGE}/pkg/client ${SEDNA_GO_PACKAGE}/pkg/apis \
"sedna:v1alpha1" \
--go-header-file ${SEDNA_ROOT}/hack/boilerplate/boilerplate.generatego.txt

# Check if Sedna home is different from the standard directory where GO projects are located
if ! [[ "${GOPATH}/src/${SEDNA_GO_PACKAGE}/" -ef "${SEDNA_ROOT}/" ]]; then
# Copy generated code into SEDNA_ROOT
echo "Warning: ${SEDNA_ROOT} not included in $GOPATH which is required by code-gen"
echo "Moving generated code from ${GOPATH}/src/${SEDNA_GO_PACKAGE}/pkg/ to ${SEDNA_ROOT}/"
rsync -a ${GOPATH}/src/${SEDNA_GO_PACKAGE}/pkg/{client,apis} ${SEDNA_ROOT}/pkg
if [ $? -eq 0 ]; then
echo "Copy successful!"
rm -rf ${GOPATH}/src/${SEDNA_GO_PACKAGE}/pkg/{client,apis}
else
echo "Error during copy of the generated code!" >&2
fi
fi
# if ! [[ "${GOPATH}/src/${SEDNA_GO_PACKAGE}/" -ef "${SEDNA_ROOT}/" ]]; then
# # Copy generated code into SEDNA_ROOT
# echo "Warning: ${SEDNA_ROOT} not included in $GOPATH which is required by code-gen"
# echo "Moving generated code from ${GOPATH}/src/${SEDNA_GO_PACKAGE}/pkg/ to ${SEDNA_ROOT}/"
# rsync -a ${GOPATH}/src/${SEDNA_GO_PACKAGE}/pkg/{client,apis} ${SEDNA_ROOT}/pkg
# if [ $? -eq 0 ]; then
# echo "Copy successful!"
# rm -rf ${GOPATH}/src/${SEDNA_GO_PACKAGE}/pkg/{client,apis}
# else
# echo "Error during copy of the generated code!" >&2
# fi
# fi
50 changes: 16 additions & 34 deletions hack/update-vendor-licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
# KubeEdge Authors:
# - File derived from kubernetes v1.19.0-beta.2
# - Changed KUBE_ROOT value to use absolute path
# - skip license for k8s.io/klog


set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${KUBE_ROOT}/hack/lib/util.sh"
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"

export LANG=C
export LC_ALL=C
Expand Down Expand Up @@ -143,7 +142,7 @@ process_content () {
#############################################################################

export GO111MODULE=on
export GOFLAGS=-mod=mod
export GOFLAGS=-mod=readonly

# Check bash version
if (( BASH_VERSINFO[0] < 4 )); then
Expand All @@ -165,7 +164,7 @@ cd "${LICENSE_ROOT}"

kube::util::ensure-temp-dir

# Save the genreated LICENSE file for each package temporarily
# Save the generated LICENSE file for each package temporarily
TMP_LICENSE_FILE="${KUBE_TEMP}/LICENSES.$$"

# The directory to save all the LICENSE files
Expand All @@ -183,7 +182,7 @@ declare -Ag CONTENT
if [ -f "${LICENSE_ROOT}/LICENSE" ]; then
(
echo "================================================================================"
echo "= Sedna licensed under: ="
echo "= KubeEdge licensed under: ="
echo
cat "${LICENSE_ROOT}/LICENSE"
echo
Expand All @@ -193,8 +192,10 @@ if [ -f "${LICENSE_ROOT}/LICENSE" ]; then
mv "${TMP_LICENSE_FILE}" "${TMP_LICENSES_DIR}/LICENSE"
fi

# Capture all module dependencies
modules=$(go list -m -json all | jq -r .Path | sort -f)
# Loop through every vendored package
for PACKAGE in $(go list -m -json all | jq -r .Path | sort -f); do
for PACKAGE in ${modules}; do
if [[ -e "staging/src/${PACKAGE}" ]]; then
echo "${PACKAGE} is a staging package, skipping" >&2
continue
Expand All @@ -203,34 +204,15 @@ for PACKAGE in $(go list -m -json all | jq -r .Path | sort -f); do
echo "${PACKAGE} doesn't exist in ${DEPS_DIR}, skipping" >&2
continue
fi
if [[ "${PACKAGE}" = "sigs.k8s.io/structured-merge-diff" ]]; then
# this package doesn't exist, but has v3 subdirectory as a different package
# so it can't be filtered by the previous rule
# temporarily treat this way until find out a better rule
echo "${PACKAGE}, temporarily skipping" >&2
continue
fi
if [[ "${PACKAGE}" = "github.com/cespare/xxhash" ]]; then
# there are 2 versions v1 and v2 under 2 folders indirectly used
# so it can't be filtered by the previous rule
# temporarily treat this way until find out a better rule
echo "${PACKAGE}, temporarily skipping" >&2
continue
fi
if [[ "${PACKAGE}" = "k8s.io/klog" ]]; then
# this package doesn't use, but has v2 subdirectory as a different package
# so it can't be filtered by the previous rule
# temporarily treat this way until find out a better rule
echo "${PACKAGE}, temporarily skipping" >&2
continue
fi
if [[ "${PACKAGE}" = "github.com/emicklei/go-restful" ]]; then
# this package doesn't use, but has v3 subdirectory as a different package
# so it can't be filtered by the previous rule
# temporarily treat this way until find out a better rule
echo "${PACKAGE}, temporarily skipping" >&2
continue
# if there are no files vendored under this package...
if [[ -z "$(find "${DEPS_DIR}/${PACKAGE}" -mindepth 1 -maxdepth 1 -type f)" ]]; then
# and we have at least the same number of submodules as subdirectories...
if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -le "$(echo "${modules}" | grep -cE "^${PACKAGE}/")" ]]; then
echo "Only submodules of ${PACKAGE} are vendored, skipping" >&2
continue
fi
fi

echo "${PACKAGE}"

process_content "${PACKAGE}" LICENSE
Expand Down
1 change: 1 addition & 0 deletions hack/update-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -o errexit
set -o nounset
set -o pipefail


echo "running 'go mod tidy'"
go mod tidy

Expand Down
4 changes: 3 additions & 1 deletion hack/verify-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ SEDNA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"

UPDATE_SCRIPT=hack/update-vendor.sh
${SEDNA_ROOT}/${UPDATE_SCRIPT}


git status

if git status --short 2>/dev/null | grep -qE 'go\.mod|go\.sum|vendor/'; then
echo "FAILED: vendor verify failed." >&2
echo "Please run the command to update your vendor directories: $UPDATE_SCRIPT" >&2
Expand Down
Loading

0 comments on commit 8d8d949

Please sign in to comment.