Skip to content

Commit

Permalink
Merge pull request #14817 from smarterclayton/client
Browse files Browse the repository at this point in the history
Move the router to use generated clientsets
  • Loading branch information
smarterclayton committed Jun 27, 2017
2 parents 1fb12f6 + bc83309 commit 3704f7f
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 77 deletions.
16 changes: 13 additions & 3 deletions pkg/cmd/infra/router/f5.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
projectinternalclientset "github.com/openshift/origin/pkg/project/generated/internalclientset"
routeapi "github.com/openshift/origin/pkg/route/apis/route"
routeinternalclientset "github.com/openshift/origin/pkg/route/generated/internalclientset"
"github.com/openshift/origin/pkg/router/controller"
f5plugin "github.com/openshift/origin/pkg/router/f5"
)
Expand Down Expand Up @@ -214,16 +216,24 @@ func (o *F5RouterOptions) Run() error {
return err
}

oc, kc, err := o.Config.Clients()
_, kc, err := o.Config.Clients()
if err != nil {
return err
}
routeclient, err := routeinternalclientset.NewForConfig(o.Config.OpenShiftConfig())
if err != nil {
return err
}
projectclient, err := projectinternalclientset.NewForConfig(o.Config.OpenShiftConfig())
if err != nil {
return err
}

statusPlugin := controller.NewStatusAdmitter(f5Plugin, oc, o.RouterName, "")
statusPlugin := controller.NewStatusAdmitter(f5Plugin, routeclient, o.RouterName, "")
uniqueHostPlugin := controller.NewUniqueHost(statusPlugin, o.RouteSelectionFunc(), o.RouterSelection.DisableNamespaceOwnershipCheck, statusPlugin)
plugin := controller.NewHostAdmitter(uniqueHostPlugin, o.F5RouteAdmitterFunc(), false, o.RouterSelection.DisableNamespaceOwnershipCheck, statusPlugin)

factory := o.RouterSelection.NewFactory(oc, kc)
factory := o.RouterSelection.NewFactory(routeclient, projectclient.Projects(), kc)
watchNodes := (len(o.InternalAddress) != 0 && len(o.VxlanGateway) != 0)
controller := factory.Create(plugin, watchNodes, o.EnableIngress)
controller.Run()
Expand Down
11 changes: 6 additions & 5 deletions pkg/cmd/infra/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"

oclient "github.com/openshift/origin/pkg/client"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/variable"
projectclient "github.com/openshift/origin/pkg/project/generated/internalclientset/typed/project/internalversion"
routeapi "github.com/openshift/origin/pkg/route/apis/route"
routeclient "github.com/openshift/origin/pkg/route/generated/internalclientset/typed/route/internalversion"
"github.com/openshift/origin/pkg/router/controller"
controllerfactory "github.com/openshift/origin/pkg/router/controller/factory"
)
Expand Down Expand Up @@ -220,8 +221,8 @@ func (o *RouterSelection) Complete() error {
}

// NewFactory initializes a factory that will watch the requested routes
func (o *RouterSelection) NewFactory(oc oclient.Interface, kc kclientset.Interface) *controllerfactory.RouterControllerFactory {
factory := controllerfactory.NewDefaultRouterControllerFactory(oc, kc)
func (o *RouterSelection) NewFactory(routeclient routeclient.RoutesGetter, projectclient projectclient.ProjectResourceInterface, kc kclientset.Interface) *controllerfactory.RouterControllerFactory {
factory := controllerfactory.NewDefaultRouterControllerFactory(routeclient, kc)
factory.Labels = o.Labels
factory.Fields = o.Fields
factory.Namespace = o.Namespace
Expand All @@ -232,7 +233,7 @@ func (o *RouterSelection) NewFactory(oc oclient.Interface, kc kclientset.Interfa
factory.Namespaces = namespaceNames{kc.Core().Namespaces(), o.NamespaceLabels}
case o.ProjectLabels != nil:
glog.Infof("Router is only using routes in projects matching %s", o.ProjectLabels)
factory.Namespaces = projectNames{oc.Projects(), o.ProjectLabels}
factory.Namespaces = projectNames{projectclient, o.ProjectLabels}
case len(factory.Namespace) > 0:
glog.Infof("Router is only using resources in namespace %s", factory.Namespace)
default:
Expand All @@ -243,7 +244,7 @@ func (o *RouterSelection) NewFactory(oc oclient.Interface, kc kclientset.Interfa

// projectNames returns the names of projects matching the label selector
type projectNames struct {
client oclient.ProjectInterface
client projectclient.ProjectResourceInterface
selector labels.Selector
}

Expand Down
20 changes: 16 additions & 4 deletions pkg/cmd/infra/router/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
projectinternalclientset "github.com/openshift/origin/pkg/project/generated/internalclientset"
routeinternalclientset "github.com/openshift/origin/pkg/route/generated/internalclientset"
"github.com/openshift/origin/pkg/router"
"github.com/openshift/origin/pkg/router/controller"
"github.com/openshift/origin/pkg/router/metrics"
"github.com/openshift/origin/pkg/router/metrics/haproxy"
templateplugin "github.com/openshift/origin/pkg/router/template"
"github.com/openshift/origin/pkg/util/proc"
"github.com/openshift/origin/pkg/version"
)

// defaultReloadInterval is how often to do reloads in seconds.
Expand Down Expand Up @@ -240,8 +243,9 @@ func (o *TemplateRouterOptions) Validate() error {

// Run launches a template router using the provided options. It never exits.
func (o *TemplateRouterOptions) Run() error {
statsPort := o.StatsPort
glog.Infof("Starting template router (%s)", version.Get())

statsPort := o.StatsPort
switch {
case o.MetricsType == "haproxy":
if len(o.StatsUsername) == 0 || len(o.StatsPassword) == 0 {
Expand Down Expand Up @@ -336,7 +340,15 @@ func (o *TemplateRouterOptions) Run() error {
StrictSNI: o.StrictSNI,
}

oc, kc, err := o.Config.Clients()
_, kc, err := o.Config.Clients()
if err != nil {
return err
}
routeclient, err := routeinternalclientset.NewForConfig(o.Config.OpenShiftConfig())
if err != nil {
return err
}
projectclient, err := projectinternalclientset.NewForConfig(o.Config.OpenShiftConfig())
if err != nil {
return err
}
Expand All @@ -347,15 +359,15 @@ func (o *TemplateRouterOptions) Run() error {
return err
}

statusPlugin := controller.NewStatusAdmitter(templatePlugin, oc, o.RouterName, o.RouterCanonicalHostname)
statusPlugin := controller.NewStatusAdmitter(templatePlugin, routeclient, o.RouterName, o.RouterCanonicalHostname)
var nextPlugin router.Plugin = statusPlugin
if o.ExtendedValidation {
nextPlugin = controller.NewExtendedValidator(nextPlugin, controller.RejectionRecorder(statusPlugin))
}
uniqueHostPlugin := controller.NewUniqueHost(nextPlugin, o.RouteSelectionFunc(), o.RouterSelection.DisableNamespaceOwnershipCheck, controller.RejectionRecorder(statusPlugin))
plugin := controller.NewHostAdmitter(uniqueHostPlugin, o.RouteAdmissionFunc(), o.AllowWildcardRoutes, o.RouterSelection.DisableNamespaceOwnershipCheck, controller.RejectionRecorder(statusPlugin))

factory := o.RouterSelection.NewFactory(oc, kc)
factory := o.RouterSelection.NewFactory(routeclient, projectclient.Projects(), kc)
controller := factory.Create(plugin, false, o.EnableIngress)
controller.Run()

Expand Down
8 changes: 4 additions & 4 deletions pkg/router/controller/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
kextensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion"

osclient "github.com/openshift/origin/pkg/client"
oscache "github.com/openshift/origin/pkg/client/cache"
routeapi "github.com/openshift/origin/pkg/route/apis/route"
osclient "github.com/openshift/origin/pkg/route/generated/internalclientset/typed/route/internalversion"
"github.com/openshift/origin/pkg/router"
routercontroller "github.com/openshift/origin/pkg/router/controller"
)
Expand All @@ -31,7 +31,7 @@ import (
// If Namespace is empty, it means "all namespaces".
type RouterControllerFactory struct {
KClient kcoreclient.EndpointsGetter
OSClient osclient.RoutesNamespacer
OSClient osclient.RoutesGetter
IngressClient kextensionsclient.IngressesGetter
SecretClient kcoreclient.SecretsGetter
NodeClient kcoreclient.NodesGetter
Expand All @@ -43,7 +43,7 @@ type RouterControllerFactory struct {
}

// NewDefaultRouterControllerFactory initializes a default router controller factory.
func NewDefaultRouterControllerFactory(oc osclient.RoutesNamespacer, kc kclientset.Interface) *RouterControllerFactory {
func NewDefaultRouterControllerFactory(oc osclient.RoutesGetter, kc kclientset.Interface) *RouterControllerFactory {
return &RouterControllerFactory{
KClient: kc.Core(),
OSClient: oc,
Expand Down Expand Up @@ -321,7 +321,7 @@ func hostIndexFunc(obj interface{}) ([]string, error) {
// routeLW is a ListWatcher for routes that can be filtered to a label, field, or
// namespace.
type routeLW struct {
client osclient.RoutesNamespacer
client osclient.RoutesGetter
label labels.Selector
field fields.Selector
namespace string
Expand Down
6 changes: 3 additions & 3 deletions pkg/router/controller/host_admitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"k8s.io/apimachinery/pkg/watch"
kapi "k8s.io/kubernetes/pkg/api"

"github.com/openshift/origin/pkg/client/testclient"
routeapi "github.com/openshift/origin/pkg/route/apis/route"
"github.com/openshift/origin/pkg/route/generated/internalclientset/fake"
)

const (
Expand Down Expand Up @@ -772,7 +772,7 @@ func TestStatusWildcardPolicyNoOp(t *testing.T) {
now := nowFn()
touched := metav1.Time{Time: now.Add(-time.Minute)}
p := &fakePlugin{}
c := testclient.NewSimpleFake()
c := fake.NewSimpleClientset()
recorder := rejectionRecorder{rejections: make(map[string]string)}
admitter := NewHostAdmitter(p, wildcardAdmitter, true, false, recorder)
err := admitter.HandleRoute(watch.Added, &routeapi.Route{
Expand Down Expand Up @@ -810,7 +810,7 @@ func TestStatusWildcardPolicyNotAllowedNoOp(t *testing.T) {
now := nowFn()
touched := metav1.Time{Time: now.Add(-time.Minute)}
p := &fakePlugin{}
c := testclient.NewSimpleFake()
c := fake.NewSimpleClientset()
recorder := rejectionRecorder{rejections: make(map[string]string)}
admitter := NewHostAdmitter(p, wildcardAdmitter, false, false, recorder)
err := admitter.HandleRoute(watch.Added, &routeapi.Route{
Expand Down
8 changes: 4 additions & 4 deletions pkg/router/controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"k8s.io/apimachinery/pkg/watch"
kapi "k8s.io/kubernetes/pkg/api"

"github.com/openshift/origin/pkg/client"
routeapi "github.com/openshift/origin/pkg/route/apis/route"
client "github.com/openshift/origin/pkg/route/generated/internalclientset/typed/route/internalversion"
"github.com/openshift/origin/pkg/router"
)

Expand All @@ -27,7 +27,7 @@ type RejectionRecorder interface {
// StatusAdmitter ensures routes added to the plugin have status set.
type StatusAdmitter struct {
plugin router.Plugin
client client.RoutesNamespacer
client client.RoutesGetter
routerName string
routerCanonicalHostname string

Expand All @@ -39,7 +39,7 @@ type StatusAdmitter struct {
// route has a status field set that matches this router. The admitter manages
// an LRU of recently seen conflicting updates to handle when two router processes
// with differing configurations are writing updates at the same time.
func NewStatusAdmitter(plugin router.Plugin, client client.RoutesNamespacer, name, hostName string) *StatusAdmitter {
func NewStatusAdmitter(plugin router.Plugin, client client.RoutesGetter, name, hostName string) *StatusAdmitter {
expected, _ := lru.New(1024)
return &StatusAdmitter{
plugin: plugin,
Expand Down Expand Up @@ -227,7 +227,7 @@ func (a *StatusAdmitter) recordIngressTouch(route *routeapi.Route, touch *metav1
// admitRoute returns true if the route has already been accepted to this router, or
// updates the route to contain an accepted condition. Returns an error if the route could
// not be admitted due to a failure, or false if the route can't be admitted at this time.
func (a *StatusAdmitter) admitRoute(oc client.RoutesNamespacer, route *routeapi.Route, name, hostName string) (bool, error) {
func (a *StatusAdmitter) admitRoute(oc client.RoutesGetter, route *routeapi.Route, name, hostName string) (bool, error) {
ingress, updated := findOrCreateIngress(route, name, hostName)

// keep lastTouch around
Expand Down
Loading

0 comments on commit 3704f7f

Please sign in to comment.