Skip to content

Commit

Permalink
ci: make presubmit check workflow work
Browse files Browse the repository at this point in the history
Signed-off-by: jwcesign <[email protected]>
  • Loading branch information
jwcesign committed Sep 26, 2024
1 parent 7f3c390 commit af07632
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 1,632 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pre-submit check

on:
push:
branches: [ "main" ]
pull_request: {}

permissions:
contents: read
pull-requests: read

jobs:
presubmit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: false

- name: Install toolchain
run: |
make toolchain
- name: Presubmit check
run: |
make presubmit
25 changes: 9 additions & 16 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ linters:
- goheader
- misspell
- nilerr
- gci
disable:
- prealloc
- unused
linters-settings:
gocyclo:
min-complexity: 11
Expand All @@ -41,22 +43,13 @@ linters-settings:
locale: US
ignore-words: []
goimports:
local-prefixes: github.com/aws/karpenter-provider-aws
goheader:
template: |-
Copyright 2024 The CloudPilot AI Authors.
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,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
local-prefixes: github.com/cloudpilot-ai/karpenter-provider-alicloud
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
skip-generated: true
issues:
fix: true
exclude: ['declaration of "(err|ctx)" shadows declaration at']
Expand Down
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST_SUITE ?= "..."
help: ## Display help
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

presubmit: verify ut-test ## Run all steps in the developer loop
presubmit: update verify ut-test ## Run all steps in the developer loop

toolchain: ## Install developer toolchain
./hack/toolchain.sh
Expand All @@ -39,18 +39,21 @@ run: ## Run Karpenter controller binary against your local cluster
FEATURE_GATES="SpotToSpotConsolidation=true" \
go run ./cmd/controller/main.go

verify: tidy ## Verify code. Includes linting, formatting, etc
go generate ./...
update: tidy download ## Update go files header, CRD and generated code
hack/boilerplate.sh
hack/update-generated.sh

verify: ## Verify code. Includes linting, formatting, etc
golangci-lint run

image: ## Build the Karpenter controller images using ko build
$(eval CONTROLLER_IMG=$(shell $(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO="$(KO_DOCKER_REPO)" ko build --bare github.com/cloudpilot-ai/karpenter-provider-alicloud/cmd/controller))
$(eval IMG_REPOSITORY=$(shell echo $(CONTROLLER_IMG) | cut -d "@" -f 1 | cut -d ":" -f 1))
$(eval IMG_TAG=$(shell echo $(CONTROLLER_IMG) | cut -d "@" -f 1 | cut -d ":" -f 2 -s))
$(eval IMG_DIGEST=$(shell echo $(CONTROLLER_IMG) | cut -d "@" -f 2))

apply: verify image ## Deploy the controller from the current state of your git repository into your ~/.kube/config cluster
kubectl apply -f ./pkg/apis/crds/
apply: image ## Deploy the controller from the current state of your git repository into your ~/.kube/config cluster
kubectl apply -f ./config/components/crds/
helm upgrade --install karpenter charts/karpenter --namespace ${KARPENTER_NAMESPACE} \
$(HELM_OPTS) \
--set logLevel=debug \
Expand All @@ -68,10 +71,13 @@ ut-test: ## Run unit tests
coverage:
go tool cover -html coverage.out -o coverage.html

tidy: ## Recursively "go mod tidy"
tidy: ## Run "go mod tidy"
go mod tidy

.PHONY: help presubmit run ut-test coverage verify image apply delete toolchain tidy
download: ## Run "go mod download"
go mod download

.PHONY: help presubmit run ut-test coverage update verify image apply delete toolchain tidy download

define newline

Expand Down
768 changes: 37 additions & 731 deletions config/components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ go 1.23

require (
github.com/awslabs/operatorpkg v0.0.0-20240805231134-67d0acfb6306
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/samber/lo v1.46.0
go.uber.org/multierr v1.11.0
k8s.io/api v0.30.3
k8s.io/apimachinery v0.30.3
k8s.io/client-go v0.30.3
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/karpenter v1.0.1
sigs.k8s.io/yaml v1.4.0
)

require (
Expand Down Expand Up @@ -49,6 +50,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand All @@ -64,7 +66,6 @@ require (
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.27.0 // indirect
Expand Down Expand Up @@ -93,5 +94,4 @@ require (
knative.dev/pkg v0.0.0-20230712131115-7051d301e7f4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
15 changes: 15 additions & 0 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2024 The CloudPilot AI Authors.

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,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
4 changes: 2 additions & 2 deletions hack/boilerplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
set -eu -o pipefail

for i in $(
find ./tools ./cmd ./pkg ./test ./hack -name "*.go"
find ./cmd ./pkg ./hack -name "*.go"
); do
if ! grep -q "Apache License" $i; then
if ! grep -q "CloudPilot AI" $i; then
cat hack/boilerplate.go.txt $i >$i.new && mv $i.new $i
fi
done
19 changes: 10 additions & 9 deletions hack/toolchain.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ main() {
}

tools() {
go install github.com/google/go-licenses@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/google/ko@latest
go install github.com/mikefarah/yq/v4@latest
go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
go install github.com/google/go-licenses@v1.6.0
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
go install github.com/google/ko@v0.16.0
go install github.com/mikefarah/yq/v4@v4.44.3
go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest
go install github.com/sigstore/cosign/v2/cmd/cosign@latest
go install -tags extended github.com/gohugoio/[email protected]
go install golang.org/x/vuln/cmd/govulncheck@latest
go install github.com/onsi/ginkgo/v2/ginkgo@latest
go install github.com/rhysd/actionlint/cmd/actionlint@latest
go install github.com/mattn/goveralls@latest
go install github.com/onsi/ginkgo/v2/ginkgo@v2.20.2
go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.2
go install github.com/mattn/goveralls@v0.0.12
go install github.com/google/go-containerregistry/cmd/crane@latest
go install oras.land/oras/cmd/oras@latest
go install oras.land/oras/cmd/[email protected]
go install k8s.io/code-generator/cmd/[email protected]

if ! echo "$PATH" | grep -q "${GOPATH:-undefined}/bin\|$HOME/go/bin"; then
echo "Go workspace's \"bin\" directory is not in PATH. Run 'export PATH=\"\$PATH:\${GOPATH:-\$HOME/go}/bin\"'."
Expand Down
35 changes: 35 additions & 0 deletions hack/update-generated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -eu -o pipefail

# Update CRD
controller-gen crd paths=./pkg/apis/v1alpha1/... output:crd:dir=./config/components/crds

# Update generated code
export REPO_ROOT=$(pwd)
export GOPATH="${REPO_ROOT}/_go"

cleanup() {
# TODO: In github action, it needs root privilege to delete this dir
sudo rm -rf "${GOPATH}"
}
trap "cleanup" EXIT SIGINT

echo $REPO_ROOT
echo $GOPATH

KARPENTER_GO_PACKAGE="github.com/cloudpilot-ai/karpenter-provider-alicloud"
GO_PKG_DIR=$(dirname "${GOPATH}/src/${KARPENTER_GO_PACKAGE}")
mkdir -p "${GO_PKG_DIR}"

echo $KARPENTER_GO_PACKAGE
echo $GO_PKG_DIR

if [[ ! -e "${GO_PKG_DIR}" || "$(readlink "${GO_PKG_DIR}")" != "${REPO_ROOT}" ]]; then
ln -snf "${REPO_ROOT}" "${GO_PKG_DIR}"
fi

deepcopy-gen \
--go-header-file hack/boilerplate.go.txt \
--output-file-base zz_generated.deepcopy \
--input-dirs github.com/cloudpilot-ai/karpenter-provider-alicloud/pkg/apis/v1alpha1
4 changes: 1 addition & 3 deletions pkg/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import (
"sigs.k8s.io/karpenter/pkg/apis"
)

//go:generate controller-gen crd object:headerFile="../../hack/boilerplate.go.txt" paths="./..." output:crd:artifacts:config=crds
var (
Group = "karpenter.k8s.alicloud"
CompatibilityGroup = "compatibility." + Group
CRDs = append(apis.CRDs) // object.Unmarshal[apiextensionsv1.CustomResourceDefinition](crds.ECSNodeClassCRD)

CRDs = apis.CRDs // object.Unmarshal[apiextensionsv1.CustomResourceDefinition](crds.ECSNodeClassCRD)
)
37 changes: 37 additions & 0 deletions pkg/apis/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2024 The CloudPilot AI Authors.
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,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +groupName=karpenter.k8s.alicloud
package v1alpha1

import (
corev1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"

"github.com/cloudpilot-ai/karpenter-provider-alicloud/pkg/apis"
)

func init() {
gv := schema.GroupVersion{Group: apis.Group, Version: "v1"}
corev1.AddToGroupVersion(scheme.Scheme, gv)
scheme.Scheme.AddKnownTypes(gv,
&ECSNodeClass{},
&ECSNodeClassList{},
)
}
Loading

0 comments on commit af07632

Please sign in to comment.