Skip to content

Commit f60c87e

Browse files
authored
Merge pull request #475 from kubernetes-sigs/master
👻 ff release-0.2 branch to master
2 parents 38483b2 + be010e1 commit f60c87e

File tree

22 files changed

+439
-87
lines changed

22 files changed

+439
-87
lines changed

.github/main.workflow

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
workflow "PR Checks" {
2+
on = "pull_request"
3+
resolves = ["verify-emoji"]
4+
}
5+
6+
action "verify-emoji" {
7+
uses = "./hack/release"
8+
secrets = ["GITHUB_TOKEN"]
9+
}

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ Please see https://git.k8s.io/community/CLA.md for more info
1919
1. Setup tools
2020
```bash
2121
$ go get -u github.com/golang/dep/cmd/dep
22-
$ go get -u gopkg.in/alecthomas/gometalinter.v2
23-
$ gometalinter.v2 --install # if can't load package, refer: https://github.com/alecthomas/gometalinter/issues/404
22+
$ curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.15.0
2423
```
2524
1. Test
2625
```bash
27-
TRACE=1 ./hack/check-everything.sh
26+
GO111MODULE=on TRACE=1 ./hack/check-everything.sh
2827
```
2928

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VERSIONING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ a:
9292
- Patch fix: :bug: (`:bug:`)
9393
- Docs: :book: (`:book:`)
9494
- Infra/Tests/Other: :running: (`:running:`)
95+
- No release note: :ghost: (`:ghost:`)
96+
97+
Use :ghost: (no release note) only for the PRs that change or revert unreleased
98+
changes, which don't deserve a release note. Please don't abuse it.
9599

96100
You can also use the equivalent emoji directly, since GitHub doesn't
97101
render the `:xyz:` aliases in PR titles.

examples/builtins/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func main() {
5353
os.Exit(1)
5454
}
5555

56-
// Setup a new controller to Reconciler ReplicaSets
56+
// Setup a new controller to reconcile ReplicaSets
5757
entryLog.Info("Setting up controller")
5858
c, err := controller.New("foo-controller", mgr, controller.Options{
5959
Reconciler: &reconcileReplicaSet{client: mgr.GetClient(), log: log.WithName("reconciler")},

examples/crd/pkg/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type ChaosPodList struct {
6161
Items []ChaosPod `json:"items"`
6262
}
6363

64+
// +kubebuilder:webhook:failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=vchaospod.kb.io,path=/validate-chaosapps-metamagical-io-v1-chaospod,mutating=false
65+
66+
var _ webhook.Validator = &ChaosPod{}
67+
6468
// ValidateCreate implements webhookutil.validator so a webhook will be registered for the type
6569
func (c *ChaosPod) ValidateCreate() error {
6670
log.Info("validate create", "name", c.Name)
@@ -89,6 +93,8 @@ func (c *ChaosPod) ValidateUpdate(old runtime.Object) error {
8993
return nil
9094
}
9195

96+
// +kubebuilder:webhook:failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=mchaospod.kb.io,path=/mutate-chaosapps-metamagical-io-v1-chaospod,mutating=true
97+
9298
var _ webhook.Defaulter = &ChaosPod{}
9399

94100
// Default implements webhookutil.defaulter so a webhook will be registered for the type

hack/release/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM k8s.gcr.io/debian-base:v1.0.0
2+
3+
LABEL com.github.actions.name="KubeBuilder PR Emoji"
4+
LABEL com.github.actions.name="Verify that KubeBuilder release notes emoji are present on the PR"
5+
LABEL com.github.actions.icon="git-pull-request"
6+
LABEL com.github.actions.color="blue"
7+
8+
RUN apt-get update -y && apt-get install -y bash jq curl
9+
10+
COPY common.sh /common.sh
11+
COPY verify-emoji.sh /verify-emoji.sh
12+
13+
ENTRYPOINT ["/verify-emoji.sh"]

hack/release/common.sh

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ cr_major_pattern=":warning:|$(printf "\xe2\x9a\xa0")"
55
cr_minor_pattern=":sparkles:|$(printf "\xe2\x9c\xa8")"
66
cr_patch_pattern=":bug:|$(printf "\xf0\x9f\x90\x9b")"
77
cr_docs_pattern=":book:|$(printf "\xf0\x9f\x93\x96")"
8+
cr_no_release_note_pattern=":ghost:|$(printf "\xf0\x9f\x91\xbb")"
89
cr_other_pattern=":running:|$(printf "\xf0\x9f\x8f\x83")"
10+
cr_all_pattern="${cr_major_pattern}|${cr_minor_pattern}|${cr_patch_pattern}|${cr_docs_pattern}|${cr_other_pattern}"
911

1012
# cr::symbol-type-raw turns :xyz: and the corresponding emoji
1113
# into one of "major", "minor", "patch", "docs", "other", or
@@ -24,6 +26,9 @@ cr::symbol-type-raw() {
2426
@(${cr_docs_pattern})?('!'))
2527
echo "docs"
2628
;;
29+
@(${cr_no_release_note_pattern})?('!'))
30+
echo "no_release_note"
31+
;;
2732
@(${cr_other_pattern})?('!'))
2833
echo "other"
2934
;;
@@ -66,6 +71,52 @@ git::ensure-release-branch() {
6671
fi
6772
}
6873
74+
# git::export-version-from-branch outputs the current version
75+
# for the given branch (as the argument) as exported variables
76+
# (${maj,min,patch}_ver, last_tag).
77+
git::export-version-from-branch() {
78+
local target_branch=${1?must specify a branch}
79+
local current_branch=$(git branch --show-current -q)
80+
81+
local expected_maj_ver
82+
local expected_min_ver
83+
if [[ ${target_branch} =~ release-0.([[:digit:]]+) ]]; then
84+
expected_maj_ver=0
85+
expected_min_ver=${BASH_REMATCH[1]}
86+
elif [[ ${target_branch} =~ release-([[:digit:]]+) ]]; then
87+
expected_maj_ver=${BASH_REMATCH[1]}
88+
else
89+
echo "branch ${target_branch} does not appear to be for a release -- it should be release-X or release-0.Y" >&2
90+
exit 1
91+
fi
92+
93+
local tag_pattern='v([[:digit:]]+).([[:digit:]]+).([[:digit:]]+)'
94+
95+
git checkout -q ${target_branch}
96+
97+
# make sure we've got a tag that matches *some* release
98+
last_tag=$(git describe --tags --abbrev=0) # try to fetch just the "current" tag name
99+
if [[ ! ${last_tag} =~ ${tag_pattern} ]]; then
100+
# it's probably for a previous version
101+
echo "tag ${last_tag} does not appear to be for a release -- it should be vX.Y.Z" >&2
102+
git checkout -q ${current_branch}
103+
exit 1
104+
fi
105+
106+
export min_ver=${BASH_REMATCH[2]}
107+
export patch_ver=${BASH_REMATCH[3]}
108+
export maj_ver=${BASH_REMATCH[1]}
109+
export last_tag=${last_tag}
110+
111+
if ${2:-1} && ([[ ${maj_ver} != ${expected_maj_ver} ]] || [[ ${maj_ver} == 0 && ${min_ver} != ${expected_min_ver} ]]); then
112+
echo "tag ${last_tag} does not appear to be for a the right release (${target_branch})" >&2
113+
git checkout ${current_branch}
114+
exit 1
115+
fi
116+
117+
git checkout -q ${current_branch}
118+
}
119+
69120
# git::export-current-version outputs the current version
70121
# as exported variables (${maj,min,patch}_ver, last_tag) after
71122
# checking that we're on the right release branch.
@@ -75,25 +126,26 @@ git::export-current-version() {
75126
76127
# deal with the release-0.1 branch, or similar
77128
local release_ver=${BASH_REMATCH[1]}
78-
maj_ver=${release_ver}
79-
local tag_pattern='v${maj_ver}.([[:digit:]]+).([[:digit]]+)'
80-
if [[ ${maj_ver} =~ 0\.([[:digit:]]+) ]]; then
81-
maj_ver=0
82-
min_ver=${BASH_REMATCH[1]}
83-
local tag_pattern="v0.(${min_ver}).([[:digit:]]+)"
129+
local expected_maj_ver=${release_ver}
130+
if [[ ${expected_maj_ver} =~ 0\.([[:digit:]]+) ]]; then
131+
expected_maj_ver=0
132+
local expected_min_ver=${BASH_REMATCH[1]}
84133
fi
85134
86-
# make sure we've got a tag that matches our release branch
87-
last_tag=$(git describe --tags --abbrev=0) # try to fetch just the "current" tag name
88-
if [[ ! ${last_tag} =~ ${tag_pattern} ]]; then
89-
echo "tag ${last_tag} does not appear to be a release for this release (${release_ver})-- it should be v${maj_ver}.Y.Z" >&2
90-
exit 1
135+
git::export-version-from-branch "release-${release_ver}" false
136+
137+
local last_tag_branch=""
138+
if [[ ${maj_ver} == "0" && ${min_ver} -eq $((expected_min_ver-1)) ]]; then
139+
echo "most recent tag is a release behind (${last_tag}), checking previous release branch to be safe" >&2
140+
last_tag_branch="release-0.${min_ver}"
141+
elif [[ ${maj_ver} -eq $((expected_maj_ver-1)) ]]; then
142+
echo "most recent tag is a release behind (${last_tag}), checking previous release branch to be safe" >&2
143+
last_tag_branch="release-${maj_ver}"
91144
fi
92145

93-
export min_ver=${BASH_REMATCH[1]}
94-
export patch_ver=${BASH_REMATCH[2]}
95-
export maj_ver=${maj_ver}
96-
export last_tag=${last_tag}
146+
if [[ -n "${last_tag_branch}" ]]; then
147+
git::export-version-from-branch ${last_tag_branch} true
148+
fi
97149
}
98150

99151
# git::next-version figures out the next version to tag

hack/release/release-notes.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ while read commit_word commit; do
5050
patch)
5151
bugfixes="${bugfixes}- ${pr_title} (#${pr_number})${NEWLINE}"
5252
;;
53-
docs|other)
53+
docs|no_release_note|other)
5454
# skip non-code-changes
5555
;;
5656
unknown)
@@ -64,8 +64,8 @@ done <<<$(git rev-list ${last_tag}..HEAD --merges --pretty=format:%B)
6464

6565
# TODO: sort non merge commits with tags
6666

67-
[[ -n "${breaking}" ]] && printf '\e[1;31mbreaking changes this version\e[0m' >&2
68-
[[ -n "${unknown}" ]] && printf '\e[1;35munknown changes in this release -- categorize manually\e[0m' >&2
67+
[[ -n "${breaking}" ]] && printf '\e[1;31mbreaking changes this version\e[0m\n' >&2
68+
[[ -n "${unknown}" ]] && printf '\e[1;35munknown changes in this release -- categorize manually\e[0m\n' >&2
6969

7070
echo "" >&2
7171
echo "" >&2

hack/release/verify-emoji.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
pr_title=$(jq -r '.pull_request.title' < ${GITHUB_EVENT_PATH})
7+
8+
read pr_prefix rest <<<${pr_title}
9+
10+
source "$(dirname ${BASH_SOURCE})/common.sh"
11+
12+
pr_type=$(cr::symbol-type ${pr_prefix})
13+
14+
summary=""
15+
conclusion="success"
16+
if [[ ${pr_type} == "unknown" ]]; then
17+
summary="You must specify an emoji at the beginning of the PR to indicate what kind of change this is.\nValid emoji: ${cr_all_pattern}.\nYou specified '${pr_prefix}'.\nSee VERSIONING.md for more information."
18+
conclusion="failure"
19+
else
20+
summary="PR is a ${pr_type} change (${pr_prefix})."
21+
fi
22+
23+
# get the PR (the PR sent from the event has the base branch head as the head)
24+
base_link=$(jq -r '.pull_request.url' < ${GITHUB_EVENT_PATH})
25+
head_commit=$(curl -H "Authorization: Bearer ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.antiope-preview+json' -q ${base_link} | jq -r '.head.sha')
26+
echo "head commit is ${head_commit}"
27+
28+
curl https://api.github.com/repos/${GITHUB_REPOSITORY}/check-runs -XPOST -H "Authorization: Bearer ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.antiope-preview+json' -H 'Content-Type: application/json' -q --data-raw '{"name": "Verify Emoji", "head_sha": "'${head_commit}'", "conclusion": "'${conclusion}'", "status": "completed", "completed_at": "'$(date -Iseconds)'", "output": {"title": "Verify Emoji", "summary": "'"${summary}"'"}}'
29+

pkg/builder/build.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Builder struct {
5050
watchRequest []watchRequest
5151
config *rest.Config
5252
ctrl controller.Controller
53+
name string
5354
}
5455

5556
// SimpleController returns a new Builder.
@@ -131,6 +132,16 @@ func (blder *Builder) WithEventFilter(p predicate.Predicate) *Builder {
131132
return blder
132133
}
133134

135+
// Named sets the name of the controller to the given name. The name shows up
136+
// in metrics, among other things, and thus should be a prometheus compatible name
137+
// (underscores and alphanumeric characters only).
138+
//
139+
// By default, controllers are named using the lowercase version of their kind.
140+
func (blder *Builder) Named(name string) *Builder {
141+
blder.name = name
142+
return blder
143+
}
144+
134145
// Complete builds the Application ControllerManagedBy.
135146
func (blder *Builder) Complete(r reconcile.Reconciler) error {
136147
_, err := blder.Build(r)
@@ -227,12 +238,14 @@ func (blder *Builder) doManager() error {
227238
}
228239

229240
func (blder *Builder) getControllerName() (string, error) {
241+
if blder.name != "" {
242+
return blder.name, nil
243+
}
230244
gvk, err := getGvk(blder.apiType, blder.mgr.GetScheme())
231245
if err != nil {
232246
return "", err
233247
}
234-
name := fmt.Sprintf("%s-application", strings.ToLower(gvk.Kind))
235-
return name, nil
248+
return strings.ToLower(gvk.Kind), nil
236249
}
237250

238251
func (blder *Builder) doController(r reconcile.Reconciler) error {

pkg/controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Options struct {
4242
// Work typically is reads and writes Kubernetes objects to make the system state match the state specified
4343
// in the object Spec.
4444
type Controller interface {
45-
// Reconciler is called to Reconciler an object by Namespace/Name
45+
// Reconciler is called to reconcile an object by Namespace/Name
4646
reconcile.Reconciler
4747

4848
// Watch takes events provided by a Source and uses the EventHandler to

pkg/doc.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ clients, caches, schemes, etc. Controllers should be Started through the Manage
3535
Controller
3636
3737
Controller implements a Kubernetes API by responding to events (object Create, Update, Delete) and ensuring that
38-
the state specified in the Spec of the object matches the state of the system. This is called a Reconciler.
38+
the state specified in the Spec of the object matches the state of the system. This is called a reconcile.
3939
If they do not match, the Controller will create / update / delete objects as needed to make them match.
4040
41-
Controllers are implemented as worker queues that process reconcile.Requests (requests to Reconciler the
41+
Controllers are implemented as worker queues that process reconcile.Requests (requests to reconcile the
4242
state for a specific object).
4343
44-
Unlike http handlers, Controllers DO NOT handle events directly, but enqueue Requests to eventually Reconciler
44+
Unlike http handlers, Controllers DO NOT handle events directly, but enqueue Requests to eventually reconcile
4545
the object. This means the handling of multiple events may be batched together and the full state of the
46-
system must be read for each Reconciler.
46+
system must be read for each reconcile.
4747
4848
* Controllers require a Reconciler to be provided to perform the work pulled from the work queue.
4949
@@ -65,11 +65,11 @@ Validating webhook is used to validate if an object meets certain requirements.
6565
Reconciler
6666
6767
Reconciler is a function provided to a Controller that may be called at anytime with the Name and Namespace of an object.
68-
When called, Reconciler will ensure that the state of the system matches what is specified in the object at the
69-
time Reconciler is called.
68+
When called, the Reconciler will ensure that the state of the system matches what is specified in the object at the
69+
time the Reconciler is called.
7070
7171
Example: Reconciler invoked for a ReplicaSet object. The ReplicaSet specifies 5 replicas but only
72-
3 Pods exist in the system. Reconciler creates 2 more Pods and sets their OwnerReference to point at the
72+
3 Pods exist in the system. The Reconciler creates 2 more Pods and sets their OwnerReference to point at the
7373
ReplicaSet with controller=true.
7474
7575
* Reconciler contains all of the business logic of a Controller.
@@ -80,7 +80,7 @@ a mapping (e.g. owner references) that maps the object that triggers the reconci
8080
8181
* Reconciler is provided the Name / Namespace of the object to reconcile.
8282
83-
* Reconciler does not care about the event contents or event type responsible for triggering the Reconciler.
83+
* Reconciler does not care about the event contents or event type responsible for triggering the reconcile.
8484
- e.g. it doesn't matter whether a ReplicaSet was created or updated, Reconciler will always compare the number of
8585
Pods in the system against what is specified in the object at the time it is called.
8686
@@ -159,7 +159,7 @@ Controller Example
159159
1.2 Pod (created by ReplicaSet) -> handler.EnqueueRequestForOwnerHandler - enqueue a Request with the
160160
Owning ReplicaSet Namespace and Name.
161161
162-
2. Reconciler ReplicaSet in response to an event
162+
2. reconcile ReplicaSet in response to an event
163163
164164
2.1 ReplicaSet object created -> Read ReplicaSet, try to read Pods -> if is missing create Pods.
165165
@@ -169,7 +169,7 @@ Owning ReplicaSet Namespace and Name.
169169
170170
Watching and EventHandling
171171
172-
Controllers may Watch multiple Kinds of objects (e.g. Pods, ReplicaSets and Deployments), but they Reconciler
172+
Controllers may Watch multiple Kinds of objects (e.g. Pods, ReplicaSets and Deployments), but they reconcile
173173
only a single Type. When one Type of object must be updated in response to changes in another Type of object,
174174
an EnqueueRequestFromMapFunc may be used to map events from one type to another. e.g. Respond to a cluster resize
175175
event (add / delete Node) by re-reconciling all instances of some API.
@@ -189,10 +189,10 @@ Controller Writing Tips
189189
190190
Reconciler Runtime Complexity:
191191
192-
* It is better to write Controllers to perform an O(1) Reconciler N times (e.g. on N different objects) instead of
193-
performing an O(N) Reconciler 1 time (e.g. on a single object which manages N other objects).
192+
* It is better to write Controllers to perform an O(1) reconcile N times (e.g. on N different objects) instead of
193+
performing an O(N) reconcile 1 time (e.g. on a single object which manages N other objects).
194194
195-
* Example: If you need to update all Services in response to a Node being added - Reconciler Services but Watch
195+
* Example: If you need to update all Services in response to a Node being added - reconcile Services but Watch
196196
Nodes (transformed to Service object name / Namespaces) instead of Reconciling Nodes and updating Services
197197
198198
Event Multiplexing:

0 commit comments

Comments
 (0)