Skip to content

Commit e9031b6

Browse files
deads2kbertinatto
authored andcommitted
UPSTREAM: <carry>: kube-controller-manager: allow running bare kube-controller-manager
UPSTREAM: <carry>: (squash) kube-controller-manager: allow running bare kube-controller-manager UPSTREAM: <carry>: kube-controller-manager: allow running bare kube-controller-manager UPSTREAM: <carry>: (squash) remove egressnetworkpolicies from gc ignored resources egressnetworkpolicies should not be in garbage collector ignored resources, so users can delete them using "--cascade=foreground" flag. Signed-off-by: Flavio Fernandes <[email protected]> OpenShift-Rebase-Source: 6c1dee4 UPSTREAM: <carry>: (squash) kube-controller-manager: allow running bare kube-controller-manager
1 parent 366b03e commit e9031b6

File tree

12 files changed

+845
-10
lines changed

12 files changed

+845
-10
lines changed

cmd/kube-controller-manager/app/apps.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ import (
3434
)
3535

3636
func startDaemonSetController(ctx context.Context, controllerContext ControllerContext) (controller.Interface, bool, error) {
37-
dsc, err := daemon.NewDaemonSetsController(
37+
dsc, err := daemon.NewNodeSelectorAwareDaemonSetsController(
3838
ctx,
39+
controllerContext.OpenShiftContext.OpenShiftDefaultProjectNodeSelector,
40+
controllerContext.OpenShiftContext.KubeDefaultProjectNodeSelector,
41+
controllerContext.InformerFactory.Core().V1().Namespaces(),
3942
controllerContext.InformerFactory.Apps().V1().DaemonSets(),
4043
controllerContext.InformerFactory.Apps().V1().ControllerRevisions(),
4144
controllerContext.InformerFactory.Core().V1().Pods(),

cmd/kube-controller-manager/app/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626

2727
// Config is the main context object for the controller manager.
2828
type Config struct {
29+
OpenShiftContext OpenShiftContext
30+
2931
ComponentConfig kubectrlmgrconfig.KubeControllerManagerConfiguration
3032

3133
SecureServing *apiserver.SecureServingInfo
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package config
2+
3+
// OpenShiftContext is additional context that we need to launch the kube-controller-manager for openshift.
4+
// Basically, this holds our additional config information.
5+
type OpenShiftContext struct {
6+
OpenShiftConfig string
7+
OpenShiftDefaultProjectNodeSelector string
8+
KubeDefaultProjectNodeSelector string
9+
}

cmd/kube-controller-manager/app/controllermanager.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ controller, and serviceaccounts controller.`,
141141
if err != nil {
142142
return err
143143
}
144+
145+
if err := ShimForOpenShift(s, c); err != nil {
146+
fmt.Fprintf(os.Stderr, "%v\n", err)
147+
return err
148+
}
149+
144150
// add feature enablement metrics
145151
utilfeature.DefaultMutableFeatureGate.AddMetrics()
146152
return Run(context.Background(), c.Complete())
@@ -335,6 +341,8 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
335341

336342
// ControllerContext defines the context object for controller
337343
type ControllerContext struct {
344+
OpenShiftContext config.OpenShiftContext
345+
338346
// ClientBuilder will provide a client for this controller to use
339347
ClientBuilder clientbuilder.ControllerClientBuilder
340348

@@ -525,7 +533,12 @@ func GetAvailableResources(clientBuilder clientbuilder.ControllerClientBuilder)
525533
// the shared-informers client and token controller.
526534
func CreateControllerContext(logger klog.Logger, s *config.CompletedConfig, rootClientBuilder, clientBuilder clientbuilder.ControllerClientBuilder, stop <-chan struct{}) (ControllerContext, error) {
527535
versionedClient := rootClientBuilder.ClientOrDie("shared-informers")
528-
sharedInformers := informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)())
536+
var sharedInformers informers.SharedInformerFactory
537+
if InformerFactoryOverride == nil {
538+
sharedInformers = informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)())
539+
} else {
540+
sharedInformers = InformerFactoryOverride
541+
}
529542

530543
metadataClient := metadata.NewForConfigOrDie(rootClientBuilder.ConfigOrDie("metadata-informers"))
531544
metadataInformers := metadatainformer.NewSharedInformerFactory(metadataClient, ResyncPeriod(s)())
@@ -556,6 +569,7 @@ func CreateControllerContext(logger klog.Logger, s *config.CompletedConfig, root
556569
}
557570

558571
ctx := ControllerContext{
572+
OpenShiftContext: s.OpenShiftContext,
559573
ClientBuilder: clientBuilder,
560574
InformerFactory: sharedInformers,
561575
ObjectOrMetadataInformerFactory: informerfactory.NewInformerFactory(sharedInformers, metadataInformers),
@@ -687,10 +701,10 @@ func (c serviceAccountTokenControllerStarter) startServiceAccountTokenController
687701
controllerContext.InformerFactory.Core().V1().ServiceAccounts(),
688702
controllerContext.InformerFactory.Core().V1().Secrets(),
689703
c.rootClientBuilder.ClientOrDie("tokens-controller"),
690-
serviceaccountcontroller.TokensControllerOptions{
704+
applyOpenShiftServiceServingCertCA(serviceaccountcontroller.TokensControllerOptions{
691705
TokenGenerator: tokenGenerator,
692706
RootCA: rootCA,
693-
},
707+
}),
694708
)
695709
if err != nil {
696710
return nil, true, fmt.Errorf("error creating Tokens controller: %v", err)

cmd/kube-controller-manager/app/options/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type KubeControllerManagerOptions struct {
9797

9898
Master string
9999
ShowHiddenMetricsForVersion string
100+
OpenShiftContext kubecontrollerconfig.OpenShiftContext
100101
}
101102

102103
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
@@ -273,6 +274,8 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
273274
fs := fss.FlagSet("misc")
274275
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).")
275276
fs.StringVar(&s.Generic.ClientConnection.Kubeconfig, "kubeconfig", s.Generic.ClientConnection.Kubeconfig, "Path to kubeconfig file with authorization and master location information (the master location can be overridden by the master flag).")
277+
fs.StringVar(&s.OpenShiftContext.OpenShiftConfig, "openshift-config", s.OpenShiftContext.OpenShiftConfig, "indicates that this process should be compatible with openshift start master")
278+
fs.MarkHidden("openshift-config")
276279
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
277280

278281
return fss
@@ -378,6 +381,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config, a
378381
return err
379382
}
380383
}
384+
385+
c.OpenShiftContext = s.OpenShiftContext
386+
381387
return nil
382388
}
383389

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package app
2+
3+
import (
4+
"io/ioutil"
5+
"path"
6+
7+
"k8s.io/apimachinery/pkg/util/json"
8+
kyaml "k8s.io/apimachinery/pkg/util/yaml"
9+
"k8s.io/client-go/informers"
10+
"k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
11+
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
12+
)
13+
14+
var InformerFactoryOverride informers.SharedInformerFactory
15+
16+
func ShimForOpenShift(controllerManagerOptions *options.KubeControllerManagerOptions, controllerManager *config.Config) error {
17+
if len(controllerManager.OpenShiftContext.OpenShiftConfig) == 0 {
18+
return nil
19+
}
20+
21+
// TODO this gets removed when no longer take flags and no longer build a recycler template
22+
openshiftConfig, err := getOpenShiftConfig(controllerManager.OpenShiftContext.OpenShiftConfig)
23+
if err != nil {
24+
return err
25+
}
26+
27+
// TODO this should be replaced by using a flex volume to inject service serving cert CAs into pods instead of adding it to the sa token
28+
if err := applyOpenShiftServiceServingCertCAFunc(path.Dir(controllerManager.OpenShiftContext.OpenShiftConfig), openshiftConfig); err != nil {
29+
return err
30+
}
31+
32+
// skip GC on some openshift resources
33+
// TODO this should be replaced by discovery information in some way
34+
if err := applyOpenShiftGCConfig(controllerManager); err != nil {
35+
return err
36+
}
37+
38+
if err := applyOpenShiftConfigDefaultProjectSelector(controllerManagerOptions, openshiftConfig); err != nil {
39+
return err
40+
}
41+
42+
// Overwrite the informers, because we have our custom generic informers for quota.
43+
// TODO update quota to create its own informer like garbage collection
44+
if informers, err := newInformerFactory(controllerManager.Kubeconfig); err != nil {
45+
return err
46+
} else {
47+
InformerFactoryOverride = informers
48+
}
49+
50+
return nil
51+
}
52+
53+
func getOpenShiftConfig(configFile string) (map[string]interface{}, error) {
54+
configBytes, err := ioutil.ReadFile(configFile)
55+
if err != nil {
56+
return nil, err
57+
}
58+
jsonBytes, err := kyaml.ToJSON(configBytes)
59+
if err != nil {
60+
return nil, err
61+
}
62+
config := map[string]interface{}{}
63+
if err := json.Unmarshal(jsonBytes, &config); err != nil {
64+
return nil, err
65+
}
66+
67+
return config, nil
68+
}
69+
70+
func applyOpenShiftConfigDefaultProjectSelector(controllerManagerOptions *options.KubeControllerManagerOptions, openshiftConfig map[string]interface{}) error {
71+
projectConfig, ok := openshiftConfig["projectConfig"]
72+
if !ok {
73+
return nil
74+
}
75+
76+
castProjectConfig := projectConfig.(map[string]interface{})
77+
defaultNodeSelector, ok := castProjectConfig["defaultNodeSelector"]
78+
if !ok {
79+
return nil
80+
}
81+
controllerManagerOptions.OpenShiftContext.OpenShiftDefaultProjectNodeSelector = defaultNodeSelector.(string)
82+
83+
return nil
84+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package app
2+
3+
import (
4+
gcconfig "k8s.io/kubernetes/pkg/controller/garbagecollector/config"
5+
6+
"k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
7+
)
8+
9+
func applyOpenShiftGCConfig(controllerManager *config.Config) error {
10+
// TODO make this configurable or discoverable. This is going to prevent us from running the stock GC controller
11+
// IF YOU ADD ANYTHING TO THIS LIST, MAKE SURE THAT YOU UPDATE THEIR STRATEGIES TO PREVENT GC FINALIZERS
12+
controllerManager.ComponentConfig.GarbageCollectorController.GCIgnoredResources = append(controllerManager.ComponentConfig.GarbageCollectorController.GCIgnoredResources,
13+
// explicitly disabled from GC for now - not enough value to track them
14+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "rolebindingrestrictions"},
15+
gcconfig.GroupResource{Group: "network.openshift.io", Resource: "clusternetworks"},
16+
gcconfig.GroupResource{Group: "network.openshift.io", Resource: "hostsubnets"},
17+
gcconfig.GroupResource{Group: "network.openshift.io", Resource: "netnamespaces"},
18+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthclientauthorizations"},
19+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthclients"},
20+
gcconfig.GroupResource{Group: "quota.openshift.io", Resource: "clusterresourcequotas"},
21+
gcconfig.GroupResource{Group: "user.openshift.io", Resource: "groups"},
22+
gcconfig.GroupResource{Group: "user.openshift.io", Resource: "identities"},
23+
gcconfig.GroupResource{Group: "user.openshift.io", Resource: "users"},
24+
gcconfig.GroupResource{Group: "image.openshift.io", Resource: "images"},
25+
26+
// virtual resource
27+
gcconfig.GroupResource{Group: "project.openshift.io", Resource: "projects"},
28+
// virtual and unwatchable resource, surfaced via rbac.authorization.k8s.io objects
29+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "clusterroles"},
30+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "clusterrolebindings"},
31+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "roles"},
32+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "rolebindings"},
33+
// these resources contain security information in their names, and we don't need to track them
34+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthaccesstokens"},
35+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthauthorizetokens"},
36+
)
37+
38+
return nil
39+
}

0 commit comments

Comments
 (0)