Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Code refactor on options #189

Merged
merged 7 commits into from
Jul 25, 2018
Merged

Code refactor on options #189

merged 7 commits into from
Jul 25, 2018

Conversation

huanwei
Copy link

@huanwei huanwei commented Jul 21, 2018

1.Describe what this PR did

Refactor code structure on options.

2.Does this pull request fix one issue?

During the debug and review of the program, I found the following codes in mysql-operator/pkg used/called the struct type of MySQLOperator Options defined in mysql-operator/cmd, while the latter package should be recognized as the program’s entrypoint.

mysql-operator/pkg/controllers/cluster/controller.go 
mysql-operator/pkg/controllers/cluster/controller_test.go 
mysql-operator/pkg/resources/statefulsets/statefulset.go 
mysql-operator/pkg/resources/statefulsets/statefulset_test.go

It looked like the option packages in mysql-operator/cmd/mysql-operator/app/options and mysql-operator/cmd/mysql-agent/app/options here were not in a good place, so I would like to to tiny refactor the code structure.

3.Describe how you did it

I did the following changes:

Move `mysql-operator/cmd/mysql-operator/app/options` to `mysql-operator/pkg/options/operator`
Move `mysql-operator/cmd/mysql-agent/app/options` to `mysql-operator/pkg/options/agent`
Rename struct  type `MySQLOperatorServer` to `MySQLOperatorOpts`, with respect to the struct type of `MysqlAgentOpts`
Adjust the usage of struct type MySQLOperatorOpts passed to the codes in `mysql-operator/pkg` and `mysql-operator/cmd`.

4.Describe how to verify it

Compile the code, build the docker images, and verify the operator, agent and cluster on Kubernetes.

[root@k8s-master ~]# kubectl get pods -n mysql-operator
NAME                              READY     STATUS    RESTARTS   AGE
mysql-cluster-with-3-replicas-0   2/2       Running   0          7d
mysql-cluster-with-3-replicas-1   2/2       Running   0          7d
mysql-cluster-with-3-replicas-2   2/2       Running   0          7d
mysql-operator-78b7d9bfcf-nfcp8   1/1       Running   0          16d

huanwei added 3 commits July 21, 2018 08:29
Signed-off-by: huanwei <huan@harmonycloud.cn>
Signed-off-by: huanwei <huan@harmonycloud.cn>
Signed-off-by: huanwei <huan@harmonycloud.cn>
@huanwei huanwei closed this Jul 21, 2018
@huanwei huanwei reopened this Jul 21, 2018
@huanwei
Copy link
Author

huanwei commented Jul 23, 2018

@owainlewis
I have submitted the OCA this morning. Pls kindly check it. Thank you.

@delabassee
Copy link
Member

delabassee commented Jul 23, 2018

@owainlewis FYI, @huanwei 's OCA has been reviewed and approved

Signed-off-by: huanwei <huan@harmonycloud.cn>
@owainlewis owainlewis added the oracle-cla: yes Contributor has signed the Oracle Contributor Licence Agreement label Jul 23, 2018
@@ -28,7 +28,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

options "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options"
opratoropts "github.com/oracle/mysql-operator/pkg/options/operator"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo here (opratoropts => operatoropts)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

@@ -45,15 +45,15 @@ const (

// resyncPeriod computes the time interval a shared informer waits before
// resyncing with the api server.
func resyncPeriod(s *options.MySQLOperatorServer) func() time.Duration {
func resyncPeriod(s *opratoropts.MySQLOperatorOpts) func() time.Duration {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo here (opratoropts => operatoropts)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

return func() time.Duration {
factor := rand.Float64() + 1
return time.Duration(float64(s.MinResyncPeriod.Nanoseconds()) * factor)
}
}

// Run starts the mysql-operator controllers. This should never exit.
func Run(s *options.MySQLOperatorServer) error {
func Run(s *opratoropts.MySQLOperatorOpts) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo here (opratoropts => operatoropts)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

@owainlewis owainlewis requested a review from prydie July 24, 2018 14:15
@owainlewis
Copy link
Member

owainlewis commented Jul 24, 2018

Thanks for this contribution @huanwei the changes seem reasonable to me in terms of code organisation. If you're happy to fix those typos then we'll get this merged. 👍

@owainlewis owainlewis removed the request for review from prydie July 24, 2018 14:21
Copy link
Member

@owainlewis owainlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Just a few minor typos and then we can merge.

huanwei added 3 commits July 25, 2018 01:01
Signed-off-by: huanwei <huan@harmonycloud.cn>
Use --decode for cross OS compatibility (oracle#187)
Signed-off-by: huanwei <huan@harmonycloud.cn>
Copy link
Author

@huanwei huanwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owainlewis I have fixed the typos. Pls Kindly review. Thanks.

@@ -28,7 +28,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

options "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options"
opratoropts "github.com/oracle/mysql-operator/pkg/options/operator"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

return func() time.Duration {
factor := rand.Float64() + 1
return time.Duration(float64(s.MinResyncPeriod.Nanoseconds()) * factor)
}
}

// Run starts the mysql-operator controllers. This should never exit.
func Run(s *options.MySQLOperatorServer) error {
func Run(s *opratoropts.MySQLOperatorOpts) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

@@ -45,15 +45,15 @@ const (

// resyncPeriod computes the time interval a shared informer waits before
// resyncing with the api server.
func resyncPeriod(s *options.MySQLOperatorServer) func() time.Duration {
func resyncPeriod(s *opratoropts.MySQLOperatorOpts) func() time.Duration {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

Copy link
Author

@huanwei huanwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owainlewis I have fixed the typos. Pls review the changes. Thanks.

@@ -28,7 +28,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

options "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options"
operatoropts "github.com/oracle/mysql-operator/pkg/options/operator"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owainlewis Pls review the change. Thanks.

@@ -45,15 +45,15 @@ const (

// resyncPeriod computes the time interval a shared informer waits before
// resyncing with the api server.
func resyncPeriod(s *options.MySQLOperatorServer) func() time.Duration {
func resyncPeriod(s *operatoropts.MySQLOperatorOpts) func() time.Duration {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owainlewis Pls review the change. Thanks.

return func() time.Duration {
factor := rand.Float64() + 1
return time.Duration(float64(s.MinResyncPeriod.Nanoseconds()) * factor)
}
}

// Run starts the mysql-operator controllers. This should never exit.
func Run(s *options.MySQLOperatorServer) error {
func Run(s *operatoropts.MySQLOperatorOpts) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owainlewis Pls review the change. Thanks.

@prydie prydie merged commit 23c5eb3 into oracle:master Jul 25, 2018
huanwei added a commit to huanwei/mysql-operator that referenced this pull request Jul 25, 2018
@huanwei huanwei deleted the code-refactor branch July 25, 2018 16:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
oracle-cla: yes Contributor has signed the Oracle Contributor Licence Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants