@@ -20,13 +20,16 @@ package options
20
20
21
21
import (
22
22
"fmt"
23
+ "time"
23
24
24
25
"github.com/spf13/pflag"
25
26
"github.com/spf13/viper"
26
27
appconfig "tkestack.io/tke/pkg/application/config"
27
28
)
28
29
29
30
const (
31
+ flagConcurrentSyncs = "concurrent-app-syncs"
32
+ flagSyncAppPeriod = "sync-app-period"
30
33
flagRepoScheme = "features-repo-scheme"
31
34
flagRepoDomainSuffix = "features-repo-domain-suffix"
32
35
flagRepoCaFile = "features-repo-cafile"
@@ -35,11 +38,13 @@ const (
35
38
)
36
39
37
40
const (
38
- configRepoScheme = "features.repo.scheme"
39
- configRepoDomainSuffix = "features.repo.domain_suffix"
40
- configRepoCaFile = "features.repo.cafile"
41
- configRepoAdmin = "features.repo.admin"
42
- configRepoAdminPassword = "features.repo.admin_password"
41
+ configSyncAppPeriod = "controller.sync_app_period"
42
+ configConcurrentAppSyncs = "controller.concurrent_app_syncs"
43
+ configRepoScheme = "features.repo.scheme"
44
+ configRepoDomainSuffix = "features.repo.domain_suffix"
45
+ configRepoCaFile = "features.repo.cafile"
46
+ configRepoAdmin = "features.repo.admin"
47
+ configRepoAdminPassword = "features.repo.admin_password"
43
48
)
44
49
45
50
// RepoOptions contains configuration items related to application attributes.
@@ -51,14 +56,26 @@ type RepoOptions struct {
51
56
AdminPassword string
52
57
}
53
58
59
+ // ControllerOptions contains configuration items related to application attributes.
60
+ type AppControllerOptions struct {
61
+ SyncAppPeriod time.Duration
62
+ ConcurrentAppSyncs int
63
+ }
64
+
54
65
// FeatureOptions contains configuration items related to application attributes.
55
66
type FeatureOptions struct {
56
- Repo RepoOptions
67
+ Repo RepoOptions
68
+ AppController AppControllerOptions
57
69
}
58
70
59
71
// NewFeatureOptions creates a FeatureOptions object with default parameters.
60
72
func NewFeatureOptions () * FeatureOptions {
61
- return & FeatureOptions {}
73
+ return & FeatureOptions {
74
+ AppController : AppControllerOptions {
75
+ SyncAppPeriod : defaultSyncPeriod ,
76
+ ConcurrentAppSyncs : defaultconcurrentSyncs ,
77
+ },
78
+ }
62
79
}
63
80
64
81
// AddFlags adds flags for console to the specified FlagSet object.
@@ -82,6 +99,12 @@ func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
82
99
fs .String (flagRepoAdminPassword , o .Repo .AdminPassword ,
83
100
"Repo admin user password." )
84
101
_ = viper .BindPFlag (configRepoAdminPassword , fs .Lookup (flagRepoAdminPassword ))
102
+
103
+ fs .DurationVar (& o .AppController .SyncAppPeriod , flagSyncAppPeriod , o .AppController .SyncAppPeriod , "The period for app health checks" )
104
+ _ = viper .BindPFlag (configSyncAppPeriod , fs .Lookup (flagSyncAppPeriod ))
105
+
106
+ fs .IntVar (& o .AppController .ConcurrentAppSyncs , flagConcurrentSyncs , o .AppController .ConcurrentAppSyncs , "The number of app objects that are allowed to sync concurrently. Larger number = more responsive app termination, but more CPU (and network) load" )
107
+ _ = viper .BindPFlag (configConcurrentAppSyncs , fs .Lookup (flagConcurrentSyncs ))
85
108
}
86
109
87
110
// ApplyFlags parsing parameters from the command line or configuration file
@@ -103,6 +126,8 @@ func (o *FeatureOptions) ApplyFlags() []error {
103
126
o .Repo .Admin = viper .GetString (configRepoAdmin )
104
127
o .Repo .AdminPassword = viper .GetString (configRepoAdminPassword )
105
128
129
+ o .AppController .SyncAppPeriod = viper .GetDuration (configSyncAppPeriod )
130
+ o .AppController .ConcurrentAppSyncs = viper .GetInt (configConcurrentAppSyncs )
106
131
return errs
107
132
}
108
133
@@ -120,3 +145,15 @@ func (o *RepoOptions) ApplyTo(cfg *appconfig.RepoConfiguration) error {
120
145
121
146
return nil
122
147
}
148
+
149
+ // ApplyTo fills up Debugging config with options.
150
+ func (o * AppControllerOptions ) ApplyTo (cfg * appconfig.AppControllerConfiguration ) error {
151
+ if o == nil {
152
+ return nil
153
+ }
154
+
155
+ cfg .ConcurrentSyncs = o .ConcurrentAppSyncs
156
+ cfg .SyncPeriod = o .SyncAppPeriod
157
+
158
+ return nil
159
+ }
0 commit comments