Skip to content

Commit

Permalink
optimize approver (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
rambohe-ch authored Apr 7, 2022
1 parent 5618159 commit d44b6da
Show file tree
Hide file tree
Showing 7 changed files with 904 additions and 238 deletions.
93 changes: 64 additions & 29 deletions cmd/yurthub/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,43 +119,18 @@ func Complete(options *options.YurtHubOptions) (*YurtHubConfiguration, error) {
proxyServerDummyAddr := net.JoinHostPort(options.HubAgentDummyIfIP, options.YurtHubProxyPort)
proxySecureServerDummyAddr := net.JoinHostPort(options.HubAgentDummyIfIP, options.YurtHubProxySecurePort)
workingMode := util.WorkingMode(options.WorkingMode)

var filterMapping map[string]filter.Runner
var filters *filter.Filters
var serviceTopologyFilterEnabled bool
var mutatedMasterServiceAddr string
var filterManager *filter.Manager
if options.EnableResourceFilter {
if options.WorkingMode == string(util.WorkingModeCloud) {
options.DisabledResourceFilters = append(options.DisabledResourceFilters, filter.DisabledInCloudMode...)
}
filters = filter.NewFilters(options.DisabledResourceFilters)
registerAllFilters(filters)
serviceTopologyFilterEnabled = filters.Enabled(filter.ServiceTopologyFilterName)
mutatedMasterServiceAddr = us[0].Host
if options.AccessServerThroughHub {
if options.EnableDummyIf {
mutatedMasterServiceAddr = proxySecureServerDummyAddr
} else {
mutatedMasterServiceAddr = proxySecureServerAddr
}
}
}

sharedFactory, yurtSharedFactory, err := createSharedInformers(fmt.Sprintf("http://%s", proxyServerAddr))
if err != nil {
return nil, err
}
registerInformers(sharedFactory, yurtSharedFactory, workingMode, serviceTopologyFilterEnabled, options.NodePoolName, options.NodeName)
filterMapping, err = generateNameToFilterMapping(filters, sharedFactory, yurtSharedFactory, serializerManager, storageWrapper, workingMode, options.NodeName, mutatedMasterServiceAddr)
registerInformers(sharedFactory, yurtSharedFactory, workingMode, serviceTopologyFilterEnabled(options), options.NodePoolName, options.NodeName)

filterManager, err := createFilterManager(options, sharedFactory, yurtSharedFactory, serializerManager, storageWrapper, us[0].Host, proxySecureServerDummyAddr, proxySecureServerAddr)
if err != nil {
klog.Errorf("could not create filter manager, %v", err)
return nil, err
}

if options.EnableResourceFilter {
filterManager = filter.NewFilterManager(sharedFactory, filterMapping)
}

cfg := &YurtHubConfiguration{
LBMode: options.LBMode,
RemoteServers: us,
Expand Down Expand Up @@ -311,3 +286,63 @@ func generateNameToFilterMapping(filters *filter.Filters,
initializerChain = append(initializerChain, genericInitializer)
return filters.NewFromFilters(initializerChain)
}

// createFilterManager will create a filter manager for data filtering framework.
func createFilterManager(options *options.YurtHubOptions,
sharedFactory informers.SharedInformerFactory,
yurtSharedFactory yurtinformers.SharedInformerFactory,
serializerManager *serializer.SerializerManager,
storageWrapper cachemanager.StorageWrapper,
apiserverAddr string,
proxySecureServerDummyAddr string,
proxySecureServerAddr string,
) (*filter.Manager, error) {
if !options.EnableResourceFilter {
return nil, nil
}

if options.WorkingMode == string(util.WorkingModeCloud) {
options.DisabledResourceFilters = append(options.DisabledResourceFilters, filter.DisabledInCloudMode...)
}
filters := filter.NewFilters(options.DisabledResourceFilters)
registerAllFilters(filters)

mutatedMasterServiceAddr := apiserverAddr
if options.AccessServerThroughHub {
if options.EnableDummyIf {
mutatedMasterServiceAddr = proxySecureServerDummyAddr
} else {
mutatedMasterServiceAddr = proxySecureServerAddr
}
}

filterMapping, err := generateNameToFilterMapping(filters, sharedFactory, yurtSharedFactory, serializerManager, storageWrapper, util.WorkingMode(options.WorkingMode), options.NodeName, mutatedMasterServiceAddr)
if err != nil {
return nil, err
}

return filter.NewFilterManager(sharedFactory, filterMapping), nil
}

// serviceTopologyFilterEnabled is used to verify the service topology filter should be enabled or not.
func serviceTopologyFilterEnabled(options *options.YurtHubOptions) bool {
if !options.EnableResourceFilter {
return false
}

for _, filterName := range options.DisabledResourceFilters {
if filterName == filter.ServiceTopologyFilterName {
return false
}
}

if options.WorkingMode == string(util.WorkingModeCloud) {
for i := range filter.DisabledInCloudMode {
if filter.DisabledInCloudMode[i] == filter.ServiceTopologyFilterName {
return false
}
}
}

return true
}
Loading

0 comments on commit d44b6da

Please sign in to comment.