How to test operator - cniackz/public GitHub Wiki
Related:
How we tested Operator v5.0.1:
- Directory:
/Users/cniackz/operator/cmd/operator
- Output directory:
/Users/cniackz/operator
- Working directory:
/Users/cniackz/operator
- Environment:
CGO_ENABLED=0;GOOS=darwin;GOARCH=arm64
- Go tool arguments:
-trimpath
If you use
--trimpath
breakpoints will not work!!!
- Program arguments:
controller is for backend code of operator
controller --kubeconfig=/Users/cniackz/.kube/config
OR
ui is for front end code of operator, here resides the code for idp in go
ui --kubeconfig=/Users/cniackz/.kube/config
- Intro: We compiled in IntelliJ and used breakpoints, it worked but we had to change the code a bit since
--kubeconfig=/Users/cniackz/.kube/config
was not working as before, plusDirectory
was changed as explained by Pedro where the entry point changed as well, so here the details:
-
on a terminal,
kubectl proxy
-
on file
pkg/controller/controller.go
line: 82 replacecfg, err := rest.InClusterConfig()
for:
var err error
cfg := &rest.Config{
Host: "http://localhost:8001/",
TLSClientConfig: rest.TLSClientConfig{Insecure: true},
APIPath: "/",
BearerToken: "eyJhbGciOiJSUzI1NiIsImtpZCI6InFETTJ6R21jMS1NRVpTOER0SnUwdVg1Q05XeDZLV2NKVTdMUnlsZWtUa28ifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRldi1zYS10b2tlbi14eGxuaiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJkZXYtc2EiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJmZDVhMzRjNy0wZTkwLTQxNTctYmY0Zi02Yjg4MzIwYWIzMDgiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDpkZXYtc2EifQ.woZ6Bmkkw-BMV-_UX0Y-S_Lkb6H9zqKZX2aNhyy7valbYIZfIzrDqJYWV9q2SwCP20jBfdsDS40nDcMnHJPE5jZHkTajAV6eAnoq4EspRqORtLGFnVV-JR-okxtvhhQpsw5MdZacJk36ED6Hg8If5uTOF7VF5r70dP7WYBMFiZ3HSlJBnbu7QoTKFmbJ1MafsTQ2RBA37IJPkqi3OHvPadTux6UdMI8LlY7bLkZkaryYR36kwIzSqsYgsnefmm4eZkZzpCeyS9scm9lPjeyQTyCAhftlxfw8m_fsV0EDhmybZCjgJi4R49leJYkHdpnCSkubj87kJAbGMwvLhMhFFQ",
}
-
worth mention, before the app entrypoint was
main.go
, now iscmd/operator/main.go
this is why Directory is now:/Users/cniackz/operator/cmd/operator
-
--kubeconfig=/Users/cniackz/.kube/config
still there, just in a different place, haven't tried yet, might still work: https://github.com/minio/operator/blob/4fef8d844843dd29d7409673c74da26803cf4b0c/pkg/controller/controller.go#L62
flag.StringVar(&kubeconfig, "kubeconfig", "", "path to a kubeconfig. Only required if out-of-cluster")
Note:
Still you can compile, push the container to the registry and test directly over a cluster for final testing.
After your fix, you can pass the flag:
Testing final solution in the cluster by building:
make build
Get the container name
=> => naming to docker.io/minio/operator:v5.0.5-5-g4eb4d3c4
createcluster
installoperator
kind load docker-image docker.io/minio/operator:v5.0.5-5-g4eb4d3c4
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: minio-operator
image: docker.io/minio/operator:v5.0.5-5-g4eb4d3c4
How to connect local Operator with Tenant pods
-
create cluster with nginx as in https://github.com/cniackz/public/wiki/MinIO-Ingress-on-Kind-for-testing-and-learning or in https://github.com/minio/wiki/wiki/MinIO-Ingress-on-Kind-for-testing-and-learning
-
installoperator with nginx
-
have 0 replicas en minio operator deployment so you test your local code of operator
-
remember to
k proxy
to contact k8s api -
trus the certs by opening minio service in browser and export the cert then trus the cert in keychain on mac:
/etc/hosts
127.0.0.1 minio.tenant-lite.svc.cluster.local
To communicate with a pod from your local operator.
k port-forward myminio-pool-1-0 9000 -n tenant-lite <--------------------------- To communicate with a pod from your local operator.
EOS:
Go here: https://github.com/cniackz/minio/wiki/How-to-debug-eos-operator