mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
implement wildcard component.
This commit is contained in:
parent
c329202ee8
commit
bade96ed78
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package config
|
||||||
|
|
||||||
|
import internal "k8s.io/controller-manager/config"
|
||||||
|
|
||||||
|
// DefaultLeaderMigrationConfiguration returns the default LeaderMigrationConfiguration
|
||||||
|
// that is valid for this release of Kubernetes.
|
||||||
|
func DefaultLeaderMigrationConfiguration() *internal.LeaderMigrationConfiguration {
|
||||||
|
return &internal.LeaderMigrationConfiguration{
|
||||||
|
LeaderName: "cloud-provider-extraction-migration",
|
||||||
|
ResourceLock: ResourceLockLeases,
|
||||||
|
ControllerLeaders: []internal.ControllerLeaderConfiguration{
|
||||||
|
{
|
||||||
|
Name: "route",
|
||||||
|
Component: "*",
|
||||||
|
}, {
|
||||||
|
Name: "service",
|
||||||
|
Component: "*",
|
||||||
|
}, {
|
||||||
|
Name: "cloud-node-lifecycle",
|
||||||
|
Component: "*",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,7 @@ type LeaderMigrator struct {
|
|||||||
func NewLeaderMigrator(config *internal.LeaderMigrationConfiguration, component string) *LeaderMigrator {
|
func NewLeaderMigrator(config *internal.LeaderMigrationConfiguration, component string) *LeaderMigrator {
|
||||||
migratedControllers := make(map[string]bool)
|
migratedControllers := make(map[string]bool)
|
||||||
for _, leader := range config.ControllerLeaders {
|
for _, leader := range config.ControllerLeaders {
|
||||||
migratedControllers[leader.Name] = leader.Component == component
|
migratedControllers[leader.Name] = leader.Component == component || leader.Component == "*"
|
||||||
}
|
}
|
||||||
return &LeaderMigrator{
|
return &LeaderMigrator{
|
||||||
MigrationReady: make(chan struct{}),
|
MigrationReady: make(chan struct{}),
|
||||||
|
@ -55,6 +55,22 @@ func TestLeaderMigratorFilterFunc(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
wildcardConfig := &internal.LeaderMigrationConfiguration{
|
||||||
|
ResourceLock: "leases",
|
||||||
|
LeaderName: "cloud-provider-extraction-migration",
|
||||||
|
ControllerLeaders: []internal.ControllerLeaderConfiguration{
|
||||||
|
{
|
||||||
|
Name: "route",
|
||||||
|
Component: "*",
|
||||||
|
}, {
|
||||||
|
Name: "service",
|
||||||
|
Component: "*",
|
||||||
|
}, {
|
||||||
|
Name: "cloud-node-lifecycle",
|
||||||
|
Component: "*",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
config *internal.LeaderMigrationConfiguration
|
config *internal.LeaderMigrationConfiguration
|
||||||
@ -106,6 +122,28 @@ func TestLeaderMigratorFilterFunc(t *testing.T) {
|
|||||||
"cloud-node-lifecycle": ControllerMigrated,
|
"cloud-node-lifecycle": ControllerMigrated,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "wildcard config, kcm",
|
||||||
|
config: wildcardConfig,
|
||||||
|
component: "kube-controller-manager",
|
||||||
|
expectResult: map[string]FilterResult{
|
||||||
|
"deployment": ControllerNonMigrated, // KCM only
|
||||||
|
"route": ControllerMigrated,
|
||||||
|
"service": ControllerMigrated,
|
||||||
|
"cloud-node-lifecycle": ControllerMigrated,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "wildcard config, ccm",
|
||||||
|
config: wildcardConfig,
|
||||||
|
component: "cloud-controller-manager",
|
||||||
|
expectResult: map[string]FilterResult{
|
||||||
|
"cloud-node": ControllerNonMigrated, // CCM only
|
||||||
|
"route": ControllerMigrated,
|
||||||
|
"service": ControllerMigrated,
|
||||||
|
"cloud-node-lifecycle": ControllerMigrated,
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
migrator := NewLeaderMigrator(tc.config, tc.component)
|
migrator := NewLeaderMigrator(tc.config, tc.component)
|
||||||
|
Loading…
Reference in New Issue
Block a user