Skip to content

Commit

Permalink
feat: implement knative support
Browse files Browse the repository at this point in the history
Knative Ingress resources are now processed and satisfied.
Plugins on Knative services are also supported via the regular
annotations.
  • Loading branch information
hbagdi committed Mar 9, 2020
1 parent d45d1de commit bbcf910
Show file tree
Hide file tree
Showing 12 changed files with 1,160 additions and 79 deletions.
31 changes: 27 additions & 4 deletions cli/ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
knativeclient "knative.dev/serving/pkg/client/clientset/versioned"
knativeinformer "knative.dev/serving/pkg/client/informers/externalversions"
)

func controllerConfigFromCLIConfig(cliConfig cliConfig) controller.Configuration {
Expand Down Expand Up @@ -240,6 +242,23 @@ func main() {
configurationinformer.WithNamespace(cliConfig.WatchNamespace),
)

knativeClient, _ := knativeclient.NewForConfig(kubeCfg)

var knativeInformerFactory knativeinformer.SharedInformerFactory
err = discovery.ServerSupportsVersion(knativeClient.Discovery(), schema.GroupVersion{
Group: "networking.internal.knative.dev",
Version: "v1alpha1",
})
if err == nil {
controllerConfig.EnableKnativeIngressSupport = true
controllerConfig.KnativeClient = knativeClient
knativeInformerFactory = knativeinformer.NewSharedInformerFactoryWithOptions(
knativeClient,
cliConfig.SyncPeriod,
knativeinformer.WithNamespace(cliConfig.WatchNamespace),
)
}

var synced []cache.InformerSynced
updateChannel := channels.NewRingChannel(1024)
reh := controller.ResourceEventHandler{
Expand Down Expand Up @@ -307,6 +326,13 @@ func main() {
cacheStores.Credential = kongCredentialInformer.GetStore()
informers = append(informers, kongCredentialInformer)

if controllerConfig.EnableKnativeIngressSupport {
knativeIngressInformer := knativeInformerFactory.Networking().V1alpha1().Ingresses().Informer()
knativeIngressInformer.AddEventHandler(reh)
cacheStores.KnativeIngress = knativeIngressInformer.GetStore()
informers = append(informers, knativeIngressInformer)
}

stopCh := make(chan struct{})
for _, informer := range informers {
go informer.Run(stopCh)
Expand All @@ -316,10 +342,7 @@ func main() {
runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync"))
}

store := store.New(
cacheStores,
annotations.IngressClassValidatorFuncFromObjectMeta(controllerConfig.IngressClass),
)
store := store.New(cacheStores, cliConfig.IngressClass)
kong, err := controller.NewKongController(&controllerConfig, updateChannel,
store)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions cli/ingress-controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"

"github.com/eapache/channels"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/annotations"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/controller"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/store"
)
Expand Down Expand Up @@ -77,10 +76,7 @@ func TestHandleSigterm(t *testing.T) {
KubeClient: kubeClient,
},
channels.NewRingChannel(1024),
store.New(
store.CacheStores{},
annotations.IngressClassValidatorFuncFromObjectMeta(conf.IngressClass),
),
store.New(store.CacheStores{}, conf.IngressClass),
)

go handleSigterm(kong, make(chan struct{}), func(code int) {
Expand Down
34 changes: 15 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,34 @@ module github.com/kong/kubernetes-ingress-controller
go 1.13

require (
cloud.google.com/go v0.40.0 // indirect
github.com/blang/semver v0.0.0-20190414102917-ba2c2ddd8906
contrib.go.opencensus.io/exporter/ocagent v0.6.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.1.0 // indirect
contrib.go.opencensus.io/exporter/stackdriver v0.12.9 // indirect
github.com/blang/semver v3.5.0+incompatible
github.com/eapache/channels v1.1.0
github.com/eapache/queue v1.1.0 // indirect
github.com/evanphx/json-patch v4.1.0+incompatible // indirect
github.com/fatih/color v1.7.0
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/googleapis/gnostic v0.1.0 // indirect
github.com/google/go-containerregistry v0.0.0-20200131185320-aec8da010de2 // indirect
github.com/hashicorp/go-uuid v1.0.1
github.com/hbagdi/deck v0.7.1-0.20191223190449-3d9f90945d9d
github.com/hbagdi/go-kong v0.10.0
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/openzipkin/zipkin-go v0.2.2 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v0.9.4
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.2.1
github.com/prometheus/client_golang v1.0.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.4.0
github.com/tidwall/gjson v1.2.1
github.com/tidwall/match v1.0.1 // indirect
github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65 // indirect
golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
google.golang.org/appengine v1.6.1 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/pool.v3 v3.1.1
k8s.io/api v0.0.0-20190819141258-3544db3b9e44
k8s.io/apimachinery v0.0.0-20190817020851-f2f3a405f61d
k8s.io/client-go v0.0.0-20190819141724-e14f31a72a77
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
k8s.io/api v0.17.0
k8s.io/apimachinery v0.17.0
k8s.io/client-go v0.17.0
knative.dev/pkg v0.0.0-20200205160431-4ec5e09f716b // indirect
knative.dev/serving v0.12.1
)
Loading

0 comments on commit bbcf910

Please sign in to comment.