Skip to content

Commit

Permalink
feature: precheck ns and api-resources in sync leaf
Browse files Browse the repository at this point in the history
Signed-off-by: renxiangyu <[email protected]>
  • Loading branch information
renxiangyu committed Mar 1, 2024
1 parent 6c4f417 commit 1f9d4e5
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 28 deletions.
18 changes: 6 additions & 12 deletions cmd/clustertree/cluster-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ func run(ctx context.Context, opts *options.Options) error {
return fmt.Errorf("error starting root pvc controller %v", err)
}

//promotePolicyController := controllers.PromotePolicyController{
// Client: mgr.GetClient(),
//}
//if err := promotePolicyController.SetupWithManager(mgr); err != nil {
// return fmt.Errorf("error starting promotePolicyController %s: %v", controllers.PromotePolicyControllerName, err)
//}

rootPVController := pv.RootPVController{
RootClient: mgr.GetClient(),
GlobalLeafManager: globalleafManager,
Expand Down Expand Up @@ -277,11 +270,12 @@ func run(ctx context.Context, opts *options.Options) error {
}

//promotePolicyController := promote.PromotePolicyController{
// RootClient: mgr.GetClient(),
// RootClientSet: rootClient,
// RootDynamicClient: dynamicClient,
// RootDiscoveryClient: discoveryClient,
// GlobalLeafManager: globalleafManager,
// RootClient: mgr.GetClient(),
// RootClientSet: rootClient,
// RootDynamicClient: dynamicClient,
// RootDiscoveryClient: discoveryClient,
// GlobalLeafManager: globalleafManager,
// PromotePolicyOptions: opts.PromotePolicyOptions,
//}
//if err = promotePolicyController.SetupWithManager(mgr); err != nil {
// return fmt.Errorf("error starting %s: %v", promote.PromotePolicyControllerName, err)
Expand Down
8 changes: 8 additions & 0 deletions cmd/clustertree/cluster-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type Options struct {
BackoffOpts flags.BackoffOptions

SyncPeriod time.Duration

PromotePolicyOptions PromotePolicyOptions
}

type KubernetesOptions struct {
Expand All @@ -59,6 +61,11 @@ type KubernetesOptions struct {
Burst int `json:"burst,omitempty" yaml:"burst,omitempty"`
}

type PromotePolicyOptions struct {
// ExcludeNamespaces are the ns name excluded by default when you need to sync leaf cluster resources
ForbidNamespaces []string
}

func NewOptions() (*Options, error) {
var leaderElection componentbaseconfigv1alpha1.LeaderElectionConfiguration
componentbaseconfigv1alpha1.RecommendedDefaultLeaderElectionConfiguration(&leaderElection)
Expand Down Expand Up @@ -93,6 +100,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.StringSliceVar(&o.AutoCreateMCSPrefix, "auto-mcs-prefix", []string{}, "The prefix of namespace for service to auto create mcs resources")
flags.StringSliceVar(&o.ReservedNamespaces, "reserved-namespaces", []string{"kube-system"}, "The namespaces protected by Kosmos that the controller-manager will skip.")
flags.DurationVar(&o.SyncPeriod, "sync-period", 0, "the sync period for informer to resync.")
flags.StringSliceVar(&o.PromotePolicyOptions.ForbidNamespaces, "forbid-promote-namespace", []string{}, "This is forbidden to promote namespace")
o.RateLimiterOpts.AddFlags(flags)
o.BackoffOpts.AddFlags(flags)
options.BindLeaderElectionFlags(&o.LeaderElection, flags)
Expand Down
17 changes: 10 additions & 7 deletions examples/promote_policy_demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ metadata:
name: promote-pilicy-sample
spec:
includedNamespaces:
- namespace1
- namespace2
- test
- kube-system
excludedNamespaces:
- namespace3
- kube-system
includedNamespaceScopedResources:
- deployment
- service
- pods
- daemonsets.apps
# - serviceexports.multicluster.x-k8s.io
- nodeconfigs.kosmos.io
excludedNamespaceScopedResources:
- pod
# - pods
# - nodeconfigs.kosmos.io
clusterName:
cluster
cluster7

Loading

0 comments on commit 1f9d4e5

Please sign in to comment.