Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update controller-runtime to v0.12.3 #129

Merged
merged 32 commits into from Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
97aff6d
fix(deps): update kubernetes packages to v0.24.3
renovate[bot] Jul 31, 2022
3098674
simplify implementation
nakamasato Aug 1, 2022
abe2c4a
fix 'Stopping and waiting for non leader election runnables' error
nakamasato Aug 21, 2022
c160edb
fix Unit test 'Status.Phase should be NotReady'
nakamasato Aug 21, 2022
a5153e8
fix lint error: Update is not checked (errcheck)
nakamasato Aug 21, 2022
bb2315b
reduced the probability of failing e2e
nakamasato Aug 23, 2022
00a42b7
change timeout
nakamasato Aug 23, 2022
029af85
add debug tool to controller test
nakamasato Sep 25, 2022
353a73d
upgrade mysql to 5.7
nakamasato Mar 5, 2023
91e4230
comment out startDebugTool
nakamasato Mar 6, 2023
8cc375c
fix startDebugTool
nakamasato Mar 6, 2023
56df9ee
update tests
nakamasato Mar 9, 2023
07ceb2a
update
nakamasato Mar 10, 2023
a6436e8
fix skaffold
nakamasato Mar 11, 2023
13fefd8
fix
nakamasato Mar 11, 2023
d09189b
fix
nakamasato Mar 11, 2023
bf900a3
set timeout to 300
nakamasato Mar 11, 2023
32ff7d3
extend timeout
nakamasato Mar 11, 2023
0200c38
remove finalizers' test
nakamasato Mar 11, 2023
fed4177
remove unnecessary import
nakamasato Mar 11, 2023
b1b4700
remove recreation step
nakamasato Mar 11, 2023
11c2618
not delete mysql deployment just delete service
nakamasato Mar 11, 2023
8a69af3
extend timeout
nakamasato Mar 11, 2023
3e03245
fix
nakamasato Mar 11, 2023
3fef452
error
nakamasato Mar 11, 2023
37b979c
fix consistently timeout
nakamasato Mar 11, 2023
b017ea1
update
nakamasato Mar 12, 2023
13fc0eb
update
nakamasato Mar 12, 2023
45de41e
remove tail
nakamasato Mar 12, 2023
5506ddd
use PingContext for db
nakamasato Mar 12, 2023
c0b1048
set 100 millisecond
nakamasato Mar 12, 2023
765d9f7
set timeout to 1 sec
nakamasato Mar 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 18 additions & 11 deletions .github/workflows/e2e.yml
Expand Up @@ -14,12 +14,7 @@ jobs:
e2e-with-kuttl:
runs-on: ubuntu-latest
steps:
- name: set up
uses: actions/setup-go@v3
with:
go-version: 1.18

- uses: actions/checkout@master
- uses: actions/checkout@v3

# https://krew.sigs.k8s.io/docs/user-guide/setup/install/
- name: krew - install
Expand All @@ -44,23 +39,35 @@ jobs:
kubectl krew install kuttl
kubectl kuttl -v

- name: e2e-with-kuttl
run: make e2e-with-kuttl
- name: docker build
run: docker build -t mysql-operator .

- name: kuttl test
run: make kuttl

e2e-with-ginkgo:
runs-on: ubuntu-latest
steps:
- name: set up
- uses: actions/checkout@v3

- name: setup go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version-file: ./go.mod
cache: true

- name: install skaffold # TODO: #69 Enable to install skaffold in e2e
run: |
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/

- uses: actions/checkout@master
- name: create kind cluster
working-directory: e2e
run: kind create cluster --name mysql-operator-e2e --kubeconfig kubeconfig --config kind-config.yml --wait 30s

- name: skaffold run
working-directory: e2e
run: skaffold run --kubeconfig kubeconfig

- name: e2e-with-ginkgo
run: make e2e-with-ginkgo
67 changes: 65 additions & 2 deletions CONTRIBUTING.md
@@ -1,6 +1,16 @@
# Code Style

- [golangci-lint](https://golangci-lint.run)
[golangci-lint](https://golangci-lint.run)

Install:
```
brew install golangci-lint
```
Run lint:
```
golangci-lint run ./...
```


# Run mysql-operator

Expand Down Expand Up @@ -53,6 +63,33 @@
kubectl delete -f config/samples/mysql_v1alpha1_mysqluser.yaml
kubectl delete -f config/samples/mysql_v1alpha1_mysql.yaml
```

TODO: get stuck in deletion.

<details>

```
1.6780545572555468e+09 INFO [FetchMySQL] Not found {"controller": "mysql", "controllerGroup": "mysql.nakamasato.com", "controllerKind": "MySQL", "mySQL": {"name":"mysql-sample","namespace":"default"}, "namespace": "default", "name": "mysql-sample", "reconcileID": "0b6db5c6-8b3b-43ce-b903-a4959d55064e", "mysql.Name": "", "mysql.Namespace": ""}
1.678054557255548e+09 INFO [FetchMySQLUser] Found. {"controller": "mysqluser", "controllerGroup": "mysql.nakamasato.com", "controllerKind": "MySQLUser", "mySQLUser": {"name":"nakamasato","namespace":"default"}, "namespace": "default", "name": "nakamasato", "reconcileID": "78d4a7cf-5be0-4d47-82c0-38c7fdcf675b", "name": "nakamasato", "mysqlUser.Namespace": "default"}
1.678054557255587e+09 ERROR [FetchMySQL] Failed {"controller": "mysqluser", "controllerGroup": "mysql.nakamasato.com", "controllerKind": "MySQLUser", "mySQLUser": {"name":"nakamasato","namespace":"default"}, "namespace": "default", "name": "nakamasato", "reconcileID": "78d4a7cf-5be0-4d47-82c0-38c7fdcf675b", "error": "MySQL.mysql.nakamasato.com \"mysql-sample\" not found"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
/Users/m.naka/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.3/pkg/internal/controller/controller.go:121
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
/Users/m.naka/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.3/pkg/internal/controller/controller.go:320
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
/Users/m.naka/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.3/pkg/internal/controller/controller.go:273
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
/Users/m.naka/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.3/pkg/internal/controller/controller.go:234
```

When getting stuck:

```
kubectl patch mysqluser nakamasato -p '{"metadata":{"finalizers": []}}' --type=merge
```

</details>

1. Secret is deleted.
```
kubectl get secret
Expand Down Expand Up @@ -83,6 +120,7 @@

```
make uninstall
docker rm -f $(docker ps | grep mysql | head -1 |awk '{print $1}')
```

## Local kubernetes
Expand Down Expand Up @@ -135,6 +173,14 @@ make uninstall
kubectl delete -f config/samples-on-k8s/mysql_v1alpha1_mysqluser.yaml
kubectl delete -f config/samples-on-k8s/mysql_v1alpha1_mysql.yaml
```

TODO: Get stuck:

```
kubectl exec -it $(kubectl get po | grep mysql | head -1 | awk '{print $1}') -- mysql -uroot -ppassword -e 'delete from mysql.user where User = "nakamasato";'
kubectl patch mysqluser nakamasato -p '{"metadata":{"finalizers": []}}' --type=merge
```

1. Stop the `skaffold dev` by `ctrl-c` -> will clean up the controller, CRDs, and installed resources.
# Test

Expand Down Expand Up @@ -206,7 +252,7 @@ make e2e-with-ginkgo
```
1. Deploy `CRD`, `mysql-operator`, and MySQL with `Deployment`:
```
cd e2e && skaffold run --kubeconfig kubeconfig
cd e2e && skaffold run --kubeconfig kubeconfig --tail
```

</details>
Expand Down Expand Up @@ -382,5 +428,22 @@ https://cloud.redhat.com/blog/kubernetes-operators-best-practices
1. Return the error in the status of the object. https://pkg.go.dev/github.com/shivanshs9/operator-utils@v1.0.1#section-readme
1. Generate an event describing the error.

### Error1: `Operation cannot be fulfilled on mysqlusers.mysql.nakamasato.com \"john\": StorageError: invalid object, Code: 4, Key: /registry/mysql.nakamasato.com/mysqlusers/default/john, ResourceVersion: 0, AdditionalErrorMsg: Precondition failed: UID in precondition: cd9c94d1-992a-457d-8fab-489b21ed02e9, UID in object meta:`

```
[manager] 1.6781410047933352e+09 ERROR Reconciler error {"controller": "mysqluser", "controllerGroup": "mysql.nakamasato.com", "controllerKind": "MySQLUser", "mySQLUser": {"name":"john","namespace":"default"}, "namespace": "default", "name": "john", "reconcileID": "85fc0e64-f2b9-413f-af44-46ff1daad7f7", "error": "Operation cannot be fulfilled on mysqlusers.mysql.nakamasato.com \"john\": StorageError: invalid object, Code: 4, Key: /registry/mysql.nakamasato.com/mysqlusers/default/john, ResourceVersion: 0, AdditionalErrorMsg: Precondition failed: UID in precondition: cd9c94d1-992a-457d-8fab-489b21ed02e9, UID in object meta: "}
```

UID in precondition and UID in object meta are different?

https://github.com/kubernetes-sigs/controller-runtime/issues/2209

## Slow build

```
time CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go 161.57s user 24.90s system 283% cpu 1:05.76 total
```

## MySQL
- http://go-database-sql.org/index.html
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -40,7 +40,7 @@ IMG ?= ghcr.io/nakamasato/mysql-operator:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.21
ENVTEST_K8S_VERSION = 1.24

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -88,7 +88,7 @@ vet: ## Run go vet against code.
go vet ./...

test: ginkgo manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GINKGO) -cover -coverprofile cover.out -covermode=atomic -skipPackage=e2e ./...
ACK_GINKGO_DEPRECATIONS=1.16.5 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" $(GINKGO) -cover -coverprofile cover.out -covermode=atomic -skipPackage=e2e ./...

##@ Build

Expand Down Expand Up @@ -216,4 +216,4 @@ e2e-with-kuttl:

.PHONY: e2e-with-ginkgo
e2e-with-ginkgo: ginkgo
$(GINKGO) e2e
ACK_GINKGO_RC=true $(GINKGO) e2e
7 changes: 3 additions & 4 deletions controllers/mysql_controller.go
Expand Up @@ -26,7 +26,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/go-logr/logr"
mysqlv1alpha1 "github.com/nakamasato/mysql-operator/api/v1alpha1"
)

Expand All @@ -51,7 +50,7 @@ type MySQLReconciler struct {
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.9.2/pkg/reconcile
func (r *MySQLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
log := log.FromContext(ctx).WithName("MySQLReconciler")

// Fetch MySQL
mysql := &mysqlv1alpha1.MySQL{}
Expand All @@ -67,7 +66,7 @@ func (r *MySQLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
}

// Get referenced number
referencedNum, err := r.countReferencesByMySQLUser(ctx, log, mysql)
referencedNum, err := r.countReferencesByMySQLUser(ctx, mysql)
if err != nil {
log.Error(err, "[countReferences] Failed get referencedNum")
return ctrl.Result{}, err
Expand Down Expand Up @@ -96,7 +95,7 @@ func (r *MySQLReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func (r *MySQLReconciler) countReferencesByMySQLUser(ctx context.Context, log logr.Logger, mysql *mysqlv1alpha1.MySQL) (int, error) {
func (r *MySQLReconciler) countReferencesByMySQLUser(ctx context.Context, mysql *mysqlv1alpha1.MySQL) (int, error) {
// 1. Get the referenced MySQLUser instances.
// 2. Return the number of referencing MySQLUser.
mysqlUserList := &mysqlv1alpha1.MySQLUserList{}
Expand Down
3 changes: 1 addition & 2 deletions controllers/mysql_controller_test.go
Expand Up @@ -8,7 +8,6 @@ import (
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -22,7 +21,7 @@ var _ = Describe("MySQL controller", func() {

BeforeEach(func() {
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
Scheme: scheme,
})
Expect(err).ToNot(HaveOccurred())

Expand Down