Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@

GIT_VERSION ?= $(shell git log -1 --format="%h")
RELEASE_TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
RELEASE_VERSION ?= $(shell cat VERSION)
IS_NEW_RELEASE ?= true

# are there uncommitted files?
ifneq ($(shell git status --porcelain),)
# next is used by GoReleaser as well when --spanshot is set
RELEASE_TAG := $(RELEASE_TAG)-next
RELEASE_VERSION := $(RELEASE_VERSION)-dirty
IS_NEW_RELEASE := false
endif

# do we consider this to be a valid new release? Or are we working going forward?
ifneq ($(shell git branch --show-current),master)
RELEASE_VERSION := $(RELEASE_VERSION)-next
IS_NEW_RELEASE := false
else
ifeq ($(shell git diff HEAD~1 VERSION),)
RELEASE_VERSION := $(RELEASE_VERSION)-next
IS_NEW_RELEASE := false
endif
endif

VERSION ?= $(RELEASE_VERSION)

# which arches can we support
ARCHES=arm64 amd64

Expand Down Expand Up @@ -37,7 +55,8 @@ E2E_FOCUS := "functional tests"
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR := bin
TEST_E2E_DIR := test/e2e
TEST_DIR := test
TEST_E2E_DIR := $(TEST_DIR)/e2e

# Binaries.
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
Expand Down Expand Up @@ -112,16 +131,10 @@ CORE_VERSION ?= v0.3.5
CORE_API ?= https://api.github.com/repos/kubernetes-sigs/cluster-api/releases
CORE_URL ?= https://github.com/kubernetes-sigs/cluster-api/releases/download/$(CORE_VERSION)

# useful function
word-dot = $(word $2,$(subst ., ,$1))

VERSION ?= $(RELEASE_TAG)
VERSION_CONTRACT ?= v1alpha3
VERSION_MAJOR ?= $(call word-dot,$(VERSION),1)
VERSION_MINOR ?= $(call word-dot,$(VERSION),2)
# metadata file to be included in releases
METADATA_YAML ?= metadata.yaml

# actual releases
RELEASE_VERSION ?= $(VERSION)
RELEASE_BASE := out/release/infrastructure-packet
RELEASE_DIR := $(RELEASE_BASE)/$(RELEASE_VERSION)
FULL_RELEASE_DIR := $(realpath .)/$(RELEASE_DIR)
Expand All @@ -145,7 +158,6 @@ FULL_MANAGERLESS_MANIFEST := $(FULL_MANAGERLESS_DIR)/infrastructure-components.y
MANAGERLESS_CLUSTERCTLYAML := $(MANAGERLESS_BASE)/clusterctl-$(MANAGERLESS_VERSION).yaml

# templates
METADATA_TEMPLATE ?= templates/metadata-template.yaml
CLUSTERCTL_TEMPLATE ?= templates/clusterctl-template.yaml
CLUSTER_TEMPLATE ?= templates/cluster-template.yaml

Expand Down Expand Up @@ -197,10 +209,11 @@ test: generate fmt vet crds
go test ./... -coverprofile cover.out

# Run e2e tests
.PHONY: e2e
e2e:
# This is the name used inside the component.yaml for the container that runs the manager
# The image gets loaded inside kind from ./test/e2e/config/packet-dev.yaml
$(E2E_FLAGS) $(MAKE) -C test/e2e run
$(E2E_FLAGS) $(MAKE) -C $(TEST_E2E_DIR) run

# Build manager binary
manager: $(MANAGER)
Expand All @@ -222,11 +235,11 @@ uninstall: crds
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: crds
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
$(KUSTOMIZE) build config/release | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
crds: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/resources/crd/bases

# Run go fmt against code
fmt:
Expand Down Expand Up @@ -297,26 +310,27 @@ $(MANAGERLESS_DIR) $(MANAGERLESS_BASE):

.PHONY: semver release-clusterctl release-manifests release $(RELEASE_CLUSTERCTLYAML) $(RELEASE_MANIFEST) $(RELEASE_METADATA) $(RELEASE_CLUSTER_TEMPLATE) $(FULL_RELEASE_CLUSTERCTLYAML)

check-release:
@echo $(IS_NEW_RELEASE)

semver:
ifeq (,$(VERSION))
$(error could not determine version to use from git tag, will not create artifacts)
$(error could not determine version to use from file, will not create artifacts)
endif
@echo "release version $(VERSION)"


manifest: kustomize semver release-manifests release-clusterctl release-cluster-template

release:
goreleaser release --rm-dist --snapshot --skip-publish --debug

release/publish:
goreleaser release --rm-dist

release-manifests: semver $(RELEASE_MANIFEST) $(RELEASE_METADATA) $(RELEASE_CLUSTER_TEMPLATE)
$(RELEASE_MANIFEST): $(RELEASE_DIR) ## Builds the manifests to publish with a release
$(KUSTOMIZE) build config/default > $@
release-version:
KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true $(KUSTOMIZE) config set config/release image-tag $(VERSION)

$(RELEASE_MANIFEST): $(RELEASE_DIR) release-version ## Builds the manifests to publish with a release
$(KUSTOMIZE) build config/release > $@

$(RELEASE_METADATA): semver $(RELEASE_DIR) $(METADATA_TEMPLATE)
cat $(METADATA_TEMPLATE) | sed 's/MAJOR/$(VERSION_MAJOR)/g' | sed 's/MINOR/$(VERSION_MINOR)/g' | sed 's/CONTRACT/$(VERSION_CONTRACT)/g' > $@
$(RELEASE_METADATA): semver $(RELEASE_DIR)
cp $(METADATA_YAML) $@

release-cluster-template: semver $(RELEASE_CLUSTER_TEMPLATE)
$(RELEASE_CLUSTER_TEMPLATE): $(RELEASE_DIR)
Expand All @@ -335,8 +349,8 @@ managerless-manifests: semver $(MANAGERLESS_MANIFEST) $(MANAGERLESS_METADATA)
$(MANAGERLESS_MANIFEST): $(MANAGERLESS_DIR)
$(KUSTOMIZE) build config/managerless > $@

$(MANAGERLESS_METADATA): semver $(MANAGERLESS_DIR) $(METADATA_TEMPLATE)
cat $(METADATA_TEMPLATE) | sed 's/MAJOR/$(VERSION_MAJOR)/g' | sed 's/MINOR/$(VERSION_MINOR)/g' | sed 's/CONTRACT/$(VERSION_CONTRACT)/g' > $@
$(MANAGERLESS_METADATA): semver $(MANAGERLESS_DIR)
cp $(METADATA_YAML) $@

managerless-cluster-template: semver $(MANAGERLESS_CLUSTER_TEMPLATE)
$(MANAGERLESS_CLUSTER_TEMPLATE): $(MANAGERLESS_DIR)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The following section describes how to use the cluster-api provider for packet (
You do _not_ need to clone this repository, or install any special tools, other than the standard
`kubectl` and `clusterctl`; see below.

To build CAPP, release it, and to deploy individual components, see [docs/BUILD.md](./docs/BUILD.md).
* To build CAPP and to deploy individual components, see [docs/BUILD.md](./docs/BUILD.md).
* To build CAPP and to cut a proper release, see [docs/RELEASE.md](./docs/RELEASE.md).

### Requirements

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.3.0
13 changes: 0 additions & 13 deletions config/default/manager_image_patch.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions config/kustomization.yaml

This file was deleted.

12 changes: 6 additions & 6 deletions config/managerless/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace: cluster-api-provider-packet-system
namePrefix: cluster-api-provider-packet-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
commonLabels:
cluster.x-k8s.io/provider: infrastructure-packet

bases:
- ../crd
- ../rbac
- ../namespace
resources:
- ../resources/crd
- ../resources/rbac
- ../resources/namespace
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
# Adds namespace to all resources.
namespace: cluster-api-provider-packet-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: cluster-api-provider-packet-

# Labels to add to all resources and selectors.
commonLabels:
cluster.x-k8s.io/provider: infrastructure-packet

bases:
- ../crd
- ../rbac
- ../namespace
- ../manager
resources:
- ../resources/crd
- ../resources/rbac
- ../resources/namespace
- ../resources/manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

images:
- name: packet-controller # images with this name
newTag: v0.3.0 # {"type":"string","x-kustomize":{"setter":{"name":"image-tag","value":"v0.3.0"}}}
newName: packethost/cluster-api-provider-packet # and this name
patchesStrategicMerge:
# 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.
# 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.
- manager_auth_proxy_patch.yaml
- manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ spec:
- /manager
args:
- --enable-leader-election
image: controller:latest
image: packet-controller
imagePullPolicy: IfNotPresent
name: manager
resources:
limits:
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Release

This document describes how to release the Packet infrastructure provider.

This is _not_ intended for regular users.

This is normally performed by our CI system. However, there are important steps to take first.

## How to Cut a Releas

In order to cut a release, you must:

1. If this is a new major or minor version - but **not** just a patch change - update [metadata.yaml](./metadata.yaml) to add it, and map it to the correct cluster-api contract version
1. Modify `VERSION` so it includes only the version number to be released, in the format `vA.B.C`
1. Run `make release-version` to ensure other files are up to date.
1. Commit the changes.
1. Push out your branch, open a PR and merge the changes
1. Tag the release with `git tag -a vX.Y.z -m "Message"
1. Push out the tag

The `make release-version` command modifies any dependent files that need to be updated for release to work. If they are not updated, lots of things fail.

It updates the following files based on your git tag:

* [config/release/kustomization.yaml](config/release/kustomization.yaml)

Dependent files **must** be changed, committed and merged _before_ pushing out the tag.

When building the manifests via `make manifests`, `make managerless`, or `make release`, it determines the version as follows:

* Take the version from the contents of [VERSION](./VERSION)
* If there are any uncommitted files, append `-dirty`
* If not on `master` branch, or if on `master` branch but the [VERSION](./VERSION) file is unchanged from the last commit on `master` branch, append `-next`

The net of the above, is that the version will be treated as "clean" only when all of the following are true:

* there are no "dirty" uncommitted files
* the current commit is on `master` branch
* the `VERSION` is different from the previous commit

Thie encourages - requires - changes to a version, and therefore a release, to consist entirely of a single commit or merge to master,
whose entire change is the `VERSION` file and, optionally, in the same commit, the `APIVERSION` file.

To see what version you would get, run `make semver`. To see if this is a new release, run `make check-release`.

We are aware that this is a somewhat duplicative process, but there is no other way, as multiple stages
depend on having the versions in checked-in files and do not support environment variable or command-line
options.

In the next stage, we will eliminate the need for a git tag, and use CI to apply the tag.

## How A Release Happens

When the VERSION file changes:

* CI creates the release in `out/`, the equivalent of `make release-manifests`
* CI copies the artifacts in `out/release/infrastructure-packet/<version>/*yaml` to the github releases
* CI builds docker images for each supported architecture as well as a multi-arch manifest, and tags it with:
* the git hash of the commit
* `master`
* the semver tag of the release, e.g. `v0.3.1`
* the tag `latest`

4 changes: 0 additions & 4 deletions docs/contribution/release.md

This file was deleted.

9 changes: 9 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# maps release series of major.minor to cluster-api contract version
# the contract version may change between minor or major versions, but *not*
# between patch versions.
#
# update this file only when a new major or minor version is released
releaseSeries:
- major: 0
minor: 3
contract: v1alpha3
4 changes: 0 additions & 4 deletions templates/metadata-template.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion test/e2e/config/packet-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ providers:
- old: "--enable-leader-election"
new: "--enable-leader-election=false"
files:
- sourcePath: "../../../templates/metadata-template.yaml"
- sourcePath: "../../../../metadata.yaml"
targetName: "metadata.yaml"
- sourcePath: "../../../templates/cluster-template.yaml"

Expand Down