Skip to content

Commit 3e0f86e

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 UPSTREAM: <carry>: kube-controller-manager: allow running bare kube-controller-manager UPSTREAM: <carry>: kube-controller-manager: allow running bare kube-controller-manager Fix garbage-collection for CRDs. These types are backed by a CRD and not by openshift-apiserver anymore. DefaultGarbageCollectionPolicy (Unsupported) does not work with CRDs. The `foregroundDeletion` finalizer was set on these CRD objects which blocks deletion indifinetelly as GC will ignore these resources.
1 parent 3e965a4 commit 3e0f86e

File tree

12 files changed

+850
-11
lines changed

12 files changed

+850
-11
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ func newDaemonSetControllerDescriptor() *ControllerDescriptor {
4141
}
4242
}
4343
func startDaemonSetController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
44-
dsc, err := daemon.NewDaemonSetsController(
44+
dsc, err := daemon.NewNodeSelectorAwareDaemonSetsController(
4545
ctx,
46+
controllerContext.OpenShiftContext.OpenShiftDefaultProjectNodeSelector,
47+
controllerContext.OpenShiftContext.KubeDefaultProjectNodeSelector,
48+
controllerContext.InformerFactory.Core().V1().Namespaces(),
4649
controllerContext.InformerFactory.Apps().V1().DaemonSets(),
4750
controllerContext.InformerFactory.Apps().V1().ControllerRevisions(),
4851
controllerContext.InformerFactory.Core().V1().Pods(),

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

+2
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
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

+16-3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ controller, and serviceaccounts controller.`,
137137
return err
138138
}
139139

140+
if err := ShimForOpenShift(s, c); err != nil {
141+
fmt.Fprintf(os.Stderr, "%v\n", err)
142+
return err
143+
}
144+
140145
// add feature enablement metrics
141146
fg := s.ComponentGlobalsRegistry.FeatureGateFor(featuregate.DefaultKubeComponent)
142147
fg.(featuregate.MutableFeatureGate).AddMetrics()
@@ -364,6 +369,8 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
364369

365370
// ControllerContext defines the context object for controller
366371
type ControllerContext struct {
372+
OpenShiftContext config.OpenShiftContext
373+
367374
// ClientBuilder will provide a client for this controller to use
368375
ClientBuilder clientbuilder.ControllerClientBuilder
369376

@@ -607,7 +614,12 @@ func CreateControllerContext(ctx context.Context, s *config.CompletedConfig, roo
607614
}
608615

609616
versionedClient := rootClientBuilder.ClientOrDie("shared-informers")
610-
sharedInformers := informers.NewSharedInformerFactoryWithOptions(versionedClient, ResyncPeriod(s)(), informers.WithTransform(trim))
617+
var sharedInformers informers.SharedInformerFactory
618+
if InformerFactoryOverride == nil {
619+
sharedInformers = informers.NewSharedInformerFactoryWithOptions(versionedClient, ResyncPeriod(s)(), informers.WithTransform(trim))
620+
} else {
621+
sharedInformers = InformerFactoryOverride
622+
}
611623

612624
metadataClient := metadata.NewForConfigOrDie(rootClientBuilder.ConfigOrDie("metadata-informers"))
613625
metadataInformers := metadatainformer.NewSharedInformerFactoryWithOptions(metadataClient, ResyncPeriod(s)(), metadatainformer.WithTransform(trim))
@@ -627,6 +639,7 @@ func CreateControllerContext(ctx context.Context, s *config.CompletedConfig, roo
627639
}, 30*time.Second, ctx.Done())
628640

629641
controllerContext := ControllerContext{
642+
OpenShiftContext: s.OpenShiftContext,
630643
ClientBuilder: clientBuilder,
631644
InformerFactory: sharedInformers,
632645
ObjectOrMetadataInformerFactory: informerfactory.NewInformerFactory(sharedInformers, metadataInformers),
@@ -808,10 +821,10 @@ func startServiceAccountTokenController(ctx context.Context, controllerContext C
808821
controllerContext.InformerFactory.Core().V1().ServiceAccounts(),
809822
controllerContext.InformerFactory.Core().V1().Secrets(),
810823
rootClientBuilder.ClientOrDie("tokens-controller"),
811-
serviceaccountcontroller.TokensControllerOptions{
824+
applyOpenShiftServiceServingCertCA(serviceaccountcontroller.TokensControllerOptions{
812825
TokenGenerator: tokenGenerator,
813826
RootCA: rootCA,
814-
},
827+
}),
815828
)
816829
if err != nil {
817830
return nil, true, fmt.Errorf("error creating Tokens controller: %v", err)

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

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type KubeControllerManagerOptions struct {
107107

108108
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
109109
ComponentGlobalsRegistry featuregate.ComponentGlobalsRegistry
110+
OpenShiftContext kubecontrollerconfig.OpenShiftContext
110111
}
111112

112113
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
@@ -301,6 +302,8 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
301302
}
302303

303304
s.ComponentGlobalsRegistry.AddFlags(fss.FlagSet("generic"))
305+
fs.StringVar(&s.OpenShiftContext.OpenShiftConfig, "openshift-config", s.OpenShiftContext.OpenShiftConfig, "indicates that this process should be compatible with openshift start master")
306+
fs.MarkHidden("openshift-config")
304307

305308
return fss
306309
}
@@ -408,6 +411,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config, a
408411
return err
409412
}
410413
}
414+
415+
c.OpenShiftContext = s.OpenShiftContext
416+
411417
return nil
412418
}
413419

+84
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//
13+
// DO NOT PUT CRDs into the list. apiexstension-apiserver does not implement GarbageCollectionPolicy
14+
// so the deletion of these will be blocked because of foregroundDeletion finalizer when foreground deletion strategy is specified.
15+
controllerManager.ComponentConfig.GarbageCollectorController.GCIgnoredResources = append(controllerManager.ComponentConfig.GarbageCollectorController.GCIgnoredResources,
16+
// explicitly disabled from GC for now - not enough value to track them
17+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthclientauthorizations"},
18+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthclients"},
19+
gcconfig.GroupResource{Group: "user.openshift.io", Resource: "groups"},
20+
gcconfig.GroupResource{Group: "user.openshift.io", Resource: "identities"},
21+
gcconfig.GroupResource{Group: "user.openshift.io", Resource: "users"},
22+
gcconfig.GroupResource{Group: "image.openshift.io", Resource: "images"},
23+
24+
// virtual resource
25+
gcconfig.GroupResource{Group: "project.openshift.io", Resource: "projects"},
26+
// virtual and unwatchable resource, surfaced via rbac.authorization.k8s.io objects
27+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "clusterroles"},
28+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "clusterrolebindings"},
29+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "roles"},
30+
gcconfig.GroupResource{Group: "authorization.openshift.io", Resource: "rolebindings"},
31+
// these resources contain security information in their names, and we don't need to track them
32+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthaccesstokens"},
33+
gcconfig.GroupResource{Group: "oauth.openshift.io", Resource: "oauthauthorizetokens"},
34+
)
35+
36+
return nil
37+
}

0 commit comments

Comments
 (0)