Skip to content

Commit

Permalink
Support nacos discovery (alibaba#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni authored Dec 14, 2022
1 parent e01377f commit bf607ae
Show file tree
Hide file tree
Showing 69 changed files with 3,312 additions and 317 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fetch-depth: 2

- name: "run go build"
run: make build
run: GOPROXY="https://proxy.golang.org,direct" make build

- name: "run go test and out codecov"
run: make prebuild; go test ./cmd/... ./pkg/... -race -coverprofile=coverage.out -covermode=atomic
Expand Down
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ header:
- '*.md'
- '*.yml'
- 'LICENSE'
- 'api/**'
- 'samples/**'
- '.github/**'
- '.licenserc.yaml'
- 'helm/**'
Expand Down
15 changes: 12 additions & 3 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export CHARTS ?= higress-registry.cn-hangzhou.cr.aliyuncs.com/charts

GO ?= go

export GOPROXY ?= https://proxy.golang.com.cn,direct

GOARCH_LOCAL := $(TARGET_ARCH)
GOOS_LOCAL := $(TARGET_OS)
RELEASE_LDFLAGS='-extldflags -static -s -w'
Expand Down Expand Up @@ -46,11 +48,11 @@ default: build

.PHONY: build
build: prebuild $(OUT)
GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT)/ $(BINARIES)
GOPROXY=$(GOPROXY) GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT)/ $(BINARIES)

.PHONY: build-linux
build-linux: prebuild $(OUT)
GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT_LINUX)/ $(BINARIES)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT_LINUX)/ $(BINARIES)

# Create targets for OUT_LINUX/binary
# There are two use cases here:
Expand All @@ -63,7 +65,7 @@ ifeq ($(BUILD_ALL),true)
$(OUT_LINUX)/$(shell basename $(1)): build-linux
else
$(OUT_LINUX)/$(shell basename $(1)): $(OUT_LINUX)
GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT_LINUX)/ -tags=$(2) $(1)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT_LINUX)/ -tags=$(2) $(1)
endif
endef

Expand Down Expand Up @@ -111,6 +113,13 @@ helm-push-kind:
cd helm/kind/istio; helm dependency update
cd helm/kind; tar -zcf istio.tgz istio; helm push istio.tgz "oci://$(CHARTS)"

cue = cue-gen -paths=./external/api/common-protos

gen-api: prebuild
cd api;./gen.sh

gen-client: gen-api
cd client; make generate-k8s-client

DIRS_TO_CLEAN := $(OUT)
DIRS_TO_CLEAN += $(OUT_LINUX)
Expand Down
7 changes: 7 additions & 0 deletions Makefile.overrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
BUILD_WITH_CONTAINER ?= 0
CONTAINER_OPTIONS = --mount type=bind,source=/tmp,destination=/tmp --net=host

GENERATE_API ?= 0

ifeq ($(GENERATE_API),1)
BUILD_WITH_CONTAINER = 1
IMAGE_VERSION=release-1.12-2021-11-12T20-52-48
endif

ifeq ($(BUILD_WITH_CONTAINER),1)
# create phony targets for the top-level items in the repo
PHONYS := $(shell ls | grep -v Makefile)
Expand Down
14 changes: 14 additions & 0 deletions api/networking/v1/mcp_bridge.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions api/networking/v1/mcp_bridge_deepcopy.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions api/networking/v1/mcp_bridge_json.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright Istio 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.
# Modified by Higress

########################
# kubernetes code generators
########################
kubetype_gen = kubetype-gen
deepcopy_gen = deepcopy-gen
client_gen = client-gen
lister_gen = lister-gen
informer_gen = informer-gen

empty:=
space := $(empty) $(empty)
comma := ,

# source packages to scan for kubetype-gen tags
kube_source_packages = $(subst $(space),$(empty), \
github.com/alibaba/higress/api/networking/v1 \
)

# base output package for generated files
kube_base_output_package = github.com/alibaba/higress/client/pkg
# base output package for kubernetes types, register, etc...
kube_api_base_package = $(kube_base_output_package)/apis
# source packages to scan for kubernetes generator tags, e.g. deepcopy-gen, client-gen, etc.
# these should correspond to the output packages from kubetype-gen
kube_api_packages = $(subst $(space),$(empty), \
$(kube_api_base_package)/networking/v1 \
)
# base output package used by kubernetes client-gen
kube_clientset_package = $(kube_base_output_package)/clientset
# clientset name used by kubernetes client-gen
kube_clientset_name = versioned
# base output package used by kubernetes lister-gen
kube_listers_package = $(kube_base_output_package)/listers
# base output package used by kubernetes informer-gen
kube_informers_package = $(kube_base_output_package)/informers

# file header text
kube_go_header_text = header.go.txt

ifeq ($(IN_BUILD_CONTAINER),1)
# k8s code generators rely on GOPATH, using $GOPATH/src as the base package
# directory. Using --output-base . does not work, as that ends up generating
# code into ./<package>, e.g. ./istio.io/client-go/pkg/apis/... To work
# around this, we'll just let k8s generate the code where it wants and copy
# back to where it should have been generated.
move_generated=cp -r $(GOPATH)/src/$(kube_base_output_package)/ . && rm -rf $(GOPATH)/src/$(kube_base_output_package)/
else
# nothing special for local builds
move_generated=
endif

rename_generated_files=\
find $(subst github.com/alibaba/higress/client/, $(empty), $(subst $(comma), $(space), $(kube_api_packages)) $(kube_clientset_package) $(kube_listers_package) $(kube_informers_package)) \
-name '*.go' -and -not -name 'doc.go' -and -not -name '*.gen.go' -type f -exec sh -c 'mv "$$1" "$${1%.go}".gen.go' - '{}' \;

.PHONY: generate-k8s-client
generate-k8s-client:
# generate kube api type wrappers for higress types
@$(kubetype_gen) --input-dirs $(kube_source_packages) --output-package $(kube_api_base_package) -h $(kube_go_header_text)
@$(move_generated)
# generate deepcopy for kube api types
@$(deepcopy_gen) --input-dirs $(kube_api_packages) -O zz_generated.deepcopy -h $(kube_go_header_text)
# generate clientsets for kube api types
@$(client_gen) --clientset-name $(kube_clientset_name) --input-base "" --input $(kube_api_packages) --output-package $(kube_clientset_package) -h $(kube_go_header_text)
# generate listers for kube api types
@$(lister_gen) --input-dirs $(kube_api_packages) --output-package $(kube_listers_package) -h $(kube_go_header_text)
# generate informers for kube api types
@$(informer_gen) --input-dirs $(kube_api_packages) --versioned-clientset-package $(kube_clientset_package)/$(kube_clientset_name) --listers-package $(kube_listers_package) --output-package $(kube_informers_package) -h $(kube_go_header_text)
@$(move_generated)
@$(rename_generated_files)


.PHONY: clean-k8s-client
clean-k8s-client:
# remove generated code
@rm -rf pkg/
13 changes: 13 additions & 0 deletions client/header.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// 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.
21 changes: 21 additions & 0 deletions client/pkg/apis/networking/v1/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions client/pkg/apis/networking/v1/register.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions client/pkg/apis/networking/v1/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bf607ae

Please sign in to comment.