diff --git a/cmd/mysql-agent/app/mysql_agent.go b/cmd/mysql-agent/app/mysql_agent.go index d240a223b..cf0a791c4 100644 --- a/cmd/mysql-agent/app/mysql_agent.go +++ b/cmd/mysql-agent/app/mysql_agent.go @@ -32,7 +32,7 @@ import ( kubernetes "k8s.io/client-go/kubernetes" rest "k8s.io/client-go/rest" - options "github.com/oracle/mysql-operator/cmd/mysql-agent/app/options" + agentopts "github.com/oracle/mysql-operator/pkg/options/agent" cluster "github.com/oracle/mysql-operator/pkg/cluster" backupcontroller "github.com/oracle/mysql-operator/pkg/controllers/backup" clustermgr "github.com/oracle/mysql-operator/pkg/controllers/cluster/manager" @@ -49,7 +49,7 @@ const ( // resyncPeriod computes the time interval a shared informer waits before // resyncing with the api server. -func resyncPeriod(opts *options.MySQLAgentOpts) func() time.Duration { +func resyncPeriod(opts *agentopts.MySQLAgentOpts) func() time.Duration { return func() time.Duration { factor := rand.Float64() + 1 return time.Duration(float64(opts.MinResyncPeriod.Nanoseconds()) * factor) @@ -57,7 +57,7 @@ func resyncPeriod(opts *options.MySQLAgentOpts) func() time.Duration { } // Run runs the MySQL backup controller. It should never exit. -func Run(opts *options.MySQLAgentOpts) error { +func Run(opts *agentopts.MySQLAgentOpts) error { kubeconfig, err := rest.InClusterConfig() if err != nil { return err diff --git a/cmd/mysql-agent/main.go b/cmd/mysql-agent/main.go index 24700ff1f..d5bafbd45 100644 --- a/cmd/mysql-agent/main.go +++ b/cmd/mysql-agent/main.go @@ -26,14 +26,14 @@ import ( "github.com/spf13/pflag" "github.com/oracle/mysql-operator/cmd/mysql-agent/app" - "github.com/oracle/mysql-operator/cmd/mysql-agent/app/options" + agentopts "github.com/oracle/mysql-operator/pkg/options/agent" "github.com/oracle/mysql-operator/pkg/version" ) func main() { fmt.Fprintf(os.Stderr, "Starting mysql-agent version %s\n", version.GetBuildVersion()) - opts := options.NewMySQLAgentOpts() + opts := agentopts.NewMySQLAgentOpts() opts.AddFlags(pflag.CommandLine) pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc) diff --git a/cmd/mysql-operator/app/mysql_operator.go b/cmd/mysql-operator/app/mysql_operator.go index e53d0b1e0..6f09d330d 100644 --- a/cmd/mysql-operator/app/mysql_operator.go +++ b/cmd/mysql-operator/app/mysql_operator.go @@ -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" backupcontroller "github.com/oracle/mysql-operator/pkg/controllers/backup" backupschedule "github.com/oracle/mysql-operator/pkg/controllers/backup/schedule" cluster "github.com/oracle/mysql-operator/pkg/controllers/cluster" @@ -45,7 +45,7 @@ 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 { return func() time.Duration { factor := rand.Float64() + 1 return time.Duration(float64(s.MinResyncPeriod.Nanoseconds()) * factor) @@ -53,7 +53,7 @@ func resyncPeriod(s *options.MySQLOperatorServer) func() time.Duration { } // Run starts the mysql-operator controllers. This should never exit. -func Run(s *options.MySQLOperatorServer) error { +func Run(s *operatoropts.MySQLOperatorOpts) error { kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.KubeConfig) if err != nil { return err diff --git a/cmd/mysql-operator/main.go b/cmd/mysql-operator/main.go index 27418588c..e8f4ce7cd 100644 --- a/cmd/mysql-operator/main.go +++ b/cmd/mysql-operator/main.go @@ -26,7 +26,7 @@ import ( "k8s.io/apiserver/pkg/util/logs" "github.com/oracle/mysql-operator/cmd/mysql-operator/app" - "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options" + operatoropts "github.com/oracle/mysql-operator/pkg/options/operator" "github.com/oracle/mysql-operator/pkg/version" ) @@ -38,7 +38,7 @@ const ( func main() { fmt.Fprintf(os.Stderr, "Starting mysql-operator version '%s'\n", version.GetBuildVersion()) - opts, err := options.NewMySQLOperatorServer(configPath) + opts, err := operatoropts.NewMySQLOperatorOpts(configPath) if err != nil { fmt.Fprintf(os.Stderr, "error reading config: %v\n", err) os.Exit(1) diff --git a/pkg/controllers/cluster/controller.go b/pkg/controllers/cluster/controller.go index b770c6c32..17ca7265b 100644 --- a/pkg/controllers/cluster/controller.go +++ b/pkg/controllers/cluster/controller.go @@ -50,7 +50,7 @@ import ( informersv1alpha1 "github.com/oracle/mysql-operator/pkg/generated/informers/externalversions/mysql/v1alpha1" listersv1alpha1 "github.com/oracle/mysql-operator/pkg/generated/listers/mysql/v1alpha1" - options "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options" + operatoropts "github.com/oracle/mysql-operator/pkg/options/operator" secrets "github.com/oracle/mysql-operator/pkg/resources/secrets" services "github.com/oracle/mysql-operator/pkg/resources/services" statefulsets "github.com/oracle/mysql-operator/pkg/resources/statefulsets" @@ -80,7 +80,7 @@ const ( // The MySQLController watches the Kubernetes API for changes to MySQL resources type MySQLController struct { // Global MySQLOperator configuration options. - opConfig options.MySQLOperatorServer + opConfig operatoropts.MySQLOperatorOpts kubeClient kubernetes.Interface opClient clientset.Interface @@ -138,7 +138,7 @@ type MySQLController struct { // NewController creates a new MySQLController. func NewController( - opConfig options.MySQLOperatorServer, + opConfig operatoropts.MySQLOperatorOpts, opClient clientset.Interface, kubeClient kubernetes.Interface, clusterInformer informersv1alpha1.ClusterInformer, diff --git a/pkg/controllers/cluster/controller_test.go b/pkg/controllers/cluster/controller_test.go index a4f2b3985..637693d71 100644 --- a/pkg/controllers/cluster/controller_test.go +++ b/pkg/controllers/cluster/controller_test.go @@ -30,7 +30,7 @@ import ( "k8s.io/client-go/kubernetes/fake" cache "k8s.io/client-go/tools/cache" - options "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options" + operatoropts "github.com/oracle/mysql-operator/pkg/options/operator" "github.com/oracle/mysql-operator/pkg/apis/mysql/v1alpha1" "github.com/oracle/mysql-operator/pkg/constants" "github.com/oracle/mysql-operator/pkg/controllers/util" @@ -42,8 +42,8 @@ import ( buildversion "github.com/oracle/mysql-operator/pkg/version" ) -func mockOperatorConfig() options.MySQLOperatorServer { - opts := options.MySQLOperatorServer{} +func mockOperatorConfig() operatoropts.MySQLOperatorOpts { + opts := operatoropts.MySQLOperatorOpts{} opts.EnsureDefaults() return opts } diff --git a/cmd/mysql-agent/app/options/options.go b/pkg/options/agent/options.go similarity index 99% rename from cmd/mysql-agent/app/options/options.go rename to pkg/options/agent/options.go index f4c2341e1..77ccd7501 100644 --- a/cmd/mysql-agent/app/options/options.go +++ b/pkg/options/agent/options.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package options +package agent import ( "fmt" diff --git a/cmd/mysql-operator/app/options/options.go b/pkg/options/operator/options.go similarity index 90% rename from cmd/mysql-operator/app/options/options.go rename to pkg/options/operator/options.go index b8ab5a2aa..c337dfb8e 100644 --- a/cmd/mysql-operator/app/options/options.go +++ b/pkg/options/operator/options.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package options +package operator import ( "io/ioutil" @@ -40,8 +40,8 @@ type Images struct { MySQLAgentImage string `yaml:"mysqlAgent"` } -// MySQLOperatorServer holds the options for the MySQLOperator. -type MySQLOperatorServer struct { +// MySQLOperatorOpts holds the options for the MySQLOperator. +type MySQLOperatorOpts struct { // KubeConfig is the path to a kubeconfig file, specifying how to connect to // the API server. KubeConfig string `yaml:"kubeconfig"` @@ -65,14 +65,14 @@ type MySQLOperatorServer struct { MinResyncPeriod metav1.Duration `yaml:"minResyncPeriod"` } -// NewMySQLOperatorServer will create a new MySQLOperatorServer. If a valid +// MySQLOperatorOpts will create a new MySQLOperatorOpts. If a valid // config file is specified and exists, it will be used to initialise the // server. Otherwise, a default server will be created. // // The values specified by either default may later be customised and overidden // by user specified commandline parameters. -func NewMySQLOperatorServer(filePath string) (*MySQLOperatorServer, error) { - var config MySQLOperatorServer +func NewMySQLOperatorOpts(filePath string) (*MySQLOperatorOpts, error) { + var config MySQLOperatorOpts yamlPath, err := filepath.Abs(filePath) if err != nil { return nil, errors.Wrapf(err, "failed to determine MySQLOperator configuration absolute path: '%s'", filePath) @@ -87,7 +87,7 @@ func NewMySQLOperatorServer(filePath string) (*MySQLOperatorServer, error) { return nil, errors.Wrapf(err, "failed to parse MySQLOperator configuration: '%s'", filePath) } } else { - config = MySQLOperatorServer{} + config = MySQLOperatorOpts{} } config.EnsureDefaults() return &config, nil @@ -95,7 +95,7 @@ func NewMySQLOperatorServer(filePath string) (*MySQLOperatorServer, error) { // EnsureDefaults provides a default configuration when required values have // not been set. -func (s *MySQLOperatorServer) EnsureDefaults() { +func (s *MySQLOperatorOpts) EnsureDefaults() { if s.Hostname == "" { hostname, err := os.Hostname() if err != nil { @@ -118,7 +118,7 @@ func (s *MySQLOperatorServer) EnsureDefaults() { } // AddFlags adds the mysql-operator flags to a given FlagSet. -func (s *MySQLOperatorServer) AddFlags(fs *pflag.FlagSet) *pflag.FlagSet { +func (s *MySQLOperatorOpts) AddFlags(fs *pflag.FlagSet) *pflag.FlagSet { fs.StringVar(&s.KubeConfig, "kubeconfig", s.KubeConfig, "Path to Kubeconfig file with authorization and master location information.") fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).") fs.StringVar(&s.Namespace, "namespace", metav1.NamespaceAll, "The namespace for which the MySQL operator manages MySQL clusters. Defaults to all.") diff --git a/cmd/mysql-operator/app/options/options_test.go b/pkg/options/operator/options_test.go similarity index 85% rename from cmd/mysql-operator/app/options/options_test.go rename to pkg/options/operator/options_test.go index f4ebb091c..95a4b1132 100644 --- a/cmd/mysql-operator/app/options/options_test.go +++ b/pkg/options/operator/options_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package options +package operator import ( "testing" @@ -21,12 +21,12 @@ import ( ) func TestEnsureDefaults(t *testing.T) { - server := MySQLOperatorServer{} + server := MySQLOperatorOpts{} server.EnsureDefaults() assertRequiredDefaults(t, server) } -func assertRequiredDefaults(t *testing.T, s MySQLOperatorServer) { +func assertRequiredDefaults(t *testing.T, s MySQLOperatorOpts) { if &s == nil { t.Error("MySQLOperatorServer: was nil, expected a valid configuration.") } @@ -52,16 +52,16 @@ func assertRequiredDefaults(t *testing.T, s MySQLOperatorServer) { } func TestEnsureDefaultsOverrideSafety(t *testing.T) { - expected := mockMySQLOperatorServer() - ensured := mockMySQLOperatorServer() + expected := mockMySQLOperatorOpts() + ensured := mockMySQLOperatorOpts() ensured.EnsureDefaults() if expected != ensured { - t.Errorf("MySQLOperatorServer.EnsureDefaults() should not modify pre-configured values.") + t.Errorf("MySQLOperatorOpts.EnsureDefaults() should not modify pre-configured values.") } } -func mockMySQLOperatorServer() MySQLOperatorServer { - return MySQLOperatorServer{ +func mockMySQLOperatorOpts() MySQLOperatorOpts { + return MySQLOperatorOpts{ KubeConfig: "some-kube-config", Master: "some-master", Hostname: "some-hostname", diff --git a/pkg/resources/statefulsets/statefulset.go b/pkg/resources/statefulsets/statefulset.go index d4f24c767..a67f26806 100644 --- a/pkg/resources/statefulsets/statefulset.go +++ b/pkg/resources/statefulsets/statefulset.go @@ -26,8 +26,8 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/intstr" - agentopts "github.com/oracle/mysql-operator/cmd/mysql-agent/app/options" - operatoropts "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options" + agentopts "github.com/oracle/mysql-operator/pkg/options/agent" + operatoropts "github.com/oracle/mysql-operator/pkg/options/operator" "github.com/oracle/mysql-operator/pkg/apis/mysql/v1alpha1" "github.com/oracle/mysql-operator/pkg/constants" "github.com/oracle/mysql-operator/pkg/resources/secrets" diff --git a/pkg/resources/statefulsets/statefulset_test.go b/pkg/resources/statefulsets/statefulset_test.go index c16b46b58..4e23150eb 100644 --- a/pkg/resources/statefulsets/statefulset_test.go +++ b/pkg/resources/statefulsets/statefulset_test.go @@ -22,12 +22,12 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - options "github.com/oracle/mysql-operator/cmd/mysql-operator/app/options" + operatoropts "github.com/oracle/mysql-operator/pkg/options/operator" "github.com/oracle/mysql-operator/pkg/apis/mysql/v1alpha1" ) -func mockOperatorConfig() options.MySQLOperatorServer { - opts := options.MySQLOperatorServer{} +func mockOperatorConfig() operatoropts.MySQLOperatorOpts { + opts := operatoropts.MySQLOperatorOpts{} opts.EnsureDefaults() return opts }