Skip to content

Commit 4c74f8c

Browse files
authored
Merge pull request #4 from authzed/gha
add github workflows
2 parents 0c2829d + a034fe5 commit 4c74f8c

29 files changed

+286
-275
lines changed

Diff for: .github/dependabot.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: "gomod"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"
8+
labels:
9+
- "area/dependencies"
10+
- package-ecosystem: "docker"
11+
directory: "/"
12+
schedule:
13+
interval: "monthly"
14+
labels:
15+
- "area/dependencies"

Diff for: .github/workflows/build-test.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: "Build & Test"
3+
on: # yamllint disable-line rule:truthy
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
branches:
9+
- "*"
10+
jobs:
11+
unit:
12+
name: "Unit"
13+
runs-on: "ubuntu-latest"
14+
steps:
15+
- uses: "actions/checkout@v3"
16+
- uses: "actions/setup-go@v3"
17+
with:
18+
go-version: "~1.19"
19+
- uses: "authzed/actions/go-test@main"

Diff for: .github/workflows/cla.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: "CLA"
3+
on: # yamllint disable-line rule:truthy
4+
issue_comment:
5+
types:
6+
- "created"
7+
pull_request_target:
8+
types:
9+
- "opened"
10+
- "closed"
11+
- "synchronize"
12+
jobs:
13+
cla:
14+
name: "Check Signature"
15+
runs-on: "ubuntu-latest"
16+
steps:
17+
- uses: "authzed/actions/cla-check@main"
18+
with:
19+
github_token: "${{ secrets.GITHUB_TOKEN }}"
20+
cla_assistant_token: "${{ secrets.CLA_ASSISTANT_ACCESS_TOKEN }}"

Diff for: .github/workflows/lint.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: "Lint"
3+
on: # yamllint disable-line rule:truthy
4+
push:
5+
branches:
6+
- "!dependabot/*"
7+
- "main"
8+
pull_request:
9+
branches: ["*"]
10+
jobs:
11+
go-lint:
12+
name: "Lint Go"
13+
runs-on: "ubuntu-latest"
14+
steps:
15+
- uses: "actions/checkout@v3"
16+
- uses: "actions/setup-go@v3"
17+
with:
18+
go-version: "~1.19"
19+
- uses: "authzed/actions/gofumpt@main"
20+
- uses: "authzed/actions/go-generate@main"
21+
- uses: "authzed/actions/golangci-lint@main"
22+
23+
extra-lint:
24+
name: "Lint YAML & Markdown"
25+
runs-on: "ubuntu-latest"
26+
steps:
27+
- uses: "actions/checkout@v3"
28+
- uses: "authzed/actions/yaml-lint@main"
29+
- uses: "authzed/actions/markdown-lint@main"
30+
31+
# TODO: enable when public
32+
# codeql:
33+
# name: "Analyze with CodeQL"
34+
# runs-on: "ubuntu-latest"
35+
# permissions:
36+
# actions: "read"
37+
# contents: "read"
38+
# security-events: "write"
39+
# strategy:
40+
# fail-fast: false
41+
# matrix:
42+
# language: ["go"]
43+
# steps:
44+
# - uses: "actions/checkout@v3"
45+
# - uses: "authzed/actions/codeql@main"

Diff for: .golangci.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
run:
3+
timeout: "5m"
4+
output:
5+
sort-results: true
6+
linters:
7+
enable:
8+
- "bidichk"
9+
- "bodyclose"
10+
- "deadcode"
11+
- "errcheck"
12+
- "errname"
13+
- "errorlint"
14+
- "gofumpt"
15+
- "goimports"
16+
- "goprintffuncname"
17+
- "gosec"
18+
- "gosimple"
19+
- "govet"
20+
- "ifshort"
21+
- "importas"
22+
- "ineffassign"
23+
- "makezero"
24+
- "prealloc"
25+
- "predeclared"
26+
- "promlinter"
27+
- "revive"
28+
- "rowserrcheck"
29+
- "staticcheck"
30+
- "structcheck"
31+
- "stylecheck"
32+
- "tenv"
33+
- "typecheck"
34+
- "unconvert"
35+
- "unused"
36+
- "varcheck"
37+
- "wastedassign"
38+
- "whitespace"

Diff for: .markdownlint.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
line-length: false
3+
no-hard-tabs: false

Diff for: .yamllint

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# vim: ft=yaml
2+
---
3+
yaml-files:
4+
- "*.yaml"
5+
- "*.yml"
6+
- ".yamllint"
7+
extends: "default"
8+
rules:
9+
quoted-strings: "enable"
10+
line-length: "disable"

Diff for: CONTRIBUTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,17 @@ go get github.com/org/newdependency@version
8585
```
8686

8787
Continuous integration enforces that `go mod tidy` has been run.
88+
89+
### Codegen and Linting
90+
91+
To run all code generators:
92+
93+
```sh
94+
go generate ./...
95+
```
96+
97+
To run all tooling, including linters:
98+
99+
```sh
100+
go generate -tags tools ./...
101+
```

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Looking to contribute? See [CONTRIBUTING.md].
4141
[Discord]: https://authzed.com/discord
4242
[CONTRIBUTING.md]: https://github.com/authzed/spicedb/blob/main/CONTRIBUTING.md
4343

44-
## Overview
44+
## Overview
4545

4646
### Handlers
4747

@@ -70,7 +70,7 @@ func mainControlLoop(ctx context.Context) {
7070
```
7171

7272
The `handler` package contains utilities for building, composing, and decorating handlers, and for building large state machines with them.
73-
See the [docs]() for more details.
73+
See the [docs](https://pkg.go.dev/github.com/authzed/controller-idioms/handler) for more details.
7474

7575
Handlers take some inspiration from [statecharts](https://statecharts.dev/) to deal with the complexity of writing and maintaining controllers, while staying close to golang idioms.
7676

@@ -96,6 +96,7 @@ func (h *UseHandler) Handle(ctx context.Context) {
9696
`Handlers` are typically chained in a way that preserves the context between handlers, but not always.
9797

9898
For example:
99+
99100
```go
100101
var CtxExpensiveObject = typedctx.NewKey[ExpensiveComputation]()
101102

@@ -147,7 +148,7 @@ secrets, err := secretIndexer.ByIndex("my-index-name", "my-index-value")
147148

148149
### Controllers and Managers
149150

150-
The `manager` package provides an optional lightweight controller `Manager` abstraction (similar to kubernetes controller manager, or the manager from controller runtime). It also provides a simple `Controller` abstraction and some basic implementations.
151+
The `manager` package provides an optional lightweight controller `Manager` abstraction (similar to kubernetes controller manager, or the manager from controller runtime). It also provides a simple `Controller` abstraction and some basic implementations.
151152

152153
The rest of `controller-idioms` can be used without using these if you are already using another solution.
153154

@@ -190,7 +191,6 @@ The queue operations are:
190191

191192
If calling these controls from a handler, it's important to `return` immediately so that the handler does not continue processing a key that the queue thinks has stopped.
192193

193-
194194
### Middleware
195195

196196
Middleware can be injected between handlers with the `middleware` package.

Diff for: adopt/adopt_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func TestSecretAdopterHandler(t *testing.T) {
300300
}
301301
for _, tt := range tests {
302302
t.Run(tt.name, func(t *testing.T) {
303-
ctrls := &fake.FakeOperations{}
303+
ctrls := &fake.FakeInterface{}
304304
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{IndexName: OwnerKeysFromMeta(OwnerAnnotationPrefix)})
305305
IndexAddUnstructured(t, indexer, tt.secretsInIndex)
306306

@@ -377,7 +377,6 @@ func NewSecretAdoptionHandler(recorder record.EventRecorder, getFromCache func(c
377377
}
378378

379379
func ExampleAdoptionHandler_Handle() {
380-
381380
}
382381

383382
func ExpectEvents(t *testing.T, recorder *record.FakeRecorder, expected []string) {

Diff for: bootstrap/crds_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import (
1010
var crdFS embed.FS
1111

1212
func ExampleCRD() {
13-
CRD(&rest.Config{}, crdFS, "example")
13+
_ = CRD(&rest.Config{}, crdFS, "example")
1414
// Output:
1515
}

Diff for: bootstrap/example.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
apiVersion: v1
2-
kind: Secret
1+
---
2+
apiVersion: "v1"
3+
kind: "Secret"
34
metadata:
4-
namespace: test
5-
name: example
6-
type: Opaque
5+
namespace: "test"
6+
name: "example"
7+
type: "Opaque"
78
data:
8-
required: data
9+
required: "data"

Diff for: bootstrap/example/crd.yaml

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
apiVersion: apiextensions.k8s.io/v1
2-
kind: CustomResourceDefinition
1+
---
2+
apiVersion: "apiextensions.k8s.io/v1"
3+
kind: "CustomResourceDefinition"
34
metadata:
4-
name: mytype.example.com
5+
name: "mytype.example.com"
56
spec:
6-
group: example.com
7+
group: "example.com"
78
names:
8-
kind: MyType
9-
listKind: MyTypeList
10-
plural: mytypes
11-
singular: mytype
12-
scope: Namespaced
9+
kind: "MyType"
10+
listKind: "MyTypeList"
11+
plural: "mytypes"
12+
singular: "mytype"
13+
scope: "Namespaced"
1314
versions:
14-
- name: v1
15+
- name: "v1"
1516
served: true
1617
storage: true

Diff for: bootstrap/resource_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ func ExampleResourceFromFile() {
2121

2222
secretGVR := corev1.SchemeGroupVersion.WithResource("secrets")
2323
scheme := runtime.NewScheme()
24-
corev1.AddToScheme(scheme)
24+
if err := corev1.AddToScheme(scheme); err != nil {
25+
panic(err)
26+
}
2527
scheme.AddKnownTypes(corev1.SchemeGroupVersion, &corev1.Secret{})
2628
client := secretApplyPatchHandlingFakeClient(scheme)
2729

2830
// create the object from the file
2931
// the example is a secret, but it could be any built-in or CRD-defined type
30-
ResourceFromFile[*corev1.Secret](ctx, "bootstrapped-secret", secretGVR, client, "./example.yaml", 0)
32+
_, err := ResourceFromFile[*corev1.Secret](ctx, "bootstrapped-secret", secretGVR, client, "./example.yaml", 0)
33+
if err != nil {
34+
panic(err)
35+
}
3136

3237
for {
3338
secret, err := client.Resource(secretGVR).Namespace("test").Get(ctx, "example", metav1.GetOptions{})

Diff for: client/rest.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package client
2+
3+
import "k8s.io/client-go/rest"
4+
5+
func DisableClientSideRateLimiting(restConfig *rest.Config) {
6+
restConfig.Burst = 2000
7+
restConfig.QPS = -1
8+
}

Diff for: component/ensure_component_test.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,23 @@ func TestEnsureServiceHandler(t *testing.T) {
7979
},
8080
Annotations: map[string]string{
8181
hashKey: "n5d8h56h6dhc7h96h8h545h96q",
82-
}}},
82+
},
83+
}},
8384
},
8485
},
8586
{
8687
name: "deletes extra services if a matching service exists",
87-
existingServices: []runtime.Object{&corev1.Service{ObjectMeta: metav1.ObjectMeta{
88-
Name: "test",
89-
Namespace: "test",
90-
Labels: map[string]string{
91-
"example.com/component": "the-main-service-component",
88+
existingServices: []runtime.Object{&corev1.Service{
89+
ObjectMeta: metav1.ObjectMeta{
90+
Name: "test",
91+
Namespace: "test",
92+
Labels: map[string]string{
93+
"example.com/component": "the-main-service-component",
94+
},
95+
Annotations: map[string]string{
96+
hashKey: "n5d8h56h6dhc7h96h8h545h96q",
97+
},
9298
},
93-
Annotations: map[string]string{
94-
hashKey: "n5d8h56h6dhc7h96h8h545h96q",
95-
}},
9699
}, &corev1.Service{ObjectMeta: metav1.ObjectMeta{
97100
Name: "extra",
98101
Namespace: "test",
@@ -108,7 +111,7 @@ func TestEnsureServiceHandler(t *testing.T) {
108111
ctx, cancel := context.WithCancel(context.Background())
109112
defer cancel()
110113

111-
ctrls := &fake.FakeOperations{}
114+
ctrls := &fake.FakeInterface{}
112115
applyCalled := false
113116
deleteCalled := false
114117

Diff for: go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/cespare/xxhash/v2 v2.1.2
77
github.com/davecgh/go-spew v1.1.1
88
github.com/fsnotify/fsnotify v1.5.4
9+
github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0
910
github.com/prometheus/client_golang v1.13.0
1011
github.com/stretchr/testify v1.8.0
1112
golang.org/x/exp v0.0.0-20220823124025-807a23277127
@@ -19,6 +20,7 @@ require (
1920
k8s.io/controller-manager v0.25.0
2021
k8s.io/klog/v2 v2.70.1
2122
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73
23+
mvdan.cc/gofumpt v0.3.1
2224
sigs.k8s.io/controller-runtime v0.12.3
2325
)
2426

@@ -80,12 +82,14 @@ require (
8082
go.uber.org/atomic v1.7.0 // indirect
8183
go.uber.org/multierr v1.6.0 // indirect
8284
go.uber.org/zap v1.19.1 // indirect
85+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
8386
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
8487
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
8588
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
8689
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
8790
golang.org/x/text v0.3.7 // indirect
8891
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
92+
golang.org/x/tools v0.1.12 // indirect
8993
google.golang.org/appengine v1.6.7 // indirect
9094
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
9195
google.golang.org/grpc v1.47.0 // indirect

0 commit comments

Comments
 (0)