diff --git a/cmd/contour/serve.go b/cmd/contour/serve.go index 63f7faa96fe..fefeaeabf97 100644 --- a/cmd/contour/serve.go +++ b/cmd/contour/serve.go @@ -110,6 +110,8 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext) serve.Flag("accesslog-format", "Format for Envoy access logs").StringVar(&ctx.AccessLogFormat) serve.Flag("disable-leader-election", "Disable leader election mechanism").BoolVar(&ctx.DisableLeaderElection) + + serve.Flag("use-extensions-v1beta1-ingress", "Subscribe to the deprecated extensions/v1beta1.Ingress type").BoolVar(&ctx.UseExtensionsV1beta1Ingress) return serve, ctx } @@ -168,7 +170,16 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { // step 4. register our resource event handler with the k8s informers. coreInformers.Core().V1().Services().Informer().AddEventHandler(eh) - coreInformers.Extensions().V1beta1().Ingresses().Informer().AddEventHandler(eh) + + // After K8s 1.13 the API server will automatically translate extensions/v1beta1.Ingress objects + // to networking/v1beta1.Ingress objects so we should only listen for one type or the other. + // The default behavior is to listen for networking/v1beta1.Ingress objects and let the API server + // transparently upgrade the extensions version for us. + if ctx.UseExtensionsV1beta1Ingress { + coreInformers.Extensions().V1beta1().Ingresses().Informer().AddEventHandler(eh) + } else { + coreInformers.Networking().V1beta1().Ingresses().Informer().AddEventHandler(eh) + } contourInformers.Contour().V1beta1().IngressRoutes().Informer().AddEventHandler(eh) contourInformers.Contour().V1beta1().TLSCertificateDelegations().Informer().AddEventHandler(eh) contourInformers.Projectcontour().V1().HTTPProxies().Informer().AddEventHandler(eh) diff --git a/cmd/contour/servecontext.go b/cmd/contour/servecontext.go index 3879e37debb..3f001dcdf99 100644 --- a/cmd/contour/servecontext.go +++ b/cmd/contour/servecontext.go @@ -98,6 +98,15 @@ type serveContext struct { // RequestTimeout sets the client request timeout globally for Contour. RequestTimeout time.Duration `yaml:"request-timeout,omitempty"` + + // Should Contour fall back to registering an informer for the deprecated + // extensions/v1beta1.Ingress type. + // By default this value is false, meaning Contour will register an informer for + // networking/v1beta1.Ingress and expect the API server to rewrite extensions/v1beta1.Ingress + // objects transparently. + // If the value is true, Contour will register for extensions/v1beta1.Ingress type and do + // the rewrite itself. + UseExtensionsV1beta1Ingress bool `yaml:"-"` } // newServeContext returns a serveContext initialized to defaults. @@ -153,6 +162,7 @@ func newServeContext() *serveContext { Namespace: "projectcontour", Name: "leader-elect", }, + UseExtensionsV1beta1Ingress: false, } } diff --git a/examples/contour/02-rbac.yaml b/examples/contour/02-rbac.yaml index b6ca954c85d..f270d7e1da7 100644 --- a/examples/contour/02-rbac.yaml +++ b/examples/contour/02-rbac.yaml @@ -49,6 +49,14 @@ rules: - get - list - watch +- apiGroups: + - "networking.k8s.io" + resources: + - ingresses + verbs: + - get + - list + - watch - apiGroups: ["contour.heptio.com"] resources: ["ingressroutes", "tlscertificatedelegations"] verbs: diff --git a/examples/contour/03-contour.yaml b/examples/contour/03-contour.yaml index 36afe06942a..16ede131f23 100644 --- a/examples/contour/03-contour.yaml +++ b/examples/contour/03-contour.yaml @@ -37,6 +37,7 @@ spec: - args: - serve - --incluster + - --use-extensions-v1beta1-ingress - --xds-address=0.0.0.0 - --xds-port=8001 - --envoy-service-http-port=80 diff --git a/examples/render/contour.yaml b/examples/render/contour.yaml index d9c93b71228..b1fd2a63b3c 100644 --- a/examples/render/contour.yaml +++ b/examples/render/contour.yaml @@ -327,6 +327,14 @@ rules: - get - list - watch +- apiGroups: + - "networking.k8s.io" + resources: + - ingresses + verbs: + - get + - list + - watch - apiGroups: ["contour.heptio.com"] resources: ["ingressroutes", "tlscertificatedelegations"] verbs: @@ -465,6 +473,7 @@ spec: - args: - serve - --incluster + - --use-extensions-v1beta1-ingress - --xds-address=0.0.0.0 - --xds-port=8001 - --envoy-service-http-port=80 diff --git a/internal/contour/cluster_test.go b/internal/contour/cluster_test.go index df1640ec768..0c147afe39b 100644 --- a/internal/contour/cluster_test.go +++ b/internal/contour/cluster_test.go @@ -28,7 +28,7 @@ import ( "github.com/projectcontour/contour/internal/envoy" "github.com/projectcontour/contour/internal/protobuf" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/contour/listener_test.go b/internal/contour/listener_test.go index 5066e559519..1a9a14cd1f2 100644 --- a/internal/contour/listener_test.go +++ b/internal/contour/listener_test.go @@ -25,7 +25,7 @@ import ( "github.com/projectcontour/contour/internal/assert" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/contour/route_test.go b/internal/contour/route_test.go index feaaf5fb2ec..798e6208670 100644 --- a/internal/contour/route_test.go +++ b/internal/contour/route_test.go @@ -29,7 +29,7 @@ import ( "github.com/projectcontour/contour/internal/envoy" "github.com/projectcontour/contour/internal/protobuf" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/contour/secret_test.go b/internal/contour/secret_test.go index ba2b53c2ef1..41dd019eb8d 100644 --- a/internal/contour/secret_test.go +++ b/internal/contour/secret_test.go @@ -11,7 +11,7 @@ import ( "github.com/projectcontour/contour/internal/assert" "github.com/projectcontour/contour/internal/dag" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/dag/annotations.go b/internal/dag/annotations.go index cbd12b4b6de..0829df7203e 100644 --- a/internal/dag/annotations.go +++ b/internal/dag/annotations.go @@ -20,7 +20,7 @@ import ( "time" envoy_api_v2_auth "github.com/envoyproxy/go-control-plane/envoy/api/v2/auth" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" ) // compatAnnotation checks the Object for the given annotation, first with the diff --git a/internal/dag/annotations_test.go b/internal/dag/annotations_test.go index 74465e7da19..c5cd15129f7 100644 --- a/internal/dag/annotations_test.go +++ b/internal/dag/annotations_test.go @@ -18,7 +18,7 @@ import ( "github.com/projectcontour/contour/internal/assert" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/dag/builder.go b/internal/dag/builder.go index b089b7fb243..d0bbd1db223 100644 --- a/internal/dag/builder.go +++ b/internal/dag/builder.go @@ -20,7 +20,7 @@ import ( "strings" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/util/intstr" ingressroutev1 "github.com/projectcontour/contour/apis/contour/v1beta1" diff --git a/internal/dag/builder_test.go b/internal/dag/builder_test.go index 7c34ff0ebfb..41265157e01 100644 --- a/internal/dag/builder_test.go +++ b/internal/dag/builder_test.go @@ -22,7 +22,7 @@ import ( ingressroutev1 "github.com/projectcontour/contour/apis/contour/v1beta1" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/dag/cache.go b/internal/dag/cache.go index 70358b79e92..ed6890930bc 100644 --- a/internal/dag/cache.go +++ b/internal/dag/cache.go @@ -14,8 +14,12 @@ package dag import ( + "bytes" + "encoding/json" + v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + extensionsv1beta1 "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" "k8s.io/client-go/tools/cache" ingressroutev1 "github.com/projectcontour/contour/apis/contour/v1beta1" @@ -105,6 +109,16 @@ func (kc *KubernetesCache) Insert(obj interface{}) bool { } kc.ingresses[m] = obj return true + case *extensionsv1beta1.Ingress: + ingress := new(v1beta1.Ingress) + if err := transposeIngress(obj, ingress); err != nil { + om := obj.GetObjectMeta() + kc.WithField("name", om.GetName()). + WithField("namespace", om.GetNamespace()). + Error(err) + return false + } + return kc.Insert(ingress) case *ingressroutev1.IngressRoute: class := ingressClass(obj) if class != "" && class != kc.ingressClass() { @@ -183,6 +197,11 @@ func (kc *KubernetesCache) remove(obj interface{}) bool { _, ok := kc.ingresses[m] delete(kc.ingresses, m) return ok + case *extensionsv1beta1.Ingress: + m := toMeta(obj) + _, ok := kc.ingresses[m] + delete(kc.ingresses, m) + return ok case *ingressroutev1.IngressRoute: m := toMeta(obj) _, ok := kc.ingressroutes[m] @@ -391,3 +410,15 @@ func (kc *KubernetesCache) secretTriggersRebuild(secret *v1.Secret) bool { return false } + +// transposeIngress transposes extensionis/v1beta1.Ingress objects into +// networking/v1beta1.Ingress objects. +func transposeIngress(src *extensionsv1beta1.Ingress, dst *v1beta1.Ingress) error { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + if err := enc.Encode(src); err != nil { + return nil + } + dec := json.NewDecoder(&buf) + return dec.Decode(dst) +} diff --git a/internal/dag/cache_test.go b/internal/dag/cache_test.go index ee19d6ab074..e9161b7703d 100644 --- a/internal/dag/cache_test.go +++ b/internal/dag/cache_test.go @@ -20,7 +20,7 @@ import ( projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/dag/policy.go b/internal/dag/policy.go index 89f1b3530db..bcb08c0f44b 100644 --- a/internal/dag/policy.go +++ b/internal/dag/policy.go @@ -18,7 +18,7 @@ import ( ingressroutev1 "github.com/projectcontour/contour/apis/contour/v1beta1" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" ) func retryPolicy(rp *projcontour.RetryPolicy) *RetryPolicy { diff --git a/internal/dag/policy_test.go b/internal/dag/policy_test.go index df179a48898..77f1445346b 100644 --- a/internal/dag/policy_test.go +++ b/internal/dag/policy_test.go @@ -20,7 +20,7 @@ import ( ingressroutev1 "github.com/projectcontour/contour/apis/contour/v1beta1" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/assert" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/dag/status_test.go b/internal/dag/status_test.go index b78a4d928f5..53f6adea06a 100644 --- a/internal/dag/status_test.go +++ b/internal/dag/status_test.go @@ -20,7 +20,7 @@ import ( projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/assert" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/e2e/cds_test.go b/internal/e2e/cds_test.go index 0b87a12d749..e0751f232f7 100644 --- a/internal/e2e/cds_test.go +++ b/internal/e2e/cds_test.go @@ -28,7 +28,7 @@ import ( "github.com/projectcontour/contour/internal/protobuf" "google.golang.org/grpc" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/e2e/lds_test.go b/internal/e2e/lds_test.go index b70847a3064..ac8537ef250 100644 --- a/internal/e2e/lds_test.go +++ b/internal/e2e/lds_test.go @@ -33,7 +33,7 @@ import ( "github.com/projectcontour/contour/internal/protobuf" "google.golang.org/grpc" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/e2e/rds_test.go b/internal/e2e/rds_test.go index 53dc99a1386..f890e5d657c 100644 --- a/internal/e2e/rds_test.go +++ b/internal/e2e/rds_test.go @@ -32,7 +32,7 @@ import ( "github.com/projectcontour/contour/internal/protobuf" "google.golang.org/grpc" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/e2e/sds_test.go b/internal/e2e/sds_test.go index 0804a669145..b52b3c4688d 100644 --- a/internal/e2e/sds_test.go +++ b/internal/e2e/sds_test.go @@ -21,7 +21,7 @@ import ( "github.com/projectcontour/contour/internal/dag" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/featuretests/ingressclass_test.go b/internal/featuretests/ingressclass_test.go index f8cbce66963..0f6f4e53214 100644 --- a/internal/featuretests/ingressclass_test.go +++ b/internal/featuretests/ingressclass_test.go @@ -22,7 +22,7 @@ import ( "github.com/projectcontour/contour/internal/contour" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/featuretests/kubernetes.go b/internal/featuretests/kubernetes.go index c66e875502c..d31a298e545 100644 --- a/internal/featuretests/kubernetes.go +++ b/internal/featuretests/kubernetes.go @@ -17,7 +17,7 @@ package featuretests import ( v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/featuretests/retrypolicy_test.go b/internal/featuretests/retrypolicy_test.go index 5dcd62e2889..5fa4799ff30 100644 --- a/internal/featuretests/retrypolicy_test.go +++ b/internal/featuretests/retrypolicy_test.go @@ -22,7 +22,7 @@ import ( projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/featuretests/timeoutpolicy_test.go b/internal/featuretests/timeoutpolicy_test.go index f96ec60d939..8ec97aa5a26 100644 --- a/internal/featuretests/timeoutpolicy_test.go +++ b/internal/featuretests/timeoutpolicy_test.go @@ -23,7 +23,7 @@ import ( "github.com/projectcontour/contour/internal/contour" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/featuretests/tlsprotocolversion_test.go b/internal/featuretests/tlsprotocolversion_test.go index 3241cad8bf7..29c6acf331b 100644 --- a/internal/featuretests/tlsprotocolversion_test.go +++ b/internal/featuretests/tlsprotocolversion_test.go @@ -22,7 +22,7 @@ import ( projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/featuretests/upstreamprotocol_test.go b/internal/featuretests/upstreamprotocol_test.go index 8c715c1c95d..2faa1287192 100644 --- a/internal/featuretests/upstreamprotocol_test.go +++ b/internal/featuretests/upstreamprotocol_test.go @@ -18,7 +18,7 @@ import ( v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/featuretests/websockets_test.go b/internal/featuretests/websockets_test.go index e478d9327eb..99e57c7c7a3 100644 --- a/internal/featuretests/websockets_test.go +++ b/internal/featuretests/websockets_test.go @@ -21,7 +21,7 @@ import ( projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/envoy" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/internal/grpc/server_test.go b/internal/grpc/server_test.go index 8078ed71b55..ebc28e10e53 100644 --- a/internal/grpc/server_test.go +++ b/internal/grpc/server_test.go @@ -31,7 +31,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" v1 "k8s.io/api/core/v1" - "k8s.io/api/extensions/v1beta1" + "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) diff --git a/site/examples/kuard.yaml b/site/examples/kuard.yaml index fa68dcdd010..689bd98c2ba 100644 --- a/site/examples/kuard.yaml +++ b/site/examples/kuard.yaml @@ -34,7 +34,7 @@ spec: sessionAffinity: None type: ClusterIP --- -apiVersion: extensions/v1beta1 +apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: kuard