Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #526 from StrongMonkey/change-extension-api
Browse files Browse the repository at this point in the history
Switch ingress to extension api
  • Loading branch information
StrongMonkey authored Sep 27, 2019
2 parents 1c31fdc + 585f8e5 commit 303f365
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 114 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ require (
github.com/rancher/mapper v0.0.0-20190814232720-058a8b7feb99
github.com/rancher/rdns-server v0.4.2
github.com/rancher/wrangler v0.2.0
github.com/rancher/wrangler-api v0.2.1-0.20190905172212-0efb8da386d3
github.com/rancher/wrangler-api v0.2.1-0.20190927043440-45392ea2688b
github.com/rivo/tview v0.0.0-20190319111340-8d5eba0c2f51
github.com/rivo/uniseg v0.0.0-20190313204849-f699dde9c340 // indirect
github.com/sirupsen/logrus v1.4.2
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,11 @@ github.com/rancher/wrangler v0.1.7-0.20190905161106-749be31cca6c/go.mod h1:TLc4v
github.com/rancher/wrangler v0.2.0 h1:ENg7iac/aLgCbugUYosUMG7Kj97i4qMPejjqZFVorbw=
github.com/rancher/wrangler v0.2.0/go.mod h1:TLc4vXF21FWz2MYNHny5zDwFwBqvgBViU5n9CHrJRQ0=
github.com/rancher/wrangler-api v0.1.4/go.mod h1:Mc8bNN5rNxpQ7am2orUbonahw4xJ6ztF+fUTSku8KnE=
github.com/rancher/wrangler-api v0.2.0 h1:VR7hLNnDrKykKLqthtwZ58pDDtUa9ijSNToPaJLEkWc=
github.com/rancher/wrangler-api v0.2.1-0.20190905172212-0efb8da386d3 h1:kCWzAByYocGwqhuizVDMXRFlga2JGmHrOOEif/ybS0Q=
github.com/rancher/wrangler-api v0.2.1-0.20190905172212-0efb8da386d3/go.mod h1:FqoFw+p4DjhLkA13E+HVbBm9eOclTbBZ2rb61MY1DjQ=
github.com/rancher/wrangler-api v0.2.1-0.20190927043440-45392ea2688b h1:q+hdvDjMlG0mBNLqsEnb6UBijaj7fbQXrAcky0aP1Uw=
github.com/rancher/wrangler-api v0.2.1-0.20190927043440-45392ea2688b/go.mod h1:FqoFw+p4DjhLkA13E+HVbBm9eOclTbBZ2rb61MY1DjQ=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/rivo/tview v0.0.0-20190319111340-8d5eba0c2f51 h1:FEnZgBwXtLYXcQD3w5X1cJxkICxfMid6hjMY3ioKykg=
Expand Down
2 changes: 1 addition & 1 deletion modules/gateway/controllers/app/serviceset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Register(ctx context.Context, rContext *types.Context) error {
c := stackobject.NewGeneratingController(ctx, rContext, "routing-serviceset", rContext.Rio.Rio().V1().App())
c.Apply = c.Apply.WithStrictCaching().
WithCacheTypes(rContext.Networking.Networking().V1alpha3().DestinationRule(),
rContext.K8sNetworking.Networking().V1beta1().Ingress(),
rContext.K8sNetworking.Extensions().V1beta1().Ingress(),
rContext.Networking.Networking().V1alpha3().VirtualService()).WithRateLimiting(10)

sh := &serviceHandler{
Expand Down
22 changes: 11 additions & 11 deletions modules/service/controllers/clusterdomain/clusterdomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/rancher/wrangler/pkg/trigger"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
extensionv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -53,7 +53,7 @@ var (
func Register(ctx context.Context, rContext *types.Context) error {
h := handler{
apply: rContext.Apply.WithSetID(gatewayIngress).WithStrictCaching().
WithCacheTypes(rContext.K8sNetworking.Networking().V1beta1().Ingress()),
WithCacheTypes(rContext.K8sNetworking.Extensions().V1beta1().Ingress()),
namespace: rContext.Namespace,
apps: rContext.Rio.Rio().V1().App(),
services: rContext.Rio.Rio().V1().Service(),
Expand Down Expand Up @@ -88,7 +88,7 @@ func Register(ctx context.Context, rContext *types.Context) error {
case constants.InstallModeHostport:
rContext.Core.Core().V1().Endpoints().OnChange(ctx, "endpoints", h.syncEndpoint)
case constants.InstallModeIngress:
rContext.K8sNetworking.Networking().V1beta1().Ingress().OnChange(ctx, "ingress-endpoints", h.syncIngress)
rContext.K8sNetworking.Extensions().V1beta1().Ingress().OnChange(ctx, "ingress-endpoints", h.syncIngress)
}
} else {
addresses := strings.Split(constants.UseIPAddress, ",")
Expand Down Expand Up @@ -131,17 +131,17 @@ func (h handler) syncClusterIngress(key string, obj *adminv1.ClusterDomain) (*ad
}

if constants.InstallMode == constants.InstallModeIngress {
ingress := constructors.NewIngress(h.namespace, constants.ClusterIngressName, networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
ingress := constructors.NewIngress(h.namespace, constants.ClusterIngressName, extensionv1beta1.Ingress{
Spec: extensionv1beta1.IngressSpec{
Rules: []extensionv1beta1.IngressRule{
{
Host: domain,
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionv1beta1.IngressRuleValue{
HTTP: &extensionv1beta1.HTTPIngressRuleValue{
Paths: []extensionv1beta1.HTTPIngressPath{
{
Path: "/rio-gateway",
Backend: networkingv1beta1.IngressBackend{
Backend: extensionv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand Down Expand Up @@ -256,7 +256,7 @@ func getNodeIP(node *v1.Node) string {
return ""
}

func (h handler) syncIngress(key string, ingress *networkingv1beta1.Ingress) (*networkingv1beta1.Ingress, error) {
func (h handler) syncIngress(key string, ingress *extensionv1beta1.Ingress) (*extensionv1beta1.Ingress, error) {
if ingress == nil {
return ingress, nil
}
Expand Down
8 changes: 4 additions & 4 deletions modules/service/controllers/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ import (
func Register(ctx context.Context, rContext *types.Context) error {
serviceController := stackobject.NewGeneratingController(ctx, rContext, "ingress-service", rContext.Rio.Rio().V1().Service())
serviceController.Apply = serviceController.Apply.WithStrictCaching().
WithCacheTypes(rContext.K8sNetworking.Networking().V1beta1().Ingress())
WithCacheTypes(rContext.K8sNetworking.Extensions().V1beta1().Ingress())

appController := stackobject.NewGeneratingController(ctx, rContext, "ingress-app", rContext.Rio.Rio().V1().App())
appController.Apply = appController.Apply.WithStrictCaching().
WithCacheTypes(rContext.K8sNetworking.Networking().V1beta1().Ingress())
WithCacheTypes(rContext.K8sNetworking.Extensions().V1beta1().Ingress())

routerController := stackobject.NewGeneratingController(ctx, rContext, "ingress-routeset", rContext.Rio.Rio().V1().Router())
routerController.Apply = routerController.Apply.WithStrictCaching().
WithCacheTypes(rContext.K8sNetworking.Networking().V1beta1().Ingress())
WithCacheTypes(rContext.K8sNetworking.Extensions().V1beta1().Ingress())

publicdomainController := stackobject.NewGeneratingController(ctx, rContext, "ingress-publicdomain", rContext.Global.Admin().V1().PublicDomain())
publicdomainController.Apply = publicdomainController.Apply.WithCacheTypes(rContext.Networking.Networking().V1alpha3().DestinationRule(),
rContext.K8sNetworking.Networking().V1beta1().Ingress())
rContext.K8sNetworking.Extensions().V1beta1().Ingress())

sh := &handler{
systemNamespace: rContext.Namespace,
Expand Down
50 changes: 25 additions & 25 deletions modules/service/controllers/ingress/populate/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/rancher/rio/pkg/services"
"github.com/rancher/wrangler/pkg/name"
"github.com/rancher/wrangler/pkg/objectset"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
)

Expand All @@ -26,16 +26,16 @@ func Ingress(namespace, domain, certName string, ignoreVersion bool, svc *riov1.
}
host := domains.GetExternalDomain(prefix, svc.Namespace, domain)

ingress := constructors.NewIngress(namespace, fmt.Sprintf("%s-%s", prefix, svc.Namespace), networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
ingress := constructors.NewIngress(namespace, fmt.Sprintf("%s-%s", prefix, svc.Namespace), extensionsv1beta1.Ingress{
Spec: extensionsv1beta1.IngressSpec{
Rules: []extensionsv1beta1.IngressRule{
{
Host: host,
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionsv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -45,7 +45,7 @@ func Ingress(namespace, domain, certName string, ignoreVersion bool, svc *riov1.
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionsv1beta1.IngressTLS{
{
Hosts: []string{fmt.Sprintf("*.%s", domain)},
SecretName: certName,
Expand All @@ -61,16 +61,16 @@ func Ingress(namespace, domain, certName string, ignoreVersion bool, svc *riov1.
func IngressForRouter(namespace, domain, certName string, route *riov1.Router, os *objectset.ObjectSet) {
host := fmt.Sprintf("%s-%s.%s", route.Name, route.Namespace, domain)

ingress := constructors.NewIngress(namespace, fmt.Sprintf("%s-%s", route.Name, route.Namespace), networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
ingress := constructors.NewIngress(namespace, fmt.Sprintf("%s-%s", route.Name, route.Namespace), extensionsv1beta1.Ingress{
Spec: extensionsv1beta1.IngressSpec{
Rules: []extensionsv1beta1.IngressRule{
{
Host: host,
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionsv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -80,7 +80,7 @@ func IngressForRouter(namespace, domain, certName string, route *riov1.Router, o
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionsv1beta1.IngressTLS{
{
Hosts: []string{fmt.Sprintf("*.%s", domain)},
SecretName: certName,
Expand All @@ -94,16 +94,16 @@ func IngressForRouter(namespace, domain, certName string, route *riov1.Router, o
}

func IngressForPublicDomain(systemNamespace string, pd *adminv1.PublicDomain, os *objectset.ObjectSet) {
ingress := constructors.NewIngress(systemNamespace, name.SafeConcatName(pd.Name, name.Hex(pd.Spec.DomainName, 5)), networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
ingress := constructors.NewIngress(systemNamespace, name.SafeConcatName(pd.Name, name.Hex(pd.Spec.DomainName, 5)), extensionsv1beta1.Ingress{
Spec: extensionsv1beta1.IngressSpec{
Rules: []extensionsv1beta1.IngressRule{
{
Host: pd.Spec.DomainName,
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionsv1beta1.IngressRuleValue{
HTTP: &extensionsv1beta1.HTTPIngressRuleValue{
Paths: []extensionsv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionsv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -113,7 +113,7 @@ func IngressForPublicDomain(systemNamespace string, pd *adminv1.PublicDomain, os
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionsv1beta1.IngressTLS{
{
Hosts: []string{pd.Spec.DomainName},
SecretName: pd.Spec.SecretRef.Name,
Expand Down
66 changes: 33 additions & 33 deletions modules/service/controllers/ingress/populate/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rancher/rio/pkg/constructors"
"github.com/rancher/wrangler/pkg/objectset"
v1 "k8s.io/api/core/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
extensionv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
Expand Down Expand Up @@ -40,16 +40,16 @@ func TestIngressWithVersion(t *testing.T) {
},
})

expected := constructors.NewIngress(systemNs, "foo-v0-default", networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
expected := constructors.NewIngress(systemNs, "foo-v0-default", extensionv1beta1.Ingress{
Spec: extensionv1beta1.IngressSpec{
Rules: []extensionv1beta1.IngressRule{
{
Host: "foo-v0-default.foo.on-rio.io",
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionv1beta1.IngressRuleValue{
HTTP: &extensionv1beta1.HTTPIngressRuleValue{
Paths: []extensionv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -59,7 +59,7 @@ func TestIngressWithVersion(t *testing.T) {
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionv1beta1.IngressTLS{
{
Hosts: []string{"*.foo.on-rio.io"},
SecretName: certName,
Expand Down Expand Up @@ -98,16 +98,16 @@ func TestIngressWithoutVersion(t *testing.T) {
},
})

expected := constructors.NewIngress(systemNs, "foo-default", networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
expected := constructors.NewIngress(systemNs, "foo-default", extensionv1beta1.Ingress{
Spec: extensionv1beta1.IngressSpec{
Rules: []extensionv1beta1.IngressRule{
{
Host: "foo-default.foo.on-rio.io",
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionv1beta1.IngressRuleValue{
HTTP: &extensionv1beta1.HTTPIngressRuleValue{
Paths: []extensionv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -117,7 +117,7 @@ func TestIngressWithoutVersion(t *testing.T) {
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionv1beta1.IngressTLS{
{
Hosts: []string{"*.foo.on-rio.io"},
SecretName: certName,
Expand All @@ -144,16 +144,16 @@ func TestRouterIngress(t *testing.T) {
},
})

expected := constructors.NewIngress(systemNs, "test-default", networkingv1beta1.Ingress{
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
expected := constructors.NewIngress(systemNs, "test-default", extensionv1beta1.Ingress{
Spec: extensionv1beta1.IngressSpec{
Rules: []extensionv1beta1.IngressRule{
{
Host: "test-default.foo.on-rio.io",
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionv1beta1.IngressRuleValue{
HTTP: &extensionv1beta1.HTTPIngressRuleValue{
Paths: []extensionv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -163,7 +163,7 @@ func TestRouterIngress(t *testing.T) {
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionv1beta1.IngressTLS{
{
Hosts: []string{"*.foo.on-rio.io"},
SecretName: certName,
Expand Down Expand Up @@ -194,21 +194,21 @@ func TestPublicDomainIngress(t *testing.T) {

systemNs := "rio-system-fake"
ingressName := "pd1-41cf6"
expected := constructors.NewIngress(systemNs, ingressName, networkingv1beta1.Ingress{
expected := constructors.NewIngress(systemNs, ingressName, extensionv1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"certmanager.k8s.io/cluster-issuer": "fake-issuer",
},
},
Spec: networkingv1beta1.IngressSpec{
Rules: []networkingv1beta1.IngressRule{
Spec: extensionv1beta1.IngressSpec{
Rules: []extensionv1beta1.IngressRule{
{
Host: "www.foo.com",
IngressRuleValue: networkingv1beta1.IngressRuleValue{
HTTP: &networkingv1beta1.HTTPIngressRuleValue{
Paths: []networkingv1beta1.HTTPIngressPath{
IngressRuleValue: extensionv1beta1.IngressRuleValue{
HTTP: &extensionv1beta1.HTTPIngressRuleValue{
Paths: []extensionv1beta1.HTTPIngressPath{
{
Backend: networkingv1beta1.IngressBackend{
Backend: extensionv1beta1.IngressBackend{
ServiceName: constants.GatewayName,
ServicePort: intstr.FromInt(80),
},
Expand All @@ -218,7 +218,7 @@ func TestPublicDomainIngress(t *testing.T) {
},
},
},
TLS: []networkingv1beta1.IngressTLS{
TLS: []extensionv1beta1.IngressTLS{
{
Hosts: []string{"www.foo.com"},
SecretName: "pd1-secret",
Expand Down
6 changes: 3 additions & 3 deletions pkg/constructors/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
tektonv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
)

Expand Down Expand Up @@ -114,8 +114,8 @@ func NewPersistentVolumeClaim(namespace, name string, obj v1.PersistentVolumeCla
return &obj
}

func NewIngress(namespace, name string, obj networkingv1beta1.Ingress) *networkingv1beta1.Ingress {
obj.APIVersion = "networking.k8s.io/v1beta1"
func NewIngress(namespace, name string, obj extensionsv1beta1.Ingress) *extensionsv1beta1.Ingress {
obj.APIVersion = "extensions/v1beta1"
obj.Kind = "Ingress"
obj.Name = name
obj.Namespace = namespace
Expand Down
1 change: 1 addition & 0 deletions scripts/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ rules:
verbs:
- "*"
- apiGroups:
- "extensions"
- "networking.k8s.io"
resources:
- "ingresses"
Expand Down
Loading

0 comments on commit 303f365

Please sign in to comment.