Skip to content

Commit

Permalink
Drop v1beta1 from ingress nginx (kubernetes#7156)
Browse files Browse the repository at this point in the history
* Drop v1beta1 from ingress nginx

Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>

* Fix intorstr logic in controller

Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>

* fixing admission

Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>

* more intorstr fixing

* correct template rendering

Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>

* Fix e2e tests for v1 api

Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>

* Fix gofmt errors

* This is finally working...almost there...

Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>

* Re-add removed validation of AdmissionReview
  • Loading branch information
rikatz committed Aug 21, 2021
1 parent f3c5069 commit f979cfb
Show file tree
Hide file tree
Showing 157 changed files with 1,051 additions and 872 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,16 @@ jobs:
id: kind
uses: engineerd/setup-kind@v0.5.0
with:
<<<<<<< HEAD
version: v0.11.1
image: kindest/node:v1.20.2
||||||| parent of 78afe7e38 (Drop v1beta1 from ingress nginx (#7156))
version: v0.10.0
image: kindest/node:v1.20.2
=======
version: v0.11.1
image: kindest/node:v1.21.1
>>>>>>> 78afe7e38 (Drop v1beta1 from ingress nginx (#7156))

- name: Test
env:
Expand All @@ -159,7 +167,13 @@ jobs:
strategy:
matrix:
<<<<<<< HEAD
k8s: [v1.16.15, v1.17.17, v1.18.19, v1.19.11, v1.20.7, v1.21.2]
||||||| parent of 78afe7e38 (Drop v1beta1 from ingress nginx (#7156))
k8s: [v1.16.15, v1.17.17, v1.18.15, v1.19.7, v1.20.2]
=======
k8s: [v1.19.11, v1.20.7, v1.21.1]
>>>>>>> 78afe7e38 (Drop v1beta1 from ingress nginx (#7156))

steps:

Expand Down
2 changes: 1 addition & 1 deletion charts/ingress-nginx/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Get the application URL by running these commands:

An example Ingress that makes use of the controller:

apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -28,12 +28,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: {{ .Release.Namespace | quote }}
name: {{ include "ingress-nginx.controller.fullname" . }}-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
{{- if .Values.controller.admissionWebhooks.timeoutSeconds }}
timeoutSeconds: {{ .Values.controller.admissionWebhooks.timeoutSeconds }}
{{- end }}
Expand Down
41 changes: 17 additions & 24 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,36 +104,29 @@ func main() {
conf.FakeCertificate = ssl.GetFakeSSLCert()
klog.InfoS("SSL fake certificate created", "file", conf.FakeCertificate.PemFileName)

var isNetworkingIngressAvailable bool

isNetworkingIngressAvailable, k8s.IsIngressV1Beta1Ready, _ = k8s.NetworkingIngressAvailable(kubeClient)
if !isNetworkingIngressAvailable {
klog.Fatalf("ingress-nginx requires Kubernetes v1.14.0 or higher")
if !k8s.NetworkingIngressAvailable(kubeClient) {
klog.Fatalf("ingress-nginx requires Kubernetes v1.19.0 or higher")
}

if k8s.IsIngressV1Beta1Ready {
klog.InfoS("Enabling new Ingress features available since Kubernetes v1.18")
k8s.IngressClass, err = kubeClient.NetworkingV1beta1().IngressClasses().
Get(context.TODO(), class.IngressClass, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
if !errors.IsUnauthorized(err) && !errors.IsForbidden(err) {
klog.Fatalf("Error searching IngressClass: %v", err)
}

klog.ErrorS(err, "Searching IngressClass", "class", class.IngressClass)
k8s.IngressClass, err = kubeClient.NetworkingV1().IngressClasses().
Get(context.TODO(), class.IngressClass, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
if !errors.IsUnauthorized(err) && !errors.IsForbidden(err) {
klog.Fatalf("Error searching IngressClass: %v", err)
}
klog.ErrorS(err, "Searching IngressClass", "class", class.IngressClass)
}

klog.Warningf("No IngressClass resource with name %v found. Only annotation will be used.", class.IngressClass)
klog.Warningf("No IngressClass resource with name %v found. Only annotation will be used.", class.IngressClass)
// TODO: remove once this is fixed in client-go
k8s.IngressClass = nil

// TODO: remove once this is fixed in client-go
k8s.IngressClass = nil
}
}

if k8s.IngressClass != nil && k8s.IngressClass.Spec.Controller != k8s.IngressNGINXController {
klog.Errorf(`Invalid IngressClass (Spec.Controller) value "%v". Should be "%v"`, k8s.IngressClass.Spec.Controller, k8s.IngressNGINXController)
klog.Fatalf("IngressClass with name %v is not valid for ingress-nginx (invalid Spec.Controller)", class.IngressClass)
}
if k8s.IngressClass != nil && k8s.IngressClass.Spec.Controller != k8s.IngressNGINXController {
klog.Errorf(`Invalid IngressClass (Spec.Controller) value "%v". Should be "%v"`, k8s.IngressClass.Spec.Controller, k8s.IngressNGINXController)
klog.Fatalf("IngressClass with name %v is not valid for ingress-nginx (invalid Spec.Controller)", class.IngressClass)
}

conf.Client = kubeClient
Expand Down
29 changes: 23 additions & 6 deletions cmd/plugin/commands/ingresses/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
"text/tabwriter"

"github.com/spf13/cobra"
networking "k8s.io/api/networking/v1beta1"
networking "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/cli-runtime/pkg/genericclioptions"

"k8s.io/ingress-nginx/cmd/plugin/request"
Expand Down Expand Up @@ -157,9 +158,10 @@ func getIngressRows(ingresses *[]networking.Ingress) []ingressRow {

defaultBackendService := ""
defaultBackendPort := ""
if ing.Spec.Backend != nil {
defaultBackendService = ing.Spec.Backend.ServiceName
defaultBackendPort = ing.Spec.Backend.ServicePort.String()
if ing.Spec.DefaultBackend != nil {
name, port := serviceToNameAndPort(ing.Spec.DefaultBackend.Service)
defaultBackendService = name
defaultBackendPort = port.String()
}

// Handle catch-all ingress
Expand Down Expand Up @@ -197,14 +199,15 @@ func getIngressRows(ingresses *[]networking.Ingress) []ingressRow {
}

for _, path := range rule.HTTP.Paths {
svcName, svcPort := serviceToNameAndPort(path.Backend.Service)
row := ingressRow{
Namespace: ing.Namespace,
IngressName: ing.Name,
Host: rule.Host,
Path: path.Path,
TLS: hasTLS,
ServiceName: path.Backend.ServiceName,
ServicePort: path.Backend.ServicePort.String(),
ServiceName: svcName,
ServicePort: svcPort.String(),
Address: address,
}

Expand All @@ -215,3 +218,17 @@ func getIngressRows(ingresses *[]networking.Ingress) []ingressRow {

return rows
}

func serviceToNameAndPort(svc *networking.IngressServiceBackend) (string, intstr.IntOrString) {
var svcName string
if svc != nil {
svcName = svc.Name
if svc.Port.Number > 0 {
return svcName, intstr.FromInt(int(svc.Port.Number))
}
if svc.Port.Name != "" {
return svcName, intstr.FromString(svc.Port.String())
}
}
return "", intstr.IntOrString{}
}
2 changes: 1 addition & 1 deletion cmd/plugin/commands/lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"

appsv1 "k8s.io/api/apps/v1"
networking "k8s.io/api/networking/v1beta1"
networking "k8s.io/api/networking/v1"
kmeta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"

Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/lints/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"strings"

networking "k8s.io/api/networking/v1beta1"
networking "k8s.io/api/networking/v1"
kmeta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/ingress-nginx/cmd/plugin/util"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/plugin/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (

appsv1 "k8s.io/api/apps/v1"
apiv1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1beta1"
networking "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
typednetworking "k8s.io/client-go/kubernetes/typed/networking/v1beta1"
typednetworking "k8s.io/client-go/kubernetes/typed/networking/v1"

"k8s.io/ingress-nginx/cmd/plugin/util"
)
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/aws/deploy-tls-termination.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -450,12 +450,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/aws/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -437,12 +437,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/baremetal/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -432,12 +432,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/cloud/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -434,12 +434,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/do/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -436,12 +436,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/exoscale/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -442,12 +442,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/kind/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -444,12 +444,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
5 changes: 2 additions & 3 deletions deploy/static/provider/scw/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ webhooks:
- apiGroups:
- networking.k8s.io
apiVersions:
- v1beta1
- v1
operations:
- CREATE
- UPDATE
Expand All @@ -436,12 +436,11 @@ webhooks:
sideEffects: None
admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /networking/v1beta1/ingresses
path: /networking/v1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
Expand Down
Loading

0 comments on commit f979cfb

Please sign in to comment.