Minimum Viable Product - MariaDB Kubernetes Operator for traditional replication (MDBF-299)

[MDBF-434] Learn Golang Created: 2022-06-14  Updated: 2023-11-20

Status: Open
Project: MariaDB Foundation Development
Component/s: Kubernetes
Affects Version/s: N/A
Fix Version/s: N/A

Type: Technical task Priority: Major
Reporter: Anel Husakovic Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In order to create the K8s operator one need the knowledge of Golang.
So l have to learn it, better.



 Comments   
Comment by Anel Husakovic [ 2022-06-17 ]

Testing the client .GET() method: https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/client/example_test.go in case where secret exists in a cluster

$ kubectl get secrets
NAME                    TYPE                                  DATA   AGE
default-token-hqpn5     kubernetes.io/service-account-token   3      14d
mariadb-sample-secret   Opaque                                1      40m

  • Testing returned error and the object

            root_secret := &corev1.Secret{}
    	err := r.Get(ctx,  req.Namespace, root_secret)
    	log.Info("Get()", "error: ", err, "root_secret", *root_secret)
     
    2022-06-17T01:59:20.696-0700    INFO    controllers.MariaDB1    Get()   {"MariaDB: ": "default/mariadb-sample", "error: ": "Secret \"mariadb-sample\" not found", "root_secret": {"metadata":{"creationTimestamp":null}}}
    

    We can see that the object is not nil and there is creationTime Null (what we can use to check), also err is not nil

  • Update the code with typed object (have to stop controller and run make run again to have visible changes)

    	err := r.Get(ctx, client.ObjectKey{
    		Namespace: req.Namespace,
    		Name:      req.Name + "-secret",
    	}, root_secret)
    	log.Info("Get()", "error: ", err, "root_secret", *root_secret)
     
    2022-06-17T01:59:56.279-0700    INFO    controllers.MariaDB1    Get()   {"MariaDB: ": "default/mariadb-sample", "error: ": null, "root_secret": {"kind":"Secret","apiVersion":"v1","metadata":{"name":"mariadb-sample-secret","namespace":"default","uid":"8fda9ce2-d7e2-425d-81e3-33e6a779175a","resourceVersion":"82748","creationTimestamp":"2022-06-17T08:25:44Z","managedFields":[{"manager":"main","operation":"Update","apiVersion":"v1","time":"2022-06-17T08:25:44Z","fieldsType":"FieldsV1","fieldsV1":{"f:data":{".":{},"f:mariadb-root-password":{}},"f:type":{}}}]},"data":{"mariadb-root-password":"bXlzZWNyZXQ="},"type":"Opaque"}}
    

    Note here that err is nil and we got the object

  • After making changes use make install build run
Generated at Thu Feb 08 03:37:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.