Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
randomvariable committed Feb 1, 2019
1 parent 7a9f9f4 commit acd6dbc
Show file tree
Hide file tree
Showing 81 changed files with 5,027 additions and 911 deletions.
5 changes: 4 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
build --workspace_status_command=./hack/print-workspace-status.sh
build --verbose_failures
build --define=MANAGER_IMAGE_NAME=cluster-api-aws-controller
build --define=MANAGER_IMAGE_TAG=0.0.3
build --define=REGISTRY_STABLE=gcr.io/cluster-api-provider-aws

build --workspace_status_command=./hack/print-workspace-status.sh
run --workspace_status_command=./hack/print-workspace-status.sh

test --features=race --test_output=errors
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ kind.kubeconfig
minikube.kubeconfig
kubeconfig

# vscode debugging bits
hack/scratch

# binaries
/manager
/clusterctl
Expand Down
28 changes: 21 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ package(default_visibility = ["//visibility:public"])
# gazelle:exclude vendor/github.com/golang/dep/cmd/dep/testdata
gazelle(
name = "gazelle",
build_tags = ["integration"],
command = "fix",
external = "vendored",
build_tags = ["integration"],
)

filegroup(
Expand All @@ -54,6 +54,15 @@ workspace_binary(
cmd = "@com_github_golang_dep//cmd/dep",
)

filegroup(
name = "mocks",
srcs = [
"//pkg/cloud/aws/services/ec2/mock_ec2iface:go_default_library",
"//pkg/cloud/aws/services/elb/mock_elbiface:go_default_library",
"//pkg/cloud/aws/services/mocks:go_mock_interfaces",
],
)

workspace_binary(
name = "generate",
args = [
Expand All @@ -76,22 +85,27 @@ workspace_binary(
cmd = "@com_github_golangci_golangci-lint//cmd/golangci-lint",
)

workspace_binary(
name = "kind-reset",
args = ["delete cluster --name=clusterapi"],
cmd = "@io_k8s_sigs_kind//:kind",
ignore_error = True,
)

filegroup(
name = "all-srcs",
srcs = glob(["**"]),
)

filegroup(
name = "cluster-api-kustomize-yaml",
name = "kubebuilder-api",
srcs = glob([
"vendor/sigs.k8s.io/cluster-api/config/crds/*.yaml",
"vendor/sigs.k8s.io/cluster-api/config/rbac/*.yaml",
"vendor/sigs.k8s.io/cluster-api/config/manager/*.yaml",
"vendor/sigs.k8s.io/cluster-api/config/default/*.yaml",
"pkg/apis:go_default_library",
"pkg/controller:go_default_library",
]),
visibility = ["//visibility:public"],
)

exports_files(glob([
"WORKSPACE",
"PROJECT",
]))
9 changes: 9 additions & 0 deletions Gopkg.lock

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

121 changes: 30 additions & 91 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@
FASTBUILD ?= n ## Set FASTBUILD=y (case-sensitive) to skip some slow tasks

## Image URL to use all building/pushing image targets
STABLE_DOCKER_REPO ?= gcr.io/cluster-api-provider-aws
MANAGER_IMAGE_NAME ?= cluster-api-aws-controller
MANAGER_IMAGE_TAG ?= 0.0.3
MANAGER_IMAGE ?= $(STABLE_DOCKER_REPO)/$(MANAGER_IMAGE_NAME):$(MANAGER_IMAGE_TAG)
DEV_DOCKER_REPO ?= gcr.io/$(shell gcloud config get-value project)
DEV_MANAGER_IMAGE ?= $(DEV_DOCKER_REPO)/$(MANAGER_IMAGE_NAME):$(MANAGER_IMAGE_TAG)

REGISTRY_DEV ?= gcr.io/$(shell gcloud config get-value project)
DEPCACHEAGE ?= 24h # Enables caching for Dep
BAZEL_ARGS ?=
BAZEL_DOCKER_ARGS := --define=REGISTRY_DEV=$(REGISTRY_DEV) $(BAZEL_ARGS)

# Bazel variables
BAZEL_VERSION := $(shell command -v bazel 2> /dev/null)
Expand All @@ -37,8 +32,11 @@ DEP ?= bazel run dep
# determine the OS
HOSTOS := $(shell go env GOHOSTOS)
HOSTARCH := $(shell go env GOARCH)
GOPATH := $(shell go env GOPATH)
BINARYPATHPATTERN :=${HOSTOS}_${HOSTARCH}_*

export GOPATH

ifndef BAZEL_VERSION
$(error "Bazel is not available. \
Installation instructions can be found at \
Expand Down Expand Up @@ -70,25 +68,9 @@ gazelle: ## Run Bazel Gazelle
check-install: ## Checks that you've installed this repository correctly
@./scripts/check-install.sh

.PHONY: manager
manager: generate ## Build manager binary.
bazel build //cmd/manager $(BAZEL_ARGS)
install bazel-bin/cmd/manager/${BINARYPATHPATTERN}/manager $(shell go env GOPATH)/bin/aws-manager

.PHONY: clusterctl
clusterctl: generate ## Build clusterctl binary.
bazel build --workspace_status_command=./hack/print-workspace-status.sh //cmd/clusterctl $(BAZEL_ARGS)
install bazel-bin/cmd/clusterctl/${BINARYPATHPATTERN}/clusterctl $(shell go env GOPATH)/bin/clusterctl

.PHONY: clusterawsadm
clusterawsadm: dep-ensure ## Build clusterawsadm binary.
bazel build --workspace_status_command=./hack/print-workspace-status.sh //cmd/clusterawsadm $(BAZEL_ARGS)
install bazel-bin/cmd/clusterawsadm/${BINARYPATHPATTERN}/clusterawsadm $(shell go env GOPATH)/bin/clusterawsadm

.PHONY: release-binaries
release-binaries: ## Build release binaries
bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //cmd/clusterctl //cmd/clusterawsadm
bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //cmd/clusterctl //cmd/clusterawsadm
bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64,@io_bazel_rules_go//go/toolchain:darwin_amd64 --build_tag_filters=cli //...
mkdir -p out
install bazel-bin/cmd/clusterawsadm/darwin_amd64_pure_stripped/clusterawsadm out/clusterawsadm-darwin-amd64
install bazel-bin/cmd/clusterawsadm/linux_amd64_pure_stripped/clusterawsadm out/clusterawsadm-linux-amd64
Expand All @@ -97,34 +79,27 @@ release-binaries: ## Build release binaries

.PHONY: test verify
test: generate verify ## Run tests
bazel test --nosandbox_debug //pkg/... //cmd/... $(BAZEL_ARGS)
bazel test //pkg/... //cmd/... $(BAZEL_ARGS)

verify:
./hack/verify_boilerplate.py

.PHONY: copy-genmocks
copy-genmocks: ## Copies generated mocks into the repository
cp -Rf bazel-genfiles/pkg/* pkg/

BAZEL_DOCKER_ARGS_COMMON := --define=MANAGER_IMAGE_NAME=$(MANAGER_IMAGE_NAME) --define=MANAGER_IMAGE_TAG=$(MANAGER_IMAGE_TAG) $(BAZEL_ARGS)
BAZEL_DOCKER_ARGS := --define=DOCKER_REPO=$(STABLE_DOCKER_REPO) $(BAZEL_DOCKER_ARGS_COMMON)
BAZEL_DOCKER_ARGS_DEV := --define=DOCKER_REPO=$(DEV_DOCKER_REPO) $(BAZEL_DOCKER_ARGS_COMMON)

.PHONY: docker-build
docker-build: generate ## Build the production docker image
docker-build: generate provider-components ## Build the production docker image
bazel run //cmd/manager:manager-image $(BAZEL_DOCKER_ARGS)

.PHONY: docker-build-dev
docker-build-dev: generate ## Build the development docker image
bazel run //cmd/manager:manager-image $(BAZEL_DOCKER_ARGS_DEV)

.PHONY: docker-push
docker-push: generate ## Push production docker image
docker-push: generate provider-components ## Push production docker image
bazel run //cmd/manager:manager-push $(BAZEL_DOCKER_ARGS)

.PHONY: docker-push-dev
docker-push-dev: generate ## Push development image
bazel run //cmd/manager:manager-push $(BAZEL_DOCKER_ARGS_DEV)
docker-push-dev: generate provider-components-dev ## Push development image
bazel run //cmd/manager:manager-push-dev $(BAZEL_DOCKER_ARGS)

.PHONY: provider-components-dev
provider-components-dev: provider-components ## Generate Kustomize version patch for the Docker image
bazel build //cmd/manager:manager-version-patch-dev $(BAZEL_DOCKER_ARGS)
install bazel-genfiles/cmd/manager/manager-version-patch-dev.yaml cmd/manager

.PHONY: clean
clean: ## Remove all generated files
Expand All @@ -138,68 +113,32 @@ clean: ## Remove all generated files
reset-bazel: ## Deep cleaning for bazel
bazel clean --expunge

cmd/clusterctl/examples/aws/out:
./cmd/clusterctl/examples/aws/generate-yaml.sh

cmd/clusterctl/examples/aws/out/credentials: cmd/clusterctl/examples/aws/out ## Generate k8s secret for AWS credentials
clusterawsadm alpha bootstrap generate-aws-default-profile > cmd/clusterctl/examples/aws/out/credentials

.PHONY: examples
examples: ## Generate example output
$(MAKE) cmd/clusterctl/examples/aws/out MANAGER_IMAGE=${MANAGER_IMAGE}

.PHONY: examples-dev
examples-dev: ## Generate example output with developer image
$(MAKE) cmd/clusterctl/examples/aws/out MANAGER_IMAGE=${DEV_MANAGER_IMAGE}

.PHONY: manifests
manifests: cmd/clusterctl/examples/aws/out/credentials ## Generate manifests for clusterctl
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd
kustomize build config/default/ > cmd/clusterctl/examples/aws/out/provider-components.yaml
echo "---" >> cmd/clusterctl/examples/aws/out/provider-components.yaml
kustomize build vendor/sigs.k8s.io/cluster-api/config/default/ >> cmd/clusterctl/examples/aws/out/provider-components.yaml

.PHONY: manifests-dev
manifests-dev: dep-ensure dep-install binaries-dev ## Builds development manifests
MANAGER_IMAGE=$(DEV_MANAGER_IMAGE) MANAGER_IMAGE_PULL_POLICY="Always" $(MAKE) manifests

# TODO(vincepri): This should move to rebuild Bazel binaries once every
# make target uses Bazel bins to run operations.
.PHONY: binaries-dev
binaries-dev: ## Builds and installs the binaries on the local GOPATH
go get -v ./...
go install -v ./...

.PHONY: create-cluster
create-cluster: ## Create a Kubernetes cluster on AWS using examples
clusterctl create cluster -v 3 \
--provider aws \
--bootstrap-type kind \
-m ./cmd/clusterctl/examples/aws/out/machines.yaml \
-c ./cmd/clusterctl/examples/aws/out/cluster.yaml \
-p ./cmd/clusterctl/examples/aws/out/provider-components.yaml \
-a ./cmd/clusterctl/examples/aws/out/addons.yaml
.PHONY: cli-dev
cli-dev: ## Builds and installs the binaries on the local GOPATH
bazel build --build_tag_filters=cli //... $(BAZEL_ARGS)
install bazel-bin/cmd/clusterawsadm/${BINARYPATHPATTERN}/clusterawsadm $(GOPATH)/bin/clusterawsadm
install bazel-bin/cmd/clusterctl/${BINARYPATHPATTERN}/clusterctl $(GOPATH)/bin/clusterctl


.PHONY: lint-full
lint-full: dep-ensure ## Run slower linters to detect possible issues
bazel run //:lint-full $(BAZEL_ARGS)

## Define kind dependencies here.

kind-reset: ## Destroys the "clusterapi" kind cluster.
kind delete cluster --name=clusterapi || true
bazel run //:kind-reset $(BAZEL_ARGS)

.PHONY: config
config: ## Create Kubernetes API components
bazel build //config
cp -Rf bazel-genfiles/config/* config/

ifneq ($(FASTBUILD),y)

## Define slow dependency targets here

.PHONY: generate
generate: gazelle dep-ensure ## Run go generate
GOPATH=$(shell go env GOPATH) bazel run //:generate $(BAZEL_ARGS)
$(MAKE) dep-ensure
bazel build $(BAZEL_ARGS) //pkg/cloud/aws/services/mocks:go_mock_interfaces \
//pkg/cloud/aws/services/ec2/mock_ec2iface:go_default_library \
//pkg/cloud/aws/services/elb/mock_elbiface:go_default_library
cp -Rf bazel-genfiles/pkg/* pkg/
bazel build --build_tag_filters=generated //... $(BAZEL_ARGS)

.PHONY: lint
lint: dep-ensure ## Lint codebase
Expand Down
26 changes: 21 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ http_archive(
urls = ["https://github.com/kubernetes/repo-infra/archive/e8f2f7c3decf03e1fde9f30d249e39b8328aa8b0.tar.gz"],
)

git_repository(
name = "bazel_skylib",
commit = "4b67f5ff384d1d2b0925299e0c1919d36b4ecaab",
remote = "https://github.com/bazelbuild/bazel-skylib.git",
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()
Expand Down Expand Up @@ -80,8 +90,8 @@ go_repository(
name = "com_github_golang_dep",
build_file_generation = "on",
importpath = "github.com/golang/dep",
strip_prefix = "dep-22125cfaa6ddc71e145b1535d4b7ee9744fefff2",
urls = ["https://github.com/golang/dep/archive/22125cfaa6ddc71e145b1535d4b7ee9744fefff2.zip"],
strip_prefix = "dep-73b3afefe4973c8d023870b691e9227a13569870",
urls = ["https://github.com/golang/dep/archive/73b3afefe4973c8d023870b691e9227a13569870.zip"],
)

go_repository(
Expand Down Expand Up @@ -119,9 +129,15 @@ go_repository(
)

go_repository(
name = "com_github_a8m_envsubst",
commit = "41dec2456c86b2a9fa51a22a808b7084b8d52c64", # v1.1.0
importpath = "github.com/a8m/envsubst",
name = "com_github_shurcool_vfsgen",
commit = "a97a25d856cadfe6481325baeb35a70d6723ca0c",
importpath = "github.com/shurcool/vfsgen",
)

go_repository(
name = "com_github_shurcool_httpfs",
commit = "809beceb23714880abc4a382a00c05f89d13b1cc",
importpath = "github.com/shurcooL/httpfs",
)

# for @io_k8s_kubernetes
Expand Down
3 changes: 3 additions & 0 deletions build/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports_files([
"stateful_set_patch.yaml",
])
35 changes: 35 additions & 0 deletions build/add_file.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2018 The Kubernetes 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.

# This is a modified version of the same rule from kubernetes/repo-infra
# modified to add the GO SDK to the PATH environment variable.

# Writes out a script which saves the runfiles directory,
# changes to the workspace root, and then runs a command.

def add_file(in_file, output, path = None):
output_path = output
input_path = in_file.path

if path and in_file.short_path.startswith(path):
output_path += in_file.short_path[len(path):]

return [
"mkdir -p $(dirname %s)" % output_path,
"test -L %s || ln -s $(pwd)/%s %s" % (output_path, input_path, output_path),
]

def add_files(in_files, path = None):
cmds = [add_file(in_file, in_file.path.build_output, path) for in_file in in_files]
return cmds.join(" && ")
Loading

0 comments on commit acd6dbc

Please sign in to comment.