Skip to content

Commit 6c1dee4

Browse files
deads2ksoltysh
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 openshift-rebase(v1.24):source=18bbb151dd9 openshift-rebase(v1.24):source=18bbb151dd9 openshift-rebase(v1.24):source=18bbb151dd9 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(v1.24):source=771b4b56597
1 parent 891b28f commit 6c1dee4

File tree

12 files changed

+843
-12
lines changed

12 files changed

+843
-12
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import (
3333
)
3434

3535
func startDaemonSetController(ctx context.Context, controllerContext ControllerContext) (controller.Interface, bool, error) {
36-
dsc, err := daemon.NewDaemonSetsController(
36+
dsc, err := daemon.NewNodeSelectorAwareDaemonSetsController(
37+
controllerContext.OpenShiftContext.OpenShiftDefaultProjectNodeSelector,
38+
controllerContext.OpenShiftContext.KubeDefaultProjectNodeSelector,
39+
controllerContext.InformerFactory.Core().V1().Namespaces(),
3740
controllerContext.InformerFactory.Apps().V1().DaemonSets(),
3841
controllerContext.InformerFactory.Apps().V1().ControllerRevisions(),
3942
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: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import (
6666
"k8s.io/controller-manager/pkg/informerfactory"
6767
"k8s.io/controller-manager/pkg/leadermigration"
6868
"k8s.io/klog/v2"
69-
kubefeatures "k8s.io/kubernetes/pkg/features"
7069

7170
"k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
7271
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
@@ -135,6 +134,10 @@ controller, and serviceaccounts controller.`,
135134
return err
136135
}
137136

137+
if err := ShimForOpenShift(s, c); err != nil {
138+
fmt.Fprintf(os.Stderr, "%v\n", err)
139+
return err
140+
}
138141
return Run(c.Complete(), wait.NeverStop)
139142
},
140143
Args: func(cmd *cobra.Command, args []string) error {
@@ -320,6 +323,8 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
320323

321324
// ControllerContext defines the context object for controller
322325
type ControllerContext struct {
326+
OpenShiftContext config.OpenShiftContext
327+
323328
// ClientBuilder will provide a client for this controller to use
324329
ClientBuilder clientbuilder.ControllerClientBuilder
325330

@@ -497,7 +502,12 @@ func GetAvailableResources(clientBuilder clientbuilder.ControllerClientBuilder)
497502
// the shared-informers client and token controller.
498503
func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clientBuilder clientbuilder.ControllerClientBuilder, stop <-chan struct{}) (ControllerContext, error) {
499504
versionedClient := rootClientBuilder.ClientOrDie("shared-informers")
500-
sharedInformers := informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)())
505+
var sharedInformers informers.SharedInformerFactory
506+
if InformerFactoryOverride == nil {
507+
sharedInformers = informers.NewSharedInformerFactory(versionedClient, ResyncPeriod(s)())
508+
} else {
509+
sharedInformers = InformerFactoryOverride
510+
}
501511

502512
metadataClient := metadata.NewForConfigOrDie(rootClientBuilder.ConfigOrDie("metadata-informers"))
503513
metadataInformers := metadatainformer.NewSharedInformerFactory(metadataClient, ResyncPeriod(s)())
@@ -528,6 +538,7 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
528538
}
529539

530540
ctx := ControllerContext{
541+
OpenShiftContext: s.OpenShiftContext,
531542
ClientBuilder: clientBuilder,
532543
InformerFactory: sharedInformers,
533544
ObjectOrMetadataInformerFactory: informerfactory.NewInformerFactory(sharedInformers, metadataInformers),
@@ -646,11 +657,10 @@ func (c serviceAccountTokenControllerStarter) startServiceAccountTokenController
646657
controllerContext.InformerFactory.Core().V1().ServiceAccounts(),
647658
controllerContext.InformerFactory.Core().V1().Secrets(),
648659
c.rootClientBuilder.ClientOrDie("tokens-controller"),
649-
serviceaccountcontroller.TokensControllerOptions{
660+
applyOpenShiftServiceServingCertCA(serviceaccountcontroller.TokensControllerOptions{
650661
TokenGenerator: tokenGenerator,
651662
RootCA: rootCA,
652-
AutoGenerate: !utilfeature.DefaultFeatureGate.Enabled(kubefeatures.LegacyServiceAccountTokenNoAutoGeneration),
653-
},
663+
}),
654664
)
655665
if err != nil {
656666
return nil, true, fmt.Errorf("error creating Tokens controller: %v", err)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type KubeControllerManagerOptions struct {
9494
Master string
9595
Kubeconfig string
9696
ShowHiddenMetricsForVersion string
97+
OpenShiftContext kubecontrollerconfig.OpenShiftContext
9798
}
9899

99100
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
@@ -261,6 +262,11 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
261262
fs := fss.FlagSet("misc")
262263
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).")
263264
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
265+
var dummy string
266+
fs.MarkDeprecated("insecure-experimental-approve-all-kubelet-csrs-for-group", "This flag does nothing.")
267+
fs.StringVar(&dummy, "insecure-experimental-approve-all-kubelet-csrs-for-group", "", "This flag does nothing.")
268+
fs.StringVar(&s.OpenShiftContext.OpenShiftConfig, "openshift-config", s.OpenShiftContext.OpenShiftConfig, "indicates that this process should be compatible with openshift start master")
269+
fs.MarkHidden("openshift-config")
264270
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
265271

266272
return fss
@@ -360,6 +366,9 @@ func (s *KubeControllerManagerOptions) ApplyTo(c *kubecontrollerconfig.Config) e
360366
return err
361367
}
362368
}
369+
370+
c.OpenShiftContext = s.OpenShiftContext
371+
363372
return nil
364373
}
365374

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)