Skip to content

Commit

Permalink
add infrastructure-components (#7)
Browse files Browse the repository at this point in the history
* add infrastructure-components make fmt

* add support for release image

* rename capm to capmaas

* prow changes

* gsutil upload release files

* fix dev-manifests
  • Loading branch information
sadysnaat authored Aug 3, 2021
1 parent d791f04 commit 962c8db
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ bin
*~

maas-credentials.env

_build
69 changes: 65 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@ ROOT_DIR_RELATIVE := .

include $(ROOT_DIR_RELATIVE)/common.mk

VERSION ?= $(shell cat clusterctl-settings.json | jq .config.nextVersion -r)

TOOLS_DIR := hack/tools
TOOLS_DIR_DEPS := $(TOOLS_DIR)/go.sum $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/Makefile
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
MANIFEST_DIR=_build/manifests
BUILD_DIR :=_build
RELEASE_DIR := _build/release
DEV_DIR := _build/dev

# Image URL to use all building/pushing image targets
IMAGE_NAME := cluster-api-provider-maas
IMG_URL ?= gcr.io/$(shell gcloud config get-value project)/${USER}
IMG_TAG ?= latest
IMG ?= ${IMG_URL}/cluster-api-provider-maas:${IMG_TAG}


# Release images
# Release docker variables
RELEASE_REGISTRY := gcr.io/spectro-images-public/release
RELEASE_CONTROLLER_IMG := $(RELEASE_REGISTRY)/$(IMAGE_NAME)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
DEFAULTER_GEN := $(TOOLS_BIN_DIR)/defaulter-gen
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -55,11 +68,48 @@ deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: $(CONTROLLER_GEN)
$(MANIFEST_DIR):
mkdir -p $(MANIFEST_DIR)
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
kustomize build config/crd > $(MANIFEST_DIR)/maas-manifest.yaml

$(BUILD_DIR):
mkdir -p $(BUILD_DIR)

$(OVERRIDES_DIR):
@mkdir -p $(OVERRIDES_DIR)

.PHONY: dev-version-check
dev-version-check:
ifndef VERSION
$(error VERSION must be set)
endif

.PHONY: release-version-check
release-version-check:
ifeq ($(VERSION), 0.0.0)
$(error VERSION must be >0.0.0 for release)
endif

.PHONY: release-manifests
release-manifests:
$(MAKE) manifests STAGE=release MANIFEST_DIR=$(RELEASE_DIR) PULL_POLICY=IfNotPresent IMAGE=$(RELEASE_CONTROLLER_IMG):$(VERSION)
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml

.PHONY: release-overrides
release-overrides:
$(MAKE) manifests STAGE=release MANIFEST_DIR=$(OVERRIDES_DIR) PULL_POLICY=IfNotPresent IMAGE=$(RELEASE_CONTROLLER_IMG):$(VERSION)

.PHONY: dev-manifests
dev-manifests:
$(MAKE) manifests STAGE=dev MANIFEST_DIR=$(DEV_DIR) PULL_POLICY=Always IMAGE=$(IMG)
cp metadata.yaml $(DEV_DIR)/metadata.yaml

# Generate manifests e.g. CRD, RBAC etc.
manifests: $(CONTROLLER_GEN) $(MANIFEST_DIR) $(KUSTOMIZE) $(BUILD_DIR)
rm -rf $(BUILD_DIR)/config
cp -R config $(BUILD_DIR)/config
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' $(BUILD_DIR)/config/default/manager_pull_policy.yaml
sed -i'' -e 's@image: .*@image: '"$(IMAGE)"'@' $(BUILD_DIR)/config/default/manager_image_patch.yaml
"$(KUSTOMIZE)" build $(BUILD_DIR)/config/default > $(MANIFEST_DIR)/infrastructure-components.yaml

# Run go fmt against code
fmt:
Expand All @@ -71,8 +121,16 @@ vet:

# Generate code
generate: $(CONTROLLER_GEN)
$(MAKE) generate-go
$(MAKE) generate-manifests

generate-go:
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

generate-manifests:
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases


# Build the docker image
docker-build: test
docker build . -t ${IMG}
Expand All @@ -86,3 +144,6 @@ docker-rmi:

mock: $(MOCKGEN)
go generate ./...

clean-release:
rm -rf $(RELEASE_DIR)
7 changes: 7 additions & 0 deletions clusterctl-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "infrastructure-maas",
"config": {
"componentsFile": "infrastructure-components.yaml",
"nextVersion": "v0.0.1"
}
}
31 changes: 14 additions & 17 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# Adds namespace to all resources.
namespace: cluster-api-provider-maas-system
namespace: capmaas-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: capmaas-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue

commonLabels:
cluster.x-k8s.io/provider: "infrastructure-maas"

resources:
- namespace.yaml
- credentials.yaml
- ../crd
- ../rbac
- ../manager
Expand All @@ -28,6 +23,8 @@ resources:

patchesStrategicMerge:
- manager_credentials_patch.yaml
- manager_pull_policy.yaml
- manager_image_patch.yaml
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
Expand All @@ -36,13 +33,13 @@ patchesStrategicMerge:
generatorOptions:
disableNameSuffixHash: true

# Create file: maas-credentials.yaml
# MAAS_ENDPOINT=http://1.2.3.4:5240/MAAS
# MAAS_APK_KEY=xxxx:yyyy:zzzz
secretGenerator:
- name: manager-bootstrap-credentials
envs:
- maas-credentials.env
## Create file: maas-credentials.yaml
## MAAS_ENDPOINT=http://1.2.3.4:5240/MAAS
## MAAS_APK_KEY=xxxx:yyyy:zzzz
#secretGenerator:
#- name: manager-bootstrap-credentials
# envs:
# - maas-credentials.env

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
11 changes: 11 additions & 0 deletions config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- image: gcr.io/spectro-images-public/release/cluster-api-provider-maas:latest
name: manager
11 changes: 11 additions & 0 deletions config/default/manager_pull_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
imagePullPolicy: IfNotPresent
4 changes: 4 additions & 0 deletions config/default/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: system
8 changes: 1 addition & 7 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: gcr.io/spectro-images-public/cluster-api-maas/release/cluster-api-provider-maas
newTag: latest
- manager.yaml
6 changes: 0 additions & 6 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: system
---
apiVersion: apps/v1
kind: Deployment
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ 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: 4 additions & 0 deletions hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ DEFAULTER_GEN := $(BIN_DIR)/defaulter-gen
$(DEFAULTER_GEN): $(BIN_DIR) go.mod go.sum
go build -tags=tools -o $@ k8s.io/code-generator/cmd/defaulter-gen

KUSTOMIZE := $(BIN_DIR)/kustomize ## Build kustomize
$(KUSTOMIZE): $(BIN_DIR) go.mod go.sum
go build -tags=tools -o $@ sigs.k8s.io/kustomize/kustomize/v3


.PHONY: clean
clean: ## Remove all tools
Expand Down
1 change: 1 addition & 0 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.16
require (
github.com/golang/mock v1.6.0
sigs.k8s.io/controller-tools v0.6.1
sigs.k8s.io/kustomize/kustomize/v3 v3.10.0
)
Loading

0 comments on commit 962c8db

Please sign in to comment.