Skip to content

Commit be8d413

Browse files
GaoXiaodongxdonggao
and
xdonggao
authored
feat(application): set syncPeriod and concurrentSyncs by config file (#1762)
Co-authored-by: xdonggao <[email protected]>
1 parent 61fef6a commit be8d413

File tree

6 files changed

+68
-15
lines changed

6 files changed

+68
-15
lines changed

Diff for: cmd/tke-application-controller/app/application.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ package app
2020

2121
import (
2222
"net/http"
23-
"time"
2423

2524
"k8s.io/apimachinery/pkg/runtime/schema"
2625
applicationv1 "tkestack.io/tke/api/application/v1"
2726
"tkestack.io/tke/pkg/application/controller/app"
2827
)
2928

30-
const (
31-
applicationSyncPeriod = 30 * time.Second
32-
concurrentApplicationSyncs = 10
33-
)
34-
3529
func startAppController(ctx ControllerContext) (http.Handler, bool, error) {
3630
if !ctx.AvailableResources[schema.GroupVersionResource{Group: applicationv1.GroupName, Version: "v1", Resource: "apps"}] {
3731
return nil, false, nil
@@ -42,11 +36,11 @@ func startAppController(ctx ControllerContext) (http.Handler, bool, error) {
4236
ctx.PlatformClient,
4337
ctx.Repo,
4438
ctx.InformerFactory.Application().V1().Apps(),
45-
applicationSyncPeriod,
39+
ctx.Config.AppControllerConfiguration.SyncPeriod,
4640
applicationv1.AppFinalize,
4741
)
4842

49-
go ctrl.Run(concurrentApplicationSyncs, ctx.Stop)
43+
go ctrl.Run(ctx.Config.AppControllerConfiguration.ConcurrentSyncs, ctx.Stop)
5044

5145
return nil, true, nil
5246
}

Diff for: cmd/tke-application-controller/app/config/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Config struct {
5050
// the rest config for the platform apiserver
5151
PlatformAPIServerClientConfig *restclient.Config
5252
RepoConfiguration appconfig.RepoConfiguration
53+
AppControllerConfiguration appconfig.AppControllerConfiguration
5354
}
5455

5556
// CreateConfigFromOptions creates a running configuration instance based
@@ -93,6 +94,9 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
9394
PlatformAPIServerClientConfig: platformAPIServerClientConfig,
9495
}
9596

97+
if err := (&opts.FeatureOptions.AppController).ApplyTo(&controllerManagerConfig.AppControllerConfiguration); err != nil {
98+
return nil, err
99+
}
96100
if err := (&opts.FeatureOptions.Repo).ApplyTo(&controllerManagerConfig.RepoConfiguration); err != nil {
97101
return nil, err
98102
}

Diff for: cmd/tke-application-controller/app/context.go

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type ControllerContext struct {
5050
// InformerFactory gives access to informers for the controller.
5151
InformerFactory versionedinformers.SharedInformerFactory
5252

53+
// Config provides access to init options for a given controller
54+
Config config.Config
55+
5356
// DeferredDiscoveryRESTMapper is a RESTMapper that will defer
5457
// initialization of the RESTMapper until the first mapping is
5558
// requested.
@@ -114,6 +117,7 @@ func CreateControllerContext(cfg *config.Config, rootClientBuilder controller.Cl
114117
ctx := ControllerContext{
115118
ClientBuilder: rootClientBuilder,
116119
InformerFactory: sharedInformers,
120+
Config: *cfg,
117121
RESTMapper: restMapper,
118122
AvailableResources: availableResources,
119123
Stop: stop,

Diff for: cmd/tke-application-controller/app/options/feature.go

+44-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ package options
2020

2121
import (
2222
"fmt"
23+
"time"
2324

2425
"github.com/spf13/pflag"
2526
"github.com/spf13/viper"
2627
appconfig "tkestack.io/tke/pkg/application/config"
2728
)
2829

2930
const (
31+
flagConcurrentSyncs = "concurrent-app-syncs"
32+
flagSyncAppPeriod = "sync-app-period"
3033
flagRepoScheme = "features-repo-scheme"
3134
flagRepoDomainSuffix = "features-repo-domain-suffix"
3235
flagRepoCaFile = "features-repo-cafile"
@@ -35,11 +38,13 @@ const (
3538
)
3639

3740
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"
4348
)
4449

4550
// RepoOptions contains configuration items related to application attributes.
@@ -51,14 +56,26 @@ type RepoOptions struct {
5156
AdminPassword string
5257
}
5358

59+
// ControllerOptions contains configuration items related to application attributes.
60+
type AppControllerOptions struct {
61+
SyncAppPeriod time.Duration
62+
ConcurrentAppSyncs int
63+
}
64+
5465
// FeatureOptions contains configuration items related to application attributes.
5566
type FeatureOptions struct {
56-
Repo RepoOptions
67+
Repo RepoOptions
68+
AppController AppControllerOptions
5769
}
5870

5971
// NewFeatureOptions creates a FeatureOptions object with default parameters.
6072
func NewFeatureOptions() *FeatureOptions {
61-
return &FeatureOptions{}
73+
return &FeatureOptions{
74+
AppController: AppControllerOptions{
75+
SyncAppPeriod: defaultSyncPeriod,
76+
ConcurrentAppSyncs: defaultconcurrentSyncs,
77+
},
78+
}
6279
}
6380

6481
// AddFlags adds flags for console to the specified FlagSet object.
@@ -82,6 +99,12 @@ func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
8299
fs.String(flagRepoAdminPassword, o.Repo.AdminPassword,
83100
"Repo admin user password.")
84101
_ = 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))
85108
}
86109

87110
// ApplyFlags parsing parameters from the command line or configuration file
@@ -103,6 +126,8 @@ func (o *FeatureOptions) ApplyFlags() []error {
103126
o.Repo.Admin = viper.GetString(configRepoAdmin)
104127
o.Repo.AdminPassword = viper.GetString(configRepoAdminPassword)
105128

129+
o.AppController.SyncAppPeriod = viper.GetDuration(configSyncAppPeriod)
130+
o.AppController.ConcurrentAppSyncs = viper.GetInt(configConcurrentAppSyncs)
106131
return errs
107132
}
108133

@@ -120,3 +145,15 @@ func (o *RepoOptions) ApplyTo(cfg *appconfig.RepoConfiguration) error {
120145

121146
return nil
122147
}
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+
}

Diff for: cmd/tke-application-controller/app/options/options.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
package options
2020

2121
import (
22+
"time"
23+
2224
"github.com/spf13/pflag"
2325
apiserveroptions "tkestack.io/tke/pkg/apiserver/options"
2426
controlleroptions "tkestack.io/tke/pkg/controller/options"
2527
"tkestack.io/tke/pkg/util/log"
2628
)
2729

30+
const (
31+
defaultSyncPeriod = 30 * time.Second
32+
defaultconcurrentSyncs = 10
33+
)
34+
2835
// Options is the main context object for the TKE controller manager.
2936
type Options struct {
3037
Log *log.Options

Diff for: pkg/application/config/types.go

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package config
2020

21+
import "time"
22+
2123
// RepoConfiguration contains options to connect to a chart repo.
2224
type RepoConfiguration struct {
2325
Scheme string
@@ -26,3 +28,8 @@ type RepoConfiguration struct {
2628
Admin string
2729
AdminPassword string
2830
}
31+
32+
type AppControllerConfiguration struct {
33+
SyncPeriod time.Duration
34+
ConcurrentSyncs int
35+
}

0 commit comments

Comments
 (0)