Merge pull request #4127 from aledbf/migration
Migrate to new networking.k8s.io/v1beta1 package
This commit is contained in:
commit
6f1261015b
116 changed files with 1172 additions and 658 deletions
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
"github.com/mitchellh/hashstructure"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
|
@ -199,7 +199,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
|||
|
||||
// CheckIngress returns an error in case the provided ingress, when added
|
||||
// to the current configuration, generates an invalid configuration
|
||||
func (n *NGINXController) CheckIngress(ing *extensions.Ingress) error {
|
||||
func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
|
||||
//TODO: this is wrong
|
||||
if n == nil {
|
||||
return fmt.Errorf("cannot check ingress on a nil ingress controller")
|
||||
|
|
@ -807,7 +807,7 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
|
||||
// getServiceClusterEndpoint returns an Endpoint corresponding to the ClusterIP
|
||||
// field of a Service.
|
||||
func (n *NGINXController) getServiceClusterEndpoint(svcKey string, backend *extensions.IngressBackend) (endpoint ingress.Endpoint, err error) {
|
||||
func (n *NGINXController) getServiceClusterEndpoint(svcKey string, backend *networking.IngressBackend) (endpoint ingress.Endpoint, err error) {
|
||||
svc, err := n.store.GetService(svcKey)
|
||||
if err != nil {
|
||||
return endpoint, fmt.Errorf("service %q does not exist", svcKey)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import (
|
|||
"github.com/eapache/channels"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
|
|
@ -169,14 +169,14 @@ func TestCheckIngress(t *testing.T) {
|
|||
ingresses: []*ingress.Ingress{},
|
||||
}
|
||||
|
||||
ing := &extensions.Ingress{
|
||||
ing := &networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-ingress",
|
||||
Namespace: "user-namespace",
|
||||
Annotations: map[string]string{},
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "example.com",
|
||||
},
|
||||
|
|
@ -262,20 +262,20 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
}{
|
||||
"alternative backend has no server and embeds into matching real backend": {
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "example.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
@ -343,20 +343,20 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
},
|
||||
"alternative backend merges with the correct real backend when multiple are present": {
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "foo-http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
@ -370,12 +370,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Host: "example.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
@ -476,20 +476,20 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
},
|
||||
"alternative backend does not merge into itself": {
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "example.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
@ -520,12 +520,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
},
|
||||
"catch-all alternative backend has no server and embeds into matching real backend": {
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
|
|
@ -586,12 +586,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
},
|
||||
"catch-all alternative backend does not merge into itself": {
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
|
|
@ -696,15 +696,15 @@ func TestExtractTLSSecretName(t *testing.T) {
|
|||
"ingress tls, nil secret": {
|
||||
"foo.bar",
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{
|
||||
Spec: networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{
|
||||
{SecretName: "demo"},
|
||||
},
|
||||
Rules: []extensions.IngressRule{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
},
|
||||
|
|
@ -720,15 +720,15 @@ func TestExtractTLSSecretName(t *testing.T) {
|
|||
"ingress tls, no host, matching cert cn": {
|
||||
"foo.bar",
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{
|
||||
Spec: networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{
|
||||
{SecretName: "demo"},
|
||||
},
|
||||
Rules: []extensions.IngressRule{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
},
|
||||
|
|
@ -746,17 +746,17 @@ func TestExtractTLSSecretName(t *testing.T) {
|
|||
"ingress tls, no host, wildcard cert with matching cn": {
|
||||
"foo.bar",
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{
|
||||
Spec: networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{
|
||||
{
|
||||
SecretName: "demo",
|
||||
},
|
||||
},
|
||||
Rules: []extensions.IngressRule{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "test.foo.bar",
|
||||
},
|
||||
|
|
@ -774,18 +774,18 @@ func TestExtractTLSSecretName(t *testing.T) {
|
|||
"ingress tls, hosts, matching cert cn": {
|
||||
"foo.bar",
|
||||
&ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{
|
||||
Spec: networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{
|
||||
{
|
||||
Hosts: []string{"foo.bar", "example.com"},
|
||||
SecretName: "demo",
|
||||
},
|
||||
},
|
||||
Rules: []extensions.IngressRule{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
},
|
||||
|
|
@ -820,12 +820,12 @@ func TestGetBackendServers(t *testing.T) {
|
|||
{
|
||||
Ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
|
|
@ -862,12 +862,12 @@ func TestGetBackendServers(t *testing.T) {
|
|||
{
|
||||
Ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
|
|
@ -882,12 +882,12 @@ func TestGetBackendServers(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
|
|
@ -924,20 +924,20 @@ func TestGetBackendServers(t *testing.T) {
|
|||
{
|
||||
Ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "example.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
@ -981,21 +981,21 @@ func TestGetBackendServers(t *testing.T) {
|
|||
{
|
||||
Ingresses: []*ingress.Ingress{
|
||||
{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "example",
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "example.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
@ -1017,21 +1017,21 @@ func TestGetBackendServers(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "example-canary",
|
||||
Namespace: "example",
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "example.com",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
"k8s.io/klog"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
|
|
@ -208,7 +208,7 @@ func (s *k8sStore) checkSSLChainIssues() {
|
|||
func (s *k8sStore) sendDummyEvent() {
|
||||
s.updateCh.In() <- Event{
|
||||
Type: UpdateEvent,
|
||||
Obj: &extensions.Ingress{
|
||||
Obj: &networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "dummy",
|
||||
Namespace: "dummy",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
package store
|
||||
|
||||
import (
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ type IngressLister struct {
|
|||
}
|
||||
|
||||
// ByKey returns the Ingress matching key in the local Ingress Store.
|
||||
func (il IngressLister) ByKey(key string) (*extensions.Ingress, error) {
|
||||
func (il IngressLister) ByKey(key string) (*networking.Ingress, error) {
|
||||
i, exists, err := il.GetByKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -35,5 +35,5 @@ func (il IngressLister) ByKey(key string) (*extensions.Ingress, error) {
|
|||
if !exists {
|
||||
return nil, NotExistsError(key)
|
||||
}
|
||||
return i.(*extensions.Ingress), nil
|
||||
return i.(*networking.Ingress), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,12 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/eapache/channels"
|
||||
"k8s.io/klog"
|
||||
|
||||
"github.com/eapache/channels"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||
networkingv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
k8sruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
|
|
@ -41,7 +43,6 @@ import (
|
|||
clientcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/klog"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
|
|
@ -274,7 +275,12 @@ func New(checkOCSP bool,
|
|||
informers.WithNamespace(namespace),
|
||||
informers.WithTweakListOptions(func(*metav1.ListOptions) {}))
|
||||
|
||||
store.informers.Ingress = infFactory.Extensions().V1beta1().Ingresses().Informer()
|
||||
if k8s.IsNetworkingIngressAvailable {
|
||||
store.informers.Ingress = infFactory.Networking().V1beta1().Ingresses().Informer()
|
||||
} else {
|
||||
store.informers.Ingress = infFactory.Extensions().V1beta1().Ingresses().Informer()
|
||||
}
|
||||
|
||||
store.listers.Ingress.Store = store.informers.Ingress.GetStore()
|
||||
|
||||
store.informers.Endpoint = infFactory.Core().V1().Endpoints().Informer()
|
||||
|
|
@ -308,7 +314,7 @@ func New(checkOCSP bool,
|
|||
store.listers.Pod.Store = store.informers.Pod.GetStore()
|
||||
|
||||
ingDeleteHandler := func(obj interface{}) {
|
||||
ing, ok := obj.(*extensions.Ingress)
|
||||
ing, ok := toIngress(obj)
|
||||
if !ok {
|
||||
// If we reached here it means the ingress was deleted but its final state is unrecorded.
|
||||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
|
||||
|
|
@ -316,12 +322,13 @@ func New(checkOCSP bool,
|
|||
klog.Errorf("couldn't get object from tombstone %#v", obj)
|
||||
return
|
||||
}
|
||||
ing, ok = tombstone.Obj.(*extensions.Ingress)
|
||||
ing, ok = tombstone.Obj.(*networkingv1beta1.Ingress)
|
||||
if !ok {
|
||||
klog.Errorf("Tombstone contained object that is not an Ingress: %#v", obj)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !class.IsValid(ing) {
|
||||
klog.Infof("ignoring delete for ingress %v based on annotation %v", ing.Name, class.IngressKey)
|
||||
return
|
||||
|
|
@ -345,7 +352,7 @@ func New(checkOCSP bool,
|
|||
|
||||
ingEventHandler := cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
ing := obj.(*extensions.Ingress)
|
||||
ing, _ := toIngress(obj)
|
||||
if !class.IsValid(ing) {
|
||||
a, _ := parser.GetStringAnnotation(class.IngressKey, ing)
|
||||
klog.Infof("ignoring add for ingress %v based on annotation %v with value %v", ing.Name, class.IngressKey, a)
|
||||
|
|
@ -368,8 +375,9 @@ func New(checkOCSP bool,
|
|||
},
|
||||
DeleteFunc: ingDeleteHandler,
|
||||
UpdateFunc: func(old, cur interface{}) {
|
||||
oldIng := old.(*extensions.Ingress)
|
||||
curIng := cur.(*extensions.Ingress)
|
||||
oldIng, _ := toIngress(old)
|
||||
curIng, _ := toIngress(cur)
|
||||
|
||||
validOld := class.IsValid(oldIng)
|
||||
validCur := class.IsValid(curIng)
|
||||
if !validOld && validCur {
|
||||
|
|
@ -622,17 +630,17 @@ func New(checkOCSP bool,
|
|||
|
||||
// isCatchAllIngress returns whether or not an ingress produces a
|
||||
// catch-all server, and so should be ignored when --disable-catch-all is set
|
||||
func isCatchAllIngress(spec extensions.IngressSpec) bool {
|
||||
func isCatchAllIngress(spec networkingv1beta1.IngressSpec) bool {
|
||||
return spec.Backend != nil && len(spec.Rules) == 0
|
||||
}
|
||||
|
||||
// syncIngress parses ingress annotations converting the value of the
|
||||
// annotation to a go struct
|
||||
func (s *k8sStore) syncIngress(ing *extensions.Ingress) {
|
||||
func (s *k8sStore) syncIngress(ing *networkingv1beta1.Ingress) {
|
||||
key := k8s.MetaNamespaceKey(ing)
|
||||
klog.V(3).Infof("updating annotations information for ingress %v", key)
|
||||
|
||||
copyIng := &extensions.Ingress{}
|
||||
copyIng := &networkingv1beta1.Ingress{}
|
||||
ing.ObjectMeta.DeepCopyInto(©Ing.ObjectMeta)
|
||||
ing.Spec.DeepCopyInto(©Ing.Spec)
|
||||
ing.Status.DeepCopyInto(©Ing.Status)
|
||||
|
|
@ -660,7 +668,7 @@ func (s *k8sStore) syncIngress(ing *extensions.Ingress) {
|
|||
|
||||
// updateSecretIngressMap takes an Ingress and updates all Secret objects it
|
||||
// references in secretIngressMap.
|
||||
func (s *k8sStore) updateSecretIngressMap(ing *extensions.Ingress) {
|
||||
func (s *k8sStore) updateSecretIngressMap(ing *networkingv1beta1.Ingress) {
|
||||
key := k8s.MetaNamespaceKey(ing)
|
||||
klog.V(3).Infof("updating references to secrets for ingress %v", key)
|
||||
|
||||
|
|
@ -702,7 +710,7 @@ func (s *k8sStore) updateSecretIngressMap(ing *extensions.Ingress) {
|
|||
|
||||
// objectRefAnnotationNsKey returns an object reference formatted as a
|
||||
// 'namespace/name' key from the given annotation name.
|
||||
func objectRefAnnotationNsKey(ann string, ing *extensions.Ingress) (string, error) {
|
||||
func objectRefAnnotationNsKey(ann string, ing *networkingv1beta1.Ingress) (string, error) {
|
||||
annValue, err := parser.GetStringAnnotation(ann, ing)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -721,7 +729,7 @@ func objectRefAnnotationNsKey(ann string, ing *extensions.Ingress) (string, erro
|
|||
|
||||
// syncSecrets synchronizes data from all Secrets referenced by the given
|
||||
// Ingress with the local store and file system.
|
||||
func (s *k8sStore) syncSecrets(ing *extensions.Ingress) {
|
||||
func (s *k8sStore) syncSecrets(ing *networkingv1beta1.Ingress) {
|
||||
key := k8s.MetaNamespaceKey(ing)
|
||||
for _, secrKey := range s.secretIngressMap.ReferencedBy(key) {
|
||||
s.syncSecret(secrKey)
|
||||
|
|
@ -751,7 +759,7 @@ func (s *k8sStore) GetService(key string) (*corev1.Service, error) {
|
|||
}
|
||||
|
||||
// getIngress returns the Ingress matching key.
|
||||
func (s *k8sStore) getIngress(key string) (*extensions.Ingress, error) {
|
||||
func (s *k8sStore) getIngress(key string) (*networkingv1beta1.Ingress, error) {
|
||||
ing, err := s.listers.IngressWithAnnotation.ByKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -892,3 +900,40 @@ func (s k8sStore) GetRunningControllerPodsCount() int {
|
|||
|
||||
return count
|
||||
}
|
||||
|
||||
var runtimeScheme = k8sruntime.NewScheme()
|
||||
|
||||
func init() {
|
||||
extensionsv1beta1.AddToScheme(runtimeScheme)
|
||||
networkingv1beta1.AddToScheme(runtimeScheme)
|
||||
}
|
||||
|
||||
func fromExtensions(old *extensionsv1beta1.Ingress) (*networkingv1beta1.Ingress, error) {
|
||||
networkingIngress := &networkingv1beta1.Ingress{}
|
||||
|
||||
err := runtimeScheme.Convert(old, networkingIngress, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return networkingIngress, nil
|
||||
}
|
||||
|
||||
func toIngress(obj interface{}) (*networkingv1beta1.Ingress, bool) {
|
||||
oldVersion, inExtension := obj.(*extensionsv1beta1.Ingress)
|
||||
if inExtension {
|
||||
ing, err := fromExtensions(oldVersion)
|
||||
if err != nil {
|
||||
klog.Errorf("unexpected error converting Ingress from extensions package: %v", err)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return ing, true
|
||||
}
|
||||
|
||||
if ing, ok := obj.(*networkingv1beta1.Ingress); ok {
|
||||
return ing, true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package store
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
|
@ -29,6 +30,7 @@ import (
|
|||
"github.com/eapache/channels"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
|
@ -44,6 +46,8 @@ import (
|
|||
)
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
k8s.IsNetworkingIngressAvailable = true
|
||||
|
||||
pod := &k8s.PodInfo{
|
||||
Name: "testpod",
|
||||
Namespace: v1.NamespaceDefault,
|
||||
|
|
@ -61,8 +65,7 @@ func TestStore(t *testing.T) {
|
|||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
|
||||
// TODO: this defer is called after any error (even the expected ones)
|
||||
// defer te.Stop()
|
||||
defer te.Stop()
|
||||
|
||||
clientSet, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
|
|
@ -149,7 +152,7 @@ func TestStore(t *testing.T) {
|
|||
if e.Obj == nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := e.Obj.(*extensions.Ingress); !ok {
|
||||
if _, ok := e.Obj.(*networking.Ingress); !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -181,22 +184,21 @@ func TestStore(t *testing.T) {
|
|||
|
||||
storer.Run(stopCh)
|
||||
|
||||
ing := ensureIngress(&extensions.Ingress{
|
||||
ing := ensureIngress(&networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "dummy",
|
||||
Namespace: ns,
|
||||
SelfLink: fmt.Sprintf("/apis/extensions/v1beta1/namespaces/%s/ingresses/dummy", ns),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "dummy",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -216,25 +218,24 @@ func TestStore(t *testing.T) {
|
|||
time.Sleep(1 * time.Second)
|
||||
|
||||
// create an invalid ingress (different class)
|
||||
invalidIngress := ensureIngress(&extensions.Ingress{
|
||||
invalidIngress := ensureIngress(&networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "custom-class",
|
||||
SelfLink: fmt.Sprintf("/apis/extensions/v1beta1/namespaces/%s/ingresses/custom-class", ns),
|
||||
Namespace: ns,
|
||||
Annotations: map[string]string{
|
||||
"kubernetes.io/ingress.class": "something",
|
||||
},
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "dummy",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -257,7 +258,7 @@ func TestStore(t *testing.T) {
|
|||
// Secret takes a bit to update
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
err = clientSet.ExtensionsV1beta1().Ingresses(ni.Namespace).Delete(ni.Name, &metav1.DeleteOptions{})
|
||||
err = clientSet.NetworkingV1beta1().Ingresses(ni.Namespace).Delete(ni.Name, &metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("error creating ingress: %v", err)
|
||||
}
|
||||
|
|
@ -302,7 +303,7 @@ func TestStore(t *testing.T) {
|
|||
if e.Obj == nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := e.Obj.(*extensions.Ingress); !ok {
|
||||
if _, ok := e.Obj.(*networking.Ingress); !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -335,25 +336,24 @@ func TestStore(t *testing.T) {
|
|||
storer.Run(stopCh)
|
||||
|
||||
// create an invalid ingress (different class)
|
||||
invalidIngress := ensureIngress(&extensions.Ingress{
|
||||
invalidIngress := ensureIngress(&networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "custom-class",
|
||||
SelfLink: fmt.Sprintf("/apis/extensions/v1beta1/namespaces/%s/ingresses/custom-class", ns),
|
||||
Namespace: ns,
|
||||
Annotations: map[string]string{
|
||||
"kubernetes.io/ingress.class": "something",
|
||||
},
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "dummy",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -535,19 +535,18 @@ func TestStore(t *testing.T) {
|
|||
ingressName := "ingress-with-secret"
|
||||
secretName := "referenced"
|
||||
|
||||
ing := ensureIngress(&extensions.Ingress{
|
||||
ing := ensureIngress(&networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: ingressName,
|
||||
Namespace: ns,
|
||||
SelfLink: fmt.Sprintf("/apis/extensions/v1beta1/namespaces/%s/ingresses/%s", ns, ingressName),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{
|
||||
Spec: networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{
|
||||
{
|
||||
SecretName: secretName,
|
||||
},
|
||||
},
|
||||
Backend: &extensions.IngressBackend{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -648,28 +647,27 @@ func TestStore(t *testing.T) {
|
|||
name := "ingress-with-secret"
|
||||
secretHosts := []string{name}
|
||||
|
||||
ing := ensureIngress(&extensions.Ingress{
|
||||
ing := ensureIngress(&networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: ns,
|
||||
SelfLink: fmt.Sprintf("/apis/extensions/v1beta1/namespaces/%s/ingresses/%s", ns, name),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{
|
||||
Spec: networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{
|
||||
{
|
||||
Hosts: secretHosts,
|
||||
SecretName: name,
|
||||
},
|
||||
},
|
||||
Rules: []extensions.IngressRule{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: name,
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -779,8 +777,7 @@ func createConfigMap(clientSet kubernetes.Interface, ns string, t *testing.T) st
|
|||
|
||||
configMap := &v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "config",
|
||||
SelfLink: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/config", ns),
|
||||
Name: "config",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -792,15 +789,15 @@ func createConfigMap(clientSet kubernetes.Interface, ns string, t *testing.T) st
|
|||
return cm.Name
|
||||
}
|
||||
|
||||
func ensureIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface, t *testing.T) *extensions.Ingress {
|
||||
func ensureIngress(ingress *networking.Ingress, clientSet kubernetes.Interface, t *testing.T) *networking.Ingress {
|
||||
t.Helper()
|
||||
ing, err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(ingress)
|
||||
ing, err := clientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Update(ingress)
|
||||
|
||||
if err != nil {
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
t.Logf("Ingress %v not found, creating", ingress)
|
||||
|
||||
ing, err = clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(ingress)
|
||||
ing, err = clientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Create(ingress)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating ingress %+v: %v", ingress, err)
|
||||
}
|
||||
|
|
@ -815,9 +812,9 @@ func ensureIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface,
|
|||
return ing
|
||||
}
|
||||
|
||||
func deleteIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface, t *testing.T) {
|
||||
func deleteIngress(ingress *networking.Ingress, clientSet kubernetes.Interface, t *testing.T) {
|
||||
t.Helper()
|
||||
err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Delete(ingress.Name, &metav1.DeleteOptions{})
|
||||
err := clientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Delete(ingress.Name, &metav1.DeleteOptions{})
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to delete ingress %+v: %v", ingress, err)
|
||||
|
|
@ -870,7 +867,7 @@ func newStore(t *testing.T) *k8sStore {
|
|||
func TestUpdateSecretIngressMap(t *testing.T) {
|
||||
s := newStore(t)
|
||||
|
||||
ingTpl := &extensions.Ingress{
|
||||
ingTpl := &networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test",
|
||||
Namespace: "testns",
|
||||
|
|
@ -880,8 +877,8 @@ func TestUpdateSecretIngressMap(t *testing.T) {
|
|||
|
||||
t.Run("with TLS secret", func(t *testing.T) {
|
||||
ing := ingTpl.DeepCopy()
|
||||
ing.Spec = extensions.IngressSpec{
|
||||
TLS: []extensions.IngressTLS{{SecretName: "tls"}},
|
||||
ing.Spec = networking.IngressSpec{
|
||||
TLS: []networking.IngressTLS{{SecretName: "tls"}},
|
||||
}
|
||||
s.listers.Ingress.Update(ing)
|
||||
s.updateSecretIngressMap(ing)
|
||||
|
|
@ -935,7 +932,7 @@ func TestListIngresses(t *testing.T) {
|
|||
s := newStore(t)
|
||||
|
||||
ingressToIgnore := &ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-2",
|
||||
Namespace: "testns",
|
||||
|
|
@ -944,8 +941,8 @@ func TestListIngresses(t *testing.T) {
|
|||
},
|
||||
CreationTimestamp: metav1.NewTime(time.Now()),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -955,21 +952,21 @@ func TestListIngresses(t *testing.T) {
|
|||
s.listers.IngressWithAnnotation.Add(ingressToIgnore)
|
||||
|
||||
ingressWithoutPath := &ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-3",
|
||||
Namespace: "testns",
|
||||
CreationTimestamp: metav1.NewTime(time.Now()),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -985,7 +982,7 @@ func TestListIngresses(t *testing.T) {
|
|||
s.listers.IngressWithAnnotation.Add(ingressWithoutPath)
|
||||
|
||||
ingressWithNginxClass := &ingress.Ingress{
|
||||
Ingress: extensions.Ingress{
|
||||
Ingress: networking.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-4",
|
||||
Namespace: "testns",
|
||||
|
|
@ -994,16 +991,16 @@ func TestListIngresses(t *testing.T) {
|
|||
},
|
||||
CreationTimestamp: metav1.NewTime(time.Now()),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
Spec: networking.IngressSpec{
|
||||
Rules: []networking.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/demo",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
|
|
@ -1133,3 +1130,51 @@ func TestGetRunningControllerPodsCount(t *testing.T) {
|
|||
t.Errorf("Expected 1 controller Pods but got %v", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIngressConversion(t *testing.T) {
|
||||
ing := &extensions.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "old-ingress",
|
||||
Namespace: "demo",
|
||||
CreationTimestamp: metav1.NewTime(time.Now()),
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Rules: []extensions.IngressRule{
|
||||
{
|
||||
Host: "foo.bar",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
{
|
||||
Backend: extensions.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
new, err := fromExtensions(ing)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error converting ingress: %v", err)
|
||||
}
|
||||
|
||||
m1, err := new.Marshal()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error marshalling Ingress: %v", err)
|
||||
}
|
||||
|
||||
m2, err := ing.Marshal()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error marshalling Ingress: %v", err)
|
||||
}
|
||||
|
||||
if bytes.Compare(m1, m2) != 0 {
|
||||
t.Fatalf("Expected marshalling of types should be equal")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
|
||||
|
|
@ -909,7 +909,7 @@ func TestGetIngressInformation(t *testing.T) {
|
|||
validIngress.Annotations = map[string]string{
|
||||
"ingress.annotation": "ok",
|
||||
}
|
||||
validIngress.Spec.Backend = &extensions.IngressBackend{
|
||||
validIngress.Spec.Backend = &networking.IngressBackend{
|
||||
ServiceName: "a-svc",
|
||||
}
|
||||
|
||||
|
|
@ -927,15 +927,15 @@ func TestGetIngressInformation(t *testing.T) {
|
|||
}
|
||||
|
||||
validIngress.Spec.Backend = nil
|
||||
validIngress.Spec.Rules = []extensions.IngressRule{
|
||||
validIngress.Spec.Rules = []networking.IngressRule{
|
||||
{
|
||||
Host: host,
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/ok",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "b-svc",
|
||||
},
|
||||
},
|
||||
|
|
@ -959,14 +959,14 @@ func TestGetIngressInformation(t *testing.T) {
|
|||
t.Errorf("Expected %v, but got %v", expected, info)
|
||||
}
|
||||
|
||||
validIngress.Spec.Rules = append(validIngress.Spec.Rules, extensions.IngressRule{
|
||||
validIngress.Spec.Rules = append(validIngress.Spec.Rules, networking.IngressRule{
|
||||
Host: "host2",
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
IngressRuleValue: networking.IngressRuleValue{
|
||||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/ok",
|
||||
Backend: extensions.IngressBackend{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "c-svc",
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue