Skip to content

Commit

Permalink
*: undo the change to controller_context
Browse files Browse the repository at this point in the history
EtcdInformer is only used by the MCO pod to reconcile image names.
This pulls out the logic of creating etcd informer from the generic
controller context to MCO pod start method.
  • Loading branch information
alaypatel07 committed Jan 19, 2020
1 parent 91ab6c5 commit c29ebe9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
28 changes: 27 additions & 1 deletion cmd/machine-config-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"flag"

"github.com/golang/glog"
operatorclientset "github.com/openshift/client-go/operator/clientset/versioned"
operatorinformers "github.com/openshift/client-go/operator/informers/externalversions"
operatorv1 "github.com/openshift/client-go/operator/informers/externalversions/operator/v1"
"github.com/openshift/machine-config-operator/cmd/common"
"github.com/openshift/machine-config-operator/internal/clients"
controllercommon "github.com/openshift/machine-config-operator/pkg/controller/common"
Expand Down Expand Up @@ -51,6 +54,14 @@ func runStartCmd(cmd *cobra.Command, args []string) {
}
run := func(ctx context.Context) {
ctrlctx := controllercommon.CreateControllerContext(cb, ctx.Done(), componentNamespace)
operatorClient := cb.OperatorClientOrDie("operator-shared-informer")

etcdInformer, err := getEtcdInformer(operatorClient, ctrlctx.OperatorInformerFactory)
if err != nil {
// MCO pod needs to restart for transient apiserver errors
glog.Errorf("unable to query discovery API %#v", err)
controllercommon.WriteTerminationError(err)
}

controller := operator.New(
componentNamespace, componentName,
Expand All @@ -74,7 +85,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
ctrlctx.ClientBuilder.APIExtClientOrDie(componentName),
ctrlctx.ClientBuilder.ConfigClientOrDie(componentName),
ctrlctx.OpenShiftKubeAPIServerKubeNamespacedInformerFactory.Core().V1().ConfigMaps(),
ctrlctx.EtcdInformer,
etcdInformer,
)

ctrlctx.NamespacedInformerFactory.Start(ctrlctx.Stop)
Expand Down Expand Up @@ -105,3 +116,18 @@ func runStartCmd(cmd *cobra.Command, args []string) {
})
panic("unreachable")
}

func getEtcdInformer(operatorClient operatorclientset.Interface, operatorSharedInformer operatorinformers.SharedInformerFactory) (operatorv1.EtcdInformer, error) {
operatorGroups, err := operatorClient.Discovery().ServerResourcesForGroupVersion("operator.openshift.io/v1")
if err != nil {
glog.Errorf("unable to get operatorGroups: %#v", err)
return nil, err
}

for _, o := range operatorGroups.APIResources {
if o.Kind == "Etcd" {
return operatorSharedInformer.Operator().V1().Etcds(), nil
}
}
return nil, nil
}
26 changes: 0 additions & 26 deletions pkg/controller/common/controller_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (

"github.com/golang/glog"
configinformers "github.com/openshift/client-go/config/informers/externalversions"
operatorclientset "github.com/openshift/client-go/operator/clientset/versioned"
operatorinformers "github.com/openshift/client-go/operator/informers/externalversions"
operatorv1 "github.com/openshift/client-go/operator/informers/externalversions/operator/v1"
"github.com/openshift/machine-config-operator/internal/clients"
daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
mcfginformers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
Expand Down Expand Up @@ -44,7 +42,6 @@ type ControllerContext struct {
APIExtInformerFactory apiextinformers.SharedInformerFactory
ConfigInformerFactory configinformers.SharedInformerFactory
OperatorInformerFactory operatorinformers.SharedInformerFactory
EtcdInformer operatorv1.EtcdInformer

AvailableResources map[schema.GroupVersionResource]bool

Expand Down Expand Up @@ -89,13 +86,6 @@ func CreateControllerContext(cb *clients.Builder, stop <-chan struct{}, targetNa
configSharedInformer := configinformers.NewSharedInformerFactory(configClient, resyncPeriod()())
operatorSharedInformer := operatorinformers.NewSharedInformerFactory(operatorClient, resyncPeriod()())

etcdInformer, err := getEtcdInformer(operatorClient, operatorSharedInformer)
if err != nil {
// MCO pod needs to restart for transient apiserver errors
glog.Errorf("unable to query discovery API %#v", err)
WriteTerminationError(err)
}

return &ControllerContext{
ClientBuilder: cb,
NamespacedInformerFactory: sharedNamespacedInformers,
Expand All @@ -107,24 +97,8 @@ func CreateControllerContext(cb *clients.Builder, stop <-chan struct{}, targetNa
APIExtInformerFactory: apiExtSharedInformer,
ConfigInformerFactory: configSharedInformer,
OperatorInformerFactory: operatorSharedInformer,
EtcdInformer: etcdInformer,
Stop: stop,
InformersStarted: make(chan struct{}),
ResyncPeriod: resyncPeriod(),
}
}

func getEtcdInformer(operatorClient operatorclientset.Interface, operatorSharedInformer operatorinformers.SharedInformerFactory) (operatorv1.EtcdInformer, error) {
operatorGroups, err := operatorClient.Discovery().ServerResourcesForGroupVersion("operator.openshift.io/v1")
if err != nil {
glog.Errorf("unable to get operatorGroups: %#v", err)
return nil, err
}

for _, o := range operatorGroups.APIResources {
if o.Kind == "Etcd" {
return operatorSharedInformer.Operator().V1().Etcds(), nil
}
}
return nil, nil
}

0 comments on commit c29ebe9

Please sign in to comment.