Skip to content

Commit 03d1f85

Browse files
committed
build: Integrate with existing tooling
1 parent b60cb4f commit 03d1f85

File tree

11 files changed

+130
-215
lines changed

11 files changed

+130
-215
lines changed

.github/workflows/goreleaser.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: goreleaser
5+
6+
on:
7+
push:
8+
tags:
9+
- v*
10+
11+
permissions:
12+
contents: write
13+
packages: write
14+
issues: write
15+
16+
jobs:
17+
goreleaser:
18+
runs-on: ubuntu-22.04
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Fetch all tags
26+
run: git fetch --force --tags
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v2
30+
31+
- name: Gather tool versions
32+
uses: endorama/asdf-parse-tool-versions@v1
33+
id: versions
34+
35+
- name: Login to ghcr.io
36+
uses: docker/login-action@v2
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Install go
43+
uses: actions/setup-go@v3
44+
with:
45+
go-version: ${{ fromJson(steps.versions.outputs.tools).golang }}
46+
cache: true
47+
48+
- name: Run goreleaser
49+
uses: goreleaser/goreleaser-action@v4
50+
with:
51+
distribution: goreleaser
52+
version: ${{ fromJson(steps.versions.outputs.tools).goreleaser }}
53+
args: release --clean
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release-main.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/release-please.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: release-please-main
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
release-please:
13+
runs-on: ubuntu-22.04
14+
steps:
15+
- uses: google-github-actions/[email protected]
16+
id: release-please
17+
with:
18+
release-type: go
19+
package-name: capi-runtime-extensions
20+
pull-request-title-pattern: "build${scope}: release${component} ${version}"
21+
changelog-notes-type: github

.go-tools

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
github.com/oligot/[email protected]
2-
gotest.tools/[email protected]
32
github.com/segmentio/[email protected]
3+
gotest.tools/[email protected]
4+
sigs.k8s.io/controller-runtime/tools/[email protected]

.goreleaser.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ changelog:
2121
release:
2222
footer: |
2323
### Summary
24-
**Full Changelog**: https://github.com/d2iq-labs/capi-runtime-extensions/compare/{{ .PreviousTag }}...{{ .Tag }}
24+
**Full Changelog**: https://github.com/d2iq-labs/{{.ProjectName}}/compare/{{ .PreviousTag }}...{{ .Tag }}
2525
2626
builds:
2727
- id: capi-runtime-extensions
@@ -61,14 +61,14 @@ dockers:
6161
#
6262
# For a release build the `-amd64` suffix will always be included and the `docker_manifests` specification below
6363
# will create the final multiplatform manifest to be pushed to the registry.
64-
- 'd2iq-labs/capi-runtime-extensions:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "amd64")) }}-amd64{{ end }}'
64+
- 'd2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "amd64")) }}-amd64{{ end }}'
6565
use: buildx
6666
dockerfile: Dockerfile
6767
build_flag_templates:
6868
- "--platform=linux/amd64"
6969
- "--pull"
7070
- "--label=org.opencontainers.image.created={{.Date}}"
71-
- "--label=org.opencontainers.image.title=capi-runtime-extensions"
71+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
7272
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
7373
- "--label=org.opencontainers.image.version={{.Version}}"
7474
- "--label=org.opencontainers.image.source={{.GitURL}}"
@@ -80,23 +80,23 @@ dockers:
8080
#
8181
# For a release build the `-amd64v8` suffix will always be included and the `docker_manifests` specification below
8282
# will create the final multiplatform manifest to be pushed to the registry.
83-
- 'd2iq-labs/capi-runtime-extensions:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "arm64")) }}-arm64v8{{ end }}'
83+
- 'd2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "arm64")) }}-arm64v8{{ end }}'
8484
use: buildx
8585
goarch: arm64
8686
dockerfile: Dockerfile
8787
build_flag_templates:
8888
- "--platform=linux/arm64"
8989
- "--pull"
9090
- "--label=org.opencontainers.image.created={{.Date}}"
91-
- "--label=org.opencontainers.image.title=capi-runtime-extensions"
91+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
9292
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
9393
- "--label=org.opencontainers.image.version={{.Version}}"
9494
- "--label=org.opencontainers.image.source={{.GitURL}}"
9595
docker_manifests:
96-
- name_template: d2iq-labs/capi-runtime-extensions:v{{trimprefix .Version "v"}}
96+
- name_template: d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}
9797
image_templates:
98-
- d2iq-labs/capi-runtime-extensions:v{{trimprefix .Version "v"}}-amd64
99-
- d2iq-labs/capi-runtime-extensions:v{{trimprefix .Version "v"}}-arm64v8
98+
- d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}-amd64
99+
- d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}-arm64v8
100100
checksum:
101101
name_template: 'checksums.txt'
102102
snapshot:

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ golang 1.19.5
44
golangci-lint 1.50.1
55
goreleaser 1.15.0
66
helm 3.11.0
7+
kube-controller-tools 0.11.2
8+
kustomize 4.5.7
79
pre-commit 3.0.2
810
shfmt 3.6.0
911
upx 4.0.2

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
REPO_ROOT := $(CURDIR)
55

6+
# Versions for tools that are not managed by asdf.
7+
ENVTEST_VERSION=1.25.x
8+
69
include make/all.mk

main.go renamed to cmd/capi-runtime-extensions/main.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
// Copyright 2023 D2iQ, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
14
package main
25

36
import (
47
"context"
58
"flag"
69
"net/http"
710
"os"
11+
"time"
812

913
"github.com/spf13/pflag"
1014
cliflag "k8s.io/component-base/cli/flag"
1115
"k8s.io/component-base/logs"
1216
logsv1 "k8s.io/component-base/logs/api/v1"
1317
"k8s.io/klog/v2"
14-
ctrl "sigs.k8s.io/controller-runtime"
15-
1618
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
1719
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1820
"sigs.k8s.io/cluster-api/exp/runtime/server"
21+
ctrl "sigs.k8s.io/controller-runtime"
1922
)
2023

2124
var (
@@ -29,11 +32,6 @@ var (
2932
logOptions = logs.NewOptions()
3033
)
3134

32-
func init() {
33-
// Adds to the catalog all the RuntimeHooks defined in cluster API.
34-
_ = runtimehooksv1.AddToCatalog(catalog)
35-
}
36-
3735
// InitFlags initializes the flags.
3836
func InitFlags(fs *pflag.FlagSet) {
3937
// Initialize logs flags using Kubernetes component-base machinery.
@@ -52,6 +50,8 @@ func InitFlags(fs *pflag.FlagSet) {
5250
}
5351

5452
func main() {
53+
_ = runtimehooksv1.AddToCatalog(catalog)
54+
5555
// Creates a logger to be used during the main func.
5656
setupLog := ctrl.Log.WithName("main")
5757

@@ -74,7 +74,14 @@ func main() {
7474
if profilerAddress != "" {
7575
klog.Infof("Profiler listening for requests at %s", profilerAddress)
7676
go func() {
77-
klog.Info(http.ListenAndServe(profilerAddress, nil))
77+
profilerServer := &http.Server{
78+
Addr: profilerAddress,
79+
Handler: nil,
80+
MaxHeaderBytes: 1 << 20,
81+
IdleTimeout: 90 * time.Second, // matches http.DefaultTransport keep-alive timeout
82+
ReadHeaderTimeout: 32 * time.Second,
83+
}
84+
klog.Info(profilerServer.ListenAndServe())
7885
}()
7986
}
8087

@@ -118,13 +125,21 @@ func main() {
118125
}
119126
}
120127

121-
func DoBeforeClusterCreate(ctx context.Context, request *runtimehooksv1.BeforeClusterCreateRequest, response *runtimehooksv1.BeforeClusterCreateResponse) {
128+
func DoBeforeClusterCreate(
129+
ctx context.Context,
130+
request *runtimehooksv1.BeforeClusterCreateRequest,
131+
response *runtimehooksv1.BeforeClusterCreateResponse,
132+
) {
122133
log := ctrl.LoggerFrom(ctx)
123134
log.Info("BeforeClusterCreate is called")
124135
// Your implementation
125136
}
126137

127-
func DoBeforeClusterUpgrade(ctx context.Context, request *runtimehooksv1.BeforeClusterUpgradeRequest, response *runtimehooksv1.BeforeClusterUpgradeResponse) {
138+
func DoBeforeClusterUpgrade(
139+
ctx context.Context,
140+
request *runtimehooksv1.BeforeClusterUpgradeRequest,
141+
response *runtimehooksv1.BeforeClusterUpgradeResponse,
142+
) {
128143
log := ctrl.LoggerFrom(ctx)
129144
log.Info("BeforeClusterUpgrade is called")
130145
// Your implementation

make/go.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export GOARCH := $(shell go env GOARCH)
1616
endif
1717

1818
define go_test
19+
source <(setup-envtest use -p env $(ENVTEST_VERSION)) && \
1920
gotestsum \
2021
--jsonfile test.json \
2122
--junitfile junit-report.xml \
@@ -45,7 +46,7 @@ endif
4546

4647
.PHONY: test.%
4748
test.%: ## Runs go tests for a specific module
48-
test.%: install-tool.go.gotestsum; $(info $(M) running tests$(if $(GOTEST_RUN), matching "$(GOTEST_RUN)") for $* module)
49+
test.%: install-tool.go.gotestsum install-tool.go.setup-envtest ; $(info $(M) running tests$(if $(GOTEST_RUN), matching "$(GOTEST_RUN)") for $* module)
4950
$(if $(filter-out root,$*),cd $* && )$(call go_test)
5051

5152
.PHONY: integration-test
@@ -156,8 +157,10 @@ go-clean.%: install-tool.golang; $(info $(M) running go clean for $* module)
156157

157158
.PHONY: go-generate
158159
go-generate: ## Runs go generate
159-
go-generate: install-tool.golang ; $(info $(M) running go generate)
160+
go-generate: install-tool.golang install-tool.kube-controller-tools ; $(info $(M) running go generate)
160161
go generate -x ./...
162+
controller-gen rbac:roleName=manager-role webhook paths="./..."
163+
controller-gen object:headerFile="header.txt" paths="./..."
161164

162165
.PHONY: go-mod-upgrade
163166
go-mod-upgrade: ## Interactive check for direct module dependency upgrades

make/goreleaser.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ endif
1010

1111
.PHONY: build-snapshot
1212
build-snapshot: ## Builds a snapshot with goreleaser
13-
build-snapshot: dockerauth install-tool.goreleaser install-tool.golang ; $(info $(M) building snapshot $*)
13+
build-snapshot: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $(info $(M) building snapshot $*)
1414
goreleaser --debug=$(GORELEASER_DEBUG) \
1515
build \
1616
--snapshot \
@@ -21,7 +21,7 @@ build-snapshot: dockerauth install-tool.goreleaser install-tool.golang ; $(info
2121

2222
.PHONY: release
2323
release: ## Builds a release with goreleaser
24-
release: dockerauth install-tool.goreleaser install-tool.golang ; $(info $(M) building release $*)
24+
release: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $(info $(M) building release $*)
2525
goreleaser --debug=$(GORELEASER_DEBUG) \
2626
release \
2727
--rm-dist \
@@ -31,7 +31,7 @@ release: dockerauth install-tool.goreleaser install-tool.golang ; $(info $(M) b
3131

3232
.PHONY: release-snapshot
3333
release-snapshot: ## Builds a snapshot release with goreleaser
34-
release-snapshot: dockerauth install-tool.goreleaser install-tool.golang ; $(info $(M) building snapshot release $*)
34+
release-snapshot: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $(info $(M) building snapshot release $*)
3535
goreleaser --debug=$(GORELEASER_DEBUG) \
3636
release \
3737
--snapshot \

0 commit comments

Comments
 (0)