Skip to content

Commit

Permalink
UPSTREAM: <carry>: kube-controller-manager: allow running bare kube-c…
Browse files Browse the repository at this point in the history
…ontroller-manager
  • Loading branch information
soltysh committed Sep 8, 2021
1 parent 413f193 commit 4398d3c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 140 deletions.
5 changes: 0 additions & 5 deletions cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ controller, and serviceaccounts controller.`,
Run: func(cmd *cobra.Command, args []string) {
verflag.PrintAndExitIfRequested()

if err := ShimFlagsForOpenShift(s, cmd); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}

c, err := s.Config(KnownControllers(), ControllersDisabledByDefault.List())
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
48 changes: 31 additions & 17 deletions cmd/kube-controller-manager/app/patch.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package app

import (
"io/ioutil"
"path"

"github.com/spf13/cobra"

"k8s.io/apimachinery/pkg/util/json"
kyaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/informers"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"
"k8s.io/kubernetes/cmd/kube-controller-manager/app/config"
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
)
Expand Down Expand Up @@ -36,6 +35,10 @@ func ShimForOpenShift(controllerManagerOptions *options.KubeControllerManagerOpt
return err
}

if err := applyOpenShiftConfigDefaultProjectSelector(controllerManagerOptions, openshiftConfig); err != nil {
return err
}

// Overwrite the informers, because we have our custom generic informers for quota.
// TODO update quota to create its own informer like garbage collection
if informers, err := newInformerFactory(controllerManager.Kubeconfig); err != nil {
Expand All @@ -47,24 +50,35 @@ func ShimForOpenShift(controllerManagerOptions *options.KubeControllerManagerOpt
return nil
}

func ShimFlagsForOpenShift(controllerManagerOptions *options.KubeControllerManagerOptions, cmd *cobra.Command) error {
if len(controllerManagerOptions.OpenShiftContext.OpenShiftConfig) == 0 {
return nil
func getOpenShiftConfig(configFile string) (map[string]interface{}, error) {
configBytes, err := ioutil.ReadFile(configFile)
if err != nil {
return nil, err
}

// TODO this gets removed when no longer take flags and no longer build a recycler template
openshiftConfig, err := getOpenShiftConfig(controllerManagerOptions.OpenShiftContext.OpenShiftConfig)
jsonBytes, err := kyaml.ToJSON(configBytes)
if err != nil {
return err
return nil, err
}
// apply the config based controller manager flags. They will override.
// TODO this should be replaced by the installer setting up the flags for us
if err := applyOpenShiftConfigFlags(controllerManagerOptions, openshiftConfig, cmd); err != nil {
return err
config := map[string]interface{}{}
if err := json.Unmarshal(jsonBytes, &config); err != nil {
return nil, err
}

return config, nil
}

func applyOpenShiftConfigDefaultProjectSelector(controllerManagerOptions *options.KubeControllerManagerOptions, openshiftConfig map[string]interface{}) error {
projectConfig, ok := openshiftConfig["projectConfig"]
if !ok {
return nil
}

klog.V(1).Infof("Flags after OpenShift shims:")
cliflag.PrintFlags(cmd.Flags())
castProjectConfig := projectConfig.(map[string]interface{})
defaultNodeSelector, ok := castProjectConfig["defaultNodeSelector"]
if !ok {
return nil
}
controllerManagerOptions.OpenShiftContext.OpenShiftDefaultProjectNodeSelector = defaultNodeSelector.(string)

return nil
}
118 changes: 0 additions & 118 deletions cmd/kube-controller-manager/app/patch_flags.go

This file was deleted.

0 comments on commit 4398d3c

Please sign in to comment.