Skip to content

Commit

Permalink
fix: race condition causing .status.accessmessage to not be setup (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
diranged authored Nov 29, 2022
1 parent c1fd6f5 commit 3035f5e
Show file tree
Hide file tree
Showing 26 changed files with 299 additions and 212 deletions.
20 changes: 1 addition & 19 deletions .github/actions/setup-go/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,5 @@ runs:
- name: Set up Go
uses: actions/setup-go@v3
with:
cache: true
go-version-file: "go.mod"

- name: Find the Go Cache
id: go
shell: bash
run: |
echo "build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Cache the Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go.outputs.build-cache }}
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}

- name: Cache Go Dependencies
uses: actions/cache@v3
with:
path: ${{ steps.go.outputs.mod-cache }}
key: ${{ runner.os }}-mod-${{ hashFiles('**/go.sum') }}
7 changes: 2 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@ jobs:
- name: Set up Go
uses: ./.github/actions/setup-go

- name: Build Binaries
run: make build cli

- name: Build Docker Image
run: make docker-build
- name: Build Artifacts
run: make build
18 changes: 7 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
if: needs.detect-noop.outputs.noop != 'true'
uses: ./.github/workflows/docgen.yaml


lint:
needs: detect-noop
if: needs.detect-noop.outputs.noop != 'true'
Expand All @@ -43,16 +42,13 @@ jobs:
uses: ./.github/workflows/test.yaml

test-e2e:
needs: detect-noop
needs: build
if: needs.detect-noop.outputs.noop != 'true'
uses: ./.github/workflows/test-e2e.yaml

# Disabled: The cross-platform builds take 10+m... so limiting these builds
# to just `main` for now.
#
# publish-dry:
# needs: detect-noop
# if: needs.detect-noop.outputs.noop != 'true'
# uses: ./.github/workflows/publish.yaml
# with:
# push: false
publish-dry:
needs: build
if: needs.detect-noop.outputs.noop != 'true'
uses: ./.github/workflows/publish.yaml
with:
publish: false
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
uses: ./.github/workflows/publish.yaml
needs: [test-e2e, unit-tests, lint, build]
with:
push: true
publish: true
77 changes: 22 additions & 55 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ name: Reusable Workflow
on:
workflow_call:
inputs:
push:
type: boolean
default: false
release:
publish:
type: boolean
default: false

Expand All @@ -21,26 +18,19 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false

- name: Set up Go
uses: ./.github/actions/setup-go

- name: Build Binaries
run: make build cli

- name: Setup QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Artifacts
run: make build

- name: Log in to the Container registry
uses: docker/[email protected]
Expand All @@ -49,50 +39,27 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: |
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{version}}
type=semver,pattern={{major}}
type=sha
type=ref,event=pr
type=ref,event=branch
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push Docker image
uses: docker/build-push-action@v3.2.0
- if: ${{ ! inputs.publish }}
uses: goreleaser/goreleaser-action@v2
with:
context: .
push: ${{ inputs.push }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
distribution: goreleaser
version: latest
args: release --snapshot --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Just to make the .goreleaser.yml pass when not using `make ..` targets.
IMG: img:local

- name: Upload binaries to release
if: ${{ inputs.release }}
uses: svenstaro/upload-release-action@v2
- if: ${{ inputs.publish }}
uses: goreleaser/goreleaser-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file_glob: true
file: outputs/ozctl-*
tag: ${{ github.ref }}
overwrite: true
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Just to make the .goreleaser.yml pass when not using `make ..` targets.
IMG: img:local
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Controller Release
name: Release

on:
push:
Expand All @@ -11,5 +11,4 @@ jobs:
publish:
uses: ./.github/workflows/publish.yaml
with:
push: true
release: true
publish: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ testbin/*
Dockerfile.cross

# Binary outputs
outputs/*
dist

# docker-buildx
.buildx_cache
Expand Down
96 changes: 96 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
before:
# https://goreleaser.com/customization/hooks/
hooks:
- go mod tidy

builds:
# Manager
- id: manager
main: ./
binary: manager
env: [CGO_ENABLED=0]
goos:
- linux
goarch:
- amd64
- arm64

# CLI
- id: cli
main: ./ozctl
binary: ozctl
env: [CGO_ENABLED=0]
goos:
- darwin
goarch:
- amd64
- arm64

universal_binaries:
- id: cli
name_template: ozctl
replace: true

dockers:
# Local image only used for `make docker-load`
- image_templates: ["{{ .Env.IMG }}"]
dockerfile: Dockerfile
use: buildx
skip_push: true

# Potential Release - AMD64
- image_templates: ["ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}-amd64"]
dockerfile: Dockerfile
goarch: amd64
use: buildx
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/diranged/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/diranged/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0

# Potential Release - ARM64
- image_templates: ["ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}-arm64v8"]
goarch: arm64
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/diranged/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/diranged/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=Apache-2.0

docker_manifests:
- id:
name_template: ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}-arm64v8

- name_template: ghcr.io/diranged/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/diranged/{{ .ProjectName }}:{{ .Version }}-arm64v8

# https://goreleaser.com/customization/changelog/
changelog:
use: github
groups:
- title: Features
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 0
- title: Bug fixes
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 1
- title: Others
order: 999
41 changes: 28 additions & 13 deletions Custom.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
SOURCE := $(wildcard api/*/*.go controller/*.go ozctl/*.go ozctl/*/*.go)

ifeq (true,$(PUBLISH))
GORELEASER_FLAGS := --rm-dist
else
GORELEASER_FLAGS := --skip-publish --snapshot --rm-dist
endif

## Tool Binaries
REVIVE_VER ?= v1.2.4
REVIVE ?= $(LOCALBIN)/revive
Expand All @@ -10,12 +16,14 @@ GOFUMPT ?= $(LOCALBIN)/gofumpt
GOLINES_VER ?= v0.11.0
GOLINES ?= $(LOCALBIN)/golines

GORELEASER_VER ?= v1.13.1
GORELEASER ?= $(LOCALBIN)/goreleaser

GEN_CRD_API_DOCS_VER ?= v0.3.1-0.20220223025230-af7c5e0048a3
GEN_CRD_API_DOCS ?= $(LOCALBIN)/go-crd-api-reference-docs

.PHONY: docker-load
docker-load:
kind load docker-image $(IMG) -n $(KIND_CLUSTER_NAME)
goreleaser:


.PHONY: cover
cover:
Expand All @@ -33,6 +41,11 @@ lint: revive
test-e2e:
go test ./test/e2e/ -v -ginkgo.v

.PHONY: goreleaser
goreleaser: $(GORELEASER)
$(GORELEASER):
GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser@$(GORELEASER_VER)

.PHONY: gofumpt
gofumpt: $(GOFUMPT)
$(GOFUMPT):
Expand All @@ -53,6 +66,18 @@ revive: $(REVIVE) ## Download revive locally if necessary.
$(REVIVE): $(LOCALBIN) Custom.mk
GOBIN=$(LOCALBIN) go install github.com/mgechev/revive@$(REVIVE_VER)

.PHONY: release
release: $(GORELEASER)
IMG=$(IMG) $(GORELEASER) release $(GORELEASER_FLAGS)

.PHONY: build
build: $(GORELEASER)
PUBLISH=false $(MAKE) release

.PHONY: docker-load
docker-load:
kind load docker-image $(IMG) -n $(KIND_CLUSTER_NAME)

gen-crd-api-reference-docs: $(GEN_CRD_API_DOCS)
$(GEN_CRD_API_DOCS):
GOBIN=$(LOCALBIN) go install github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_CRD_API_DOCS_VER)
Expand All @@ -65,13 +90,3 @@ godocs: $(GEN_CRD_API_DOCS)
-template-dir $$(go env GOMODCACHE)/github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_CRD_API_DOCS_VER)/template \
-out-file API.md \
-v 5

##@ Build CLI
.PHONY: cli
cli: outputs/ozctl-osx outputs/ozctl-osx-arm64

outputs/ozctl-osx: ozctl controllers api $(SOURCE)
GOOS=darwin GOARCH=amd64 LDFLAGS=$(RELEASE_LDFLAGS) go build -o $@ ./ozctl

outputs/ozctl-osx-arm64: ozctl controllers api $(SOURCE)
GOOS=darwin GOARCH=arm64 LDFLAGS=$(RELEASE_LDFLAGS) go build -o $@ ./ozctl
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $ kind create cluster
install/upgrade the controller:

```sh
$ make docker-build docker-load manifests deploy
$ make release docker-load manifests deploy
...
service/oz-controller-manager-metrics-service created
deployment.apps/oz-controller-manager created
Expand Down
Loading

0 comments on commit 3035f5e

Please sign in to comment.