提交 51ca9ef7 编写于 作者: L liqingping

feat: rename options to createOptions

上级 366d7878
......@@ -31,21 +31,21 @@ import (
"opendilab.org/di-orchestrator/pkg/controllers"
)
type OperatorOptions struct {
type CreateOptions struct {
MetricAddress string
ProbeAddress string
EnableLeaderElection bool
}
func NewOperatorOptions() *OperatorOptions {
return &OperatorOptions{
func NewCreateOptions() *CreateOptions {
return &CreateOptions{
MetricAddress: ":8443",
ProbeAddress: ":8080",
EnableLeaderElection: false,
}
}
func (o *OperatorOptions) AddFlags(cmd *cobra.Command) {
func (o *CreateOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.MetricAddress, "metric-addr", o.MetricAddress, "The address the metric endpoint binds to.")
cmd.Flags().StringVar(&o.ProbeAddress, "probe-addr", o.ProbeAddress, "The address the probe endpoint binds to.")
cmd.Flags().BoolVar(&o.EnableLeaderElection, "leader-elect", o.EnableLeaderElection,
......@@ -54,7 +54,7 @@ func (o *OperatorOptions) AddFlags(cmd *cobra.Command) {
}
func NewCmdOperator() *cobra.Command {
o := NewOperatorOptions()
o := NewCreateOptions()
var operatorCmd = &cobra.Command{
Use: "operator",
Short: "Command to run di-operator ",
......@@ -85,7 +85,7 @@ func init() {
//+kubebuilder:scaffold:scheme
}
func runCommand(cmd *cobra.Command, options *OperatorOptions) error {
func runCommand(cmd *cobra.Command, options *CreateOptions) error {
ctrl.SetLogger(cmdcommon.Logger)
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
......
......@@ -36,7 +36,7 @@ var (
DefaultAGConfigName = "aggregator-config"
)
type ServerOptions struct {
type CreateOptions struct {
*cmdcommon.GenericFlags
ServerBindAddress string
......@@ -46,8 +46,8 @@ type ServerOptions struct {
AGCconfigName string
}
func NewServerOptions() *ServerOptions {
return &ServerOptions{
func NewCreateOptions() *CreateOptions {
return &CreateOptions{
GenericFlags: cmdcommon.NewGenericFlags(),
ServerBindAddress: ":8080",
GPUAllocPolicy: gpualloc.SimpleGPUAllocPolicy,
......@@ -56,7 +56,7 @@ func NewServerOptions() *ServerOptions {
}
}
func (o *ServerOptions) AddFlags(cmd *cobra.Command) {
func (o *CreateOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&o.ServerBindAddress, "server-bind-address", "b", o.ServerBindAddress,
"The address for server to bind to.")
cmd.Flags().StringVarP(&o.GPUAllocPolicy, "gpu-alloc-policy", "p", o.GPUAllocPolicy,
......@@ -70,7 +70,7 @@ func (o *ServerOptions) AddFlags(cmd *cobra.Command) {
// serverCmd represents the server command
func NewCmdServer() *cobra.Command {
o := NewServerOptions()
o := NewCreateOptions()
var serverCmd = &cobra.Command{
Use: "server",
Short: "Command to run di-server ",
......@@ -89,7 +89,7 @@ Examples:
return serverCmd
}
func runCommand(cmd *cobra.Command, options *ServerOptions) error {
func runCommand(cmd *cobra.Command, options *CreateOptions) error {
cfg, err := ctrl.GetConfig()
if err != nil {
return err
......
/*
Copyright 2021 The OpenDILab authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package webhook
// import (
// "flag"
// "os"
// // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// // to ensure that exec-entrypoint and run can make use of them.
// _ "k8s.io/client-go/plugin/pkg/client/auth"
// "k8s.io/apimachinery/pkg/runtime"
// utilruntime "k8s.io/apimachinery/pkg/util/runtime"
// clientgoscheme "k8s.io/client-go/kubernetes/scheme"
// ctrl "sigs.k8s.io/controller-runtime"
// "sigs.k8s.io/controller-runtime/pkg/healthz"
// "sigs.k8s.io/controller-runtime/pkg/log/zap"
// div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
// //+kubebuilder:scaffold:imports
// )
// var (
// scheme = runtime.NewScheme()
// setupLog = ctrl.Log.WithName("setup")
// )
// func init() {
// utilruntime.Must(clientgoscheme.AddToScheme(scheme))
// utilruntime.Must(div1alpha1.AddToScheme(scheme))
// //+kubebuilder:scaffold:scheme
// }
// func main() {
// var metricsAddr, probeAddr string
// var enableLeaderElection bool
// flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
// flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
// flag.BoolVar(&enableLeaderElection, "leader-elect", false,
// "Enable leader election for controller manager. "+
// "Enabling this will ensure there is only one active controller manager.")
// opts := zap.Options{
// Development: true,
// }
// opts.BindFlags(flag.CommandLine)
// flag.Parse()
// ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
// mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
// Scheme: scheme,
// MetricsBindAddress: metricsAddr,
// Port: 9443,
// HealthProbeBindAddress: probeAddr,
// LeaderElection: enableLeaderElection,
// LeaderElectionID: "67841a5d.opendilab.org",
// })
// if err != nil {
// setupLog.Error(err, "unable to start manager")
// os.Exit(1)
// }
// if err = (&div1alpha1.DIJob{}).SetupWebhookWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create webhook", "webhook", "DIJob")
// os.Exit(1)
// }
// //+kubebuilder:scaffold:builder
// if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
// setupLog.Error(err, "unable to set up health check")
// os.Exit(1)
// }
// if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
// setupLog.Error(err, "unable to set up ready check")
// os.Exit(1)
// }
// setupLog.Info("starting manager")
// if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
// setupLog.Error(err, "problem running manager")
// os.Exit(1)
// }
// }
......@@ -28,15 +28,15 @@ import (
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
)
type WebhookOptions struct {
type CreateOptions struct {
MetricAddress string
ProbeAddress string
EnableLeaderElection bool
Port int
}
func NewWebhookOptions() *WebhookOptions {
return &WebhookOptions{
func NewCreateOptions() *CreateOptions {
return &CreateOptions{
MetricAddress: ":8443",
ProbeAddress: ":8080",
EnableLeaderElection: false,
......@@ -44,7 +44,7 @@ func NewWebhookOptions() *WebhookOptions {
}
}
func (o *WebhookOptions) AddFlags(cmd *cobra.Command) {
func (o *CreateOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.MetricAddress, "metric-addr", o.MetricAddress, "The address the metric endpoint binds to.")
cmd.Flags().StringVar(&o.ProbeAddress, "probe-addr", o.ProbeAddress, "The address the probe endpoint binds to.")
cmd.Flags().BoolVar(&o.EnableLeaderElection, "leader-elect", o.EnableLeaderElection,
......@@ -54,7 +54,7 @@ func (o *WebhookOptions) AddFlags(cmd *cobra.Command) {
}
func NewCmdWebhook() *cobra.Command {
o := NewWebhookOptions()
o := NewCreateOptions()
var webhookCmd = &cobra.Command{
Use: "webhook",
Short: "Command to run di-webhook ",
......@@ -85,7 +85,7 @@ func init() {
//+kubebuilder:scaffold:scheme
}
func runCommand(cmd *cobra.Command, options *WebhookOptions) error {
func runCommand(cmd *cobra.Command, options *CreateOptions) error {
ctrl.SetLogger(cmdcommon.Logger)
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册