Skip to content

Commit f7481a6

Browse files
authored
Automatically create personal organization (#64)
This PR introduces a new controller that will automatically create a personal organization for every user that's created within Milo. This also introduces a new GitHub action workflow to publish the kustomize manifests and docker container.
2 parents b2f5b06 + a4b559b commit f7481a6

27 files changed

Lines changed: 934 additions & 232 deletions

.devcontainer/devcontainer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Kubebuilder DevContainer",
3-
"image": "docker.io/golang:1.23",
3+
"image": "docker.io/golang:1.24",
44
"features": {
55
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
66
"ghcr.io/devcontainers/features/git:1": {}
@@ -22,4 +22,3 @@
2222

2323
"onCreateCommand": "bash .devcontainer/post-install.sh"
2424
}
25-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
publish-container-image:
9+
permissions:
10+
id-token: write
11+
contents: read
12+
packages: write
13+
uses: datum-cloud/actions/.github/workflows/publish-docker.yaml@v1.5.1
14+
with:
15+
image-name: datum
16+
secrets: inherit
17+
18+
19+
publish-kustomize-bundles:
20+
permissions:
21+
id-token: write
22+
contents: read
23+
packages: write
24+
uses: datum-cloud/actions/.github/workflows/publish-kustomize-bundle.yaml@v1.5.1
25+
with:
26+
bundle-name: ghcr.io/datum-cloud/datum-kustomize
27+
bundle-path: config
28+
secrets: inherit

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- name: Run linter
2121
uses: golangci/golangci-lint-action@v6
2222
with:
23-
version: v1.63.4
23+
version: v2.1.6

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ go.work
2525
*.swp
2626
*.swo
2727
*~
28+
29+
# Ignore kubeconfig
30+
.kube

.golangci.yml

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
7+
- copyloopvar
228
- dupl
239
- errcheck
24-
- copyloopvar
2510
- ginkgolinter
2611
- goconst
2712
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3113
- govet
3214
- ineffassign
33-
- lll
3415
- misspell
3516
- nakedret
3617
- prealloc
3718
- revive
3819
- staticcheck
39-
- typecheck
4020
- unconvert
4121
- unparam
4222
- unused
43-
44-
linters-settings:
45-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
4629
rules:
47-
- name: comment-spacings
30+
- linters:
31+
- dupl
32+
path: internal/*
33+
paths:
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
formatters:
38+
enable:
39+
- gofmt
40+
- goimports
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- third_party$
45+
- builtin$
46+
- examples$

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM docker.io/golang:1.23 AS builder
2+
FROM docker.io/golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -13,6 +13,7 @@ RUN go mod download
1313

1414
# Copy the go source
1515
COPY cmd/ cmd/
16+
COPY internal/ internal/
1617

1718
# Build
1819
# the GOARCH has not a default value to allow the binary be built according to the host where the command

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4646
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4747

4848
.PHONY: generate
49-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
49+
generate: controller-gen defaulter-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5050
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
51+
$(DEFAULTER_GEN) ./internal/config --output-file=zz_generated.defaults.go
5152

5253
.PHONY: fmt
5354
fmt: ## Run go fmt against code.
@@ -168,17 +169,19 @@ KUBECTL ?= kubectl
168169
KIND ?= kind
169170
KUSTOMIZE ?= $(LOCALBIN)/kustomize
170171
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
172+
DEFAULTER_GEN ?= $(LOCALBIN)/defaulter-gen
171173
ENVTEST ?= $(LOCALBIN)/setup-envtest
172174
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
173175

174176
## Tool Versions
175177
KUSTOMIZE_VERSION ?= v5.6.0
176178
CONTROLLER_TOOLS_VERSION ?= v0.17.2
179+
DEFAULTER_GEN_VERSION ?= v0.32.3
177180
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
178181
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
179182
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
180183
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
181-
GOLANGCI_LINT_VERSION ?= v1.63.4
184+
GOLANGCI_LINT_VERSION ?= v2.1.6
182185

183186
.PHONY: kustomize
184187
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -190,6 +193,11 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
190193
$(CONTROLLER_GEN): $(LOCALBIN)
191194
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
192195

196+
.PHONY: defaulter-gen
197+
defaulter-gen: $(DEFAULTER_GEN) ## Download defaulter-gen locally if necessary.
198+
$(DEFAULTER_GEN): $(LOCALBIN)
199+
$(call go-install-tool,$(DEFAULTER_GEN),k8s.io/code-generator/cmd/defaulter-gen,$(DEFAULTER_GEN_VERSION))
200+
193201
.PHONY: setup-envtest
194202
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
195203
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
@@ -206,7 +214,7 @@ $(ENVTEST): $(LOCALBIN)
206214
.PHONY: golangci-lint
207215
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
208216
$(GOLANGCI_LINT): $(LOCALBIN)
209-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
217+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
210218

211219
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
212220
# $1 - target path with name of binary

PROJECT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ layout:
77
- go.kubebuilder.io/v4
88
projectName: datum-cloud
99
repo: go.datum.net/datum
10+
resources:
11+
- controller: true
12+
domain: iam.datumapis.com
13+
external: true
14+
kind: User
15+
path: go.miloapis.com/milo/pkg/apis/iam/v1alpha1
16+
version: v1alpha1
1017
version: "3"

0 commit comments

Comments
 (0)