-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Normalize options & Add 'dense' options
1. Now, all options should be put in the configuration file 2. Dense means that during the reconcil process, the content of status for crd is more abundant.
- Loading branch information
Showing
9 changed files
with
163 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
metrics_addr: 127.0.0.1:8080 | ||
enable_leader_election: true | ||
sync_period: 15 | ||
|
||
admin_project: example | ||
auth_url: https://10.0.1.4:30000/v3 | ||
admin_username: goodone | ||
admin_password: cj5ezKSEbbZhYh7C | ||
|
||
ap_interval_waiting: 20 | ||
ap_dense: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package options | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"yunion.io/x/structarg" | ||
) | ||
|
||
type OperatroOptions struct { | ||
structarg.BaseOptions | ||
|
||
MetricsAddr string `help:"The address the metric endpoint binds to." default:":8080"` | ||
EnableLeaderElection bool `help:"Enable leader election for controller manager. Enable intensive information collection during the reconcile process." default:"false"` | ||
EnableWebhooks bool `help:"Enable webhooks for controller manager." default:"false"` | ||
SyncPeriod int `help:"The interval between two adjacent local cache refreshes. unit:m" default:"10"` | ||
|
||
AdminAuthConfig | ||
AnsiblePlaybookConfig | ||
VirtualMachineConfig | ||
} | ||
|
||
type AdminAuthConfig struct { | ||
Region string `help:"Region name or ID"` | ||
AuthURL string `help:"Keystone auth URL"` | ||
AdminUsername string `help:"Admin username"` | ||
AdminPassword string `help:"Admin password"` | ||
AdminDomain string `help:"Admin domain"` | ||
AdminProject string `help:"Admin project"` | ||
} | ||
|
||
type AnsiblePlaybookConfig struct { | ||
IntervalPending int `json:"ap_interval_pending" help:"Reconcile interval when the state of the ansibleplaybook is pending." default:"15"` | ||
IntervalWaiting int `json:"ap_interval_waiting" help:"Reconcile interval when the state of the ansibleplaybook is waiting." default:"15"` | ||
Dense bool `json:"ap_dense" help:"Enable intensive information collection during the reconcile process." default:"false"` | ||
} | ||
|
||
type VirtualMachineConfig struct { | ||
IntervalPending int `json:"vm_interval_pending" help:"Reconcile interval when the state of the virtualmachine is pending." default:"5"` | ||
} | ||
|
||
var Options OperatroOptions | ||
|
||
func ParseOptions(args ...string) { | ||
parser, err := structarg.NewArgumentParser(&Options, "", "", "") | ||
if err != nil { | ||
log.Fatalf("Unable to define argument parser: %s.", err.Error()) | ||
} | ||
|
||
if len(args) == 0 { | ||
args = os.Args[1:] | ||
} | ||
|
||
err = parser.ParseArgs2(args, false, false) | ||
if err != nil { | ||
log.Fatalf("Unable to parse args: %s.", err.Error()) | ||
} | ||
|
||
if Options.Help { | ||
fmt.Println(parser.HelpString()) | ||
os.Exit(0) | ||
} | ||
|
||
if len(Options.Config) == 0 { | ||
defaultConfig := "/etc/yunion/oso.conf" | ||
Options.Config = defaultConfig | ||
} | ||
|
||
log.Printf("Use configuration file '%s'.", Options.Config) | ||
|
||
err = parser.ParseFile(Options.Config) | ||
if err != nil { | ||
log.Fatalf("Unable to parse configuration file: %s.", err.Error()) | ||
} | ||
|
||
parser.SetDefault() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package options | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"yunion.io/x/structarg" | ||
) | ||
|
||
func TestParseOptions(t *testing.T) { | ||
want := OperatroOptions{ | ||
BaseOptions: structarg.BaseOptions{}, | ||
MetricsAddr: "127.0.0.1:8080", | ||
EnableLeaderElection: true, | ||
SyncPeriod: 15, | ||
AdminAuthConfig: AdminAuthConfig{ | ||
AdminProject: "example", | ||
AuthURL: "https://10.0.1.4:30000/v3", | ||
AdminUsername: "goodone", | ||
AdminPassword: "cj5ezKSEbbZhYh7C", | ||
}, | ||
AnsiblePlaybookConfig: AnsiblePlaybookConfig{ | ||
IntervalPending: 15, | ||
IntervalWaiting: 20, | ||
Dense: true, | ||
}, | ||
VirtualMachineConfig: VirtualMachineConfig{ | ||
IntervalPending: 5, | ||
}, | ||
} | ||
ParseOptions("--config", "./demo.conf") | ||
Options.BaseOptions = want.BaseOptions | ||
if !reflect.DeepEqual(want, Options) { | ||
t.Fatalf("want: %#v\n get: %#v", want, Options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters