Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to new networking.k8s.io/v1beta1 package #4127

Merged
merged 2 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func main() {
conf.FakeCertificate = ssl.GetFakeSSLCert(fs)
klog.Infof("Created fake certificate with PemFileName: %v", conf.FakeCertificate.PemFileName)

k8s.IsNetworkingIngressAvailable = k8s.NetworkingIngressAvailable(kubeClient)
if !k8s.IsNetworkingIngressAvailable {
klog.Warningf("Using deprecated \"k8s.io/api/extensions/v1beta1\" package because Kubernetes version is < v1.14.0")
}

conf.Client = kubeClient

reg := prometheus.NewRegistry()
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin/commands/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package backends

import (
"fmt"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin/commands/certs/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package certs

import (
"fmt"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
3 changes: 2 additions & 1 deletion cmd/plugin/commands/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package conf

import (
"fmt"
"github.com/spf13/cobra"
"strings"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"

"k8s.io/ingress-nginx/cmd/plugin/kubectl"
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin/commands/general/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package general

import (
"fmt"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin/commands/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package info

import (
"fmt"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/commands/ingresses/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package ingresses

import (
"fmt"
"github.com/spf13/cobra"
"os"
"text/tabwriter"

"k8s.io/api/extensions/v1beta1"
"github.com/spf13/cobra"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/cli-runtime/pkg/genericclioptions"

"k8s.io/ingress-nginx/cmd/plugin/request"
Expand Down Expand Up @@ -130,7 +130,7 @@ type ingressRow struct {
NumEndpoints string
}

func getIngressRows(ingresses *[]v1beta1.Ingress) []ingressRow {
func getIngressRows(ingresses *[]networking.Ingress) []ingressRow {
rows := make([]ingressRow, 0)

for _, ing := range *ingresses {
Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/commands/lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/spf13/cobra"

appsv1 "k8s.io/api/apps/v1"

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

"k8s.io/ingress-nginx/cmd/plugin/lints"
"k8s.io/ingress-nginx/cmd/plugin/request"
"k8s.io/ingress-nginx/cmd/plugin/util"
Expand Down Expand Up @@ -178,7 +178,7 @@ func checkObjectArray(lints []lint, objects []kmeta.Object, opts lintOptions) {
}

func ingresses(opts lintOptions) error {
var ings []v1beta1.Ingress
var ings []networking.Ingress
var err error
if opts.allNamespaces {
ings, err = request.GetIngressDefinitions(opts.flags, "")
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin/commands/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package logs

import (
"fmt"

"github.com/spf13/cobra"

"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
5 changes: 3 additions & 2 deletions cmd/plugin/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"bytes"
"fmt"
"io"
apiv1 "k8s.io/api/core/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"os"
"os/exec"
"strings"
"syscall"

apiv1 "k8s.io/api/core/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
)

// PodExecString takes a pod and a command, uses kubectl exec to run the command in the pod
Expand Down
16 changes: 8 additions & 8 deletions cmd/plugin/lints/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"strings"

"k8s.io/api/extensions/v1beta1"
networking "k8s.io/api/networking/v1beta1"
kmeta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/ingress-nginx/cmd/plugin/util"
)
Expand All @@ -30,12 +30,12 @@ type IngressLint struct {
message string
issue int
version string
f func(ing v1beta1.Ingress) bool
f func(ing networking.Ingress) bool
}

// Check returns true if the lint detects an issue
func (lint IngressLint) Check(obj kmeta.Object) bool {
ing := obj.(*v1beta1.Ingress)
ing := obj.(*networking.Ingress)
return lint.f(*ing)
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func GetIngressLints() []IngressLint {
}
}

func xForwardedPrefixIsBool(ing v1beta1.Ingress) bool {
func xForwardedPrefixIsBool(ing networking.Ingress) bool {
for name, val := range ing.Annotations {
if strings.HasSuffix(name, "/x-forwarded-prefix") && (val == "true" || val == "false") {
return true
Expand All @@ -96,7 +96,7 @@ func xForwardedPrefixIsBool(ing v1beta1.Ingress) bool {
return false
}

func annotationPrefixIsNginxCom(ing v1beta1.Ingress) bool {
func annotationPrefixIsNginxCom(ing networking.Ingress) bool {
for name := range ing.Annotations {
if strings.HasPrefix(name, "nginx.com/") {
return true
Expand All @@ -105,7 +105,7 @@ func annotationPrefixIsNginxCom(ing v1beta1.Ingress) bool {
return false
}

func annotationPrefixIsNginxOrg(ing v1beta1.Ingress) bool {
func annotationPrefixIsNginxOrg(ing networking.Ingress) bool {
for name := range ing.Annotations {
if strings.HasPrefix(name, "nginx.org/") {
return true
Expand All @@ -114,7 +114,7 @@ func annotationPrefixIsNginxOrg(ing v1beta1.Ingress) bool {
return false
}

func rewriteTargetWithoutCaptureGroup(ing v1beta1.Ingress) bool {
func rewriteTargetWithoutCaptureGroup(ing networking.Ingress) bool {
for name, val := range ing.Annotations {
if strings.HasSuffix(name, "/rewrite-target") && !strings.Contains(val, "$1") {
return true
Expand All @@ -128,7 +128,7 @@ func removedAnnotation(annotationName string, issueNumber int, version string) I
message: fmt.Sprintf("Contains the removed %v annotation.", annotationName),
issue: issueNumber,
version: version,
f: func(ing v1beta1.Ingress) bool {
f: func(ing networking.Ingress) bool {
for annotation := range ing.Annotations {
if strings.HasSuffix(annotation, "/"+annotationName) {
return true
Expand Down
15 changes: 8 additions & 7 deletions cmd/plugin/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import (

appsv1 "k8s.io/api/apps/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
networking "k8s.io/api/networking/v1beta1"
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"
extensions "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
typednetworking "k8s.io/client-go/kubernetes/typed/networking/v1beta1"

"k8s.io/ingress-nginx/cmd/plugin/util"
)

Expand Down Expand Up @@ -90,20 +91,20 @@ func GetDeployments(flags *genericclioptions.ConfigFlags, namespace string) ([]a
}

// GetIngressDefinitions returns an array of Ingress resource definitions
func GetIngressDefinitions(flags *genericclioptions.ConfigFlags, namespace string) ([]v1beta1.Ingress, error) {
func GetIngressDefinitions(flags *genericclioptions.ConfigFlags, namespace string) ([]networking.Ingress, error) {
rawConfig, err := flags.ToRESTConfig()
if err != nil {
return make([]v1beta1.Ingress, 0), err
return make([]networking.Ingress, 0), err
}

api, err := extensions.NewForConfig(rawConfig)
api, err := typednetworking.NewForConfig(rawConfig)
if err != nil {
return make([]v1beta1.Ingress, 0), err
return make([]networking.Ingress, 0), err
}

pods, err := api.Ingresses(namespace).List(metav1.ListOptions{})
if err != nil {
return make([]v1beta1.Ingress, 0), err
return make([]networking.Ingress, 0), err
}

return pods.Items, nil
Expand Down
24 changes: 19 additions & 5 deletions deploy/cluster-wide/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ rules:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- "extensions"
resources:
Expand All @@ -37,14 +44,21 @@ rules:
- list
- watch
- apiGroups:
- ""
- "extensions"
resources:
- events
- ingresses/status
verbs:
- create
- patch
- update
- apiGroups:
- "extensions"
- "networking.k8s.io"
resources:
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- "networking.k8s.io"
resources:
- ingresses/status
verbs:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/auth/external-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
name: external-auth
namespace: default
resourceVersion: "2068378"
selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/external-auth
selfLink: /apis/networking/v1beta1/namespaces/default/ingresses/external-auth
uid: 5c388f1d-8970-11e6-9004-080027d2dc94
spec:
rules:
Expand Down
6 changes: 3 additions & 3 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Rules:
/tea tea-svc:80 (<none>)
/coffee coffee-svc:80 (<none>)
Annotations:
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"cafe-ingress","namespace":"default","selfLink":"/apis/extensions/v1beta1/namespaces/default/ingresses/cafe-ingress"},"spec":{"rules":[{"host":"cafe.com","http":{"paths":[{"backend":{"serviceName":"tea-svc","servicePort":80},"path":"/tea"},{"backend":{"serviceName":"coffee-svc","servicePort":80},"path":"/coffee"}]}}]},"status":{"loadBalancer":{"ingress":[{"ip":"169.48.142.110"}]}}}
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"cafe-ingress","namespace":"default","selfLink":"/apis/networking/v1beta1/namespaces/default/ingresses/cafe-ingress"},"spec":{"rules":[{"host":"cafe.com","http":{"paths":[{"backend":{"serviceName":"tea-svc","servicePort":80},"path":"/tea"},{"backend":{"serviceName":"coffee-svc","servicePort":80},"path":"/coffee"}]}}]},"status":{"loadBalancer":{"ingress":[{"ip":"169.48.142.110"}]}}}

Events:
Type Reason Age From Message
Expand Down Expand Up @@ -218,8 +218,8 @@ $ kubectl exec test-701078429-s5kca -- curl --cacert /var/run/secrets/kubernetes
"/apis/batch/v2alpha1",
"/apis/certificates.k8s.io",
"/apis/certificates.k8s.io/v1alpha1",
"/apis/extensions",
"/apis/extensions/v1beta1",
"/apis/networking",
"/apis/networking/v1beta1",
"/apis/policy",
"/apis/policy/v1alpha1",
"/apis/rbac.authorization.k8s.io",
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200j
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -246,7 +245,6 @@ github.com/zakjan/cert-chain-resolver v0.0.0-20180703112424-6076e1ded272 h1:scDk
github.com/zakjan/cert-chain-resolver v0.0.0-20180703112424-6076e1ded272/go.mod h1:KNkcm66cr4ilOiEcjydK+tc2ShPUhqmuoXCljXUBPu8=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A=
go.opencensus.io v0.19.2 h1:ZZpq6xI6kv/LuE/5s5UQvBU5vMjvRnPb8PvJrIntAnc=
go.opencensus.io v0.19.2/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2 h1:NAfh7zF0/3/HqtMvJNZ/RFrSlCE6ZTlHmKfhL/Dm1Jk=
Expand Down Expand Up @@ -308,7 +306,6 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313 h1:pczuHS43Cp2ktBEEmLwScxgjWsBSzdaQiKzUyf3DTTc=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -336,7 +333,6 @@ google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.2.0/go.mod h1:IfRCZScioGtypHNTlz3gFk67J8uePVW7uDTBzXuIkhU=
google.golang.org/api v0.3.0 h1:UIJY20OEo3+tK5MBlcdx37kmdH6EnRjGkW78mc6+EeA=
google.golang.org/api v0.3.0/go.mod h1:IuvZyQh8jgscv8qWfQ4ABd8m7hEudgBFM/EdhA3BnXw=
google.golang.org/api v0.3.1 h1:oJra/lMfmtm13/rgY/8i3MzjFWYXvQIAKjQ3HqofMk8=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
Expand All @@ -354,7 +350,6 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.19.1 h1:TrBcJ1yqAl1G++wO39nD/qtgpsW9/1+QGrluyMGEYgM=
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
10 changes: 5 additions & 5 deletions internal/admission/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package controller
import (
"github.com/google/uuid"
"k8s.io/api/admission/v1beta1"
extensions "k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
networking "k8s.io/api/networking/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
"k8s.io/klog"
Expand All @@ -29,7 +29,7 @@ import (
// Checker must return an error if the ingress provided as argument
// contains invalid instructions
type Checker interface {
CheckIngress(ing *extensions.Ingress) error
CheckIngress(ing *networking.Ingress) error
}

// IngressAdmission implements the AdmissionController interface
Expand All @@ -52,14 +52,14 @@ func (ia *IngressAdmission) HandleAdmission(ar *v1beta1.AdmissionReview) error {
}
klog.V(3).Infof("handling ingress admission webhook request for {%s} %s in namespace %s", ar.Request.Resource.String(), ar.Request.Name, ar.Request.Namespace)

ingressResource := v1.GroupVersionResource{Group: extensions.SchemeGroupVersion.Group, Version: extensions.SchemeGroupVersion.Version, Resource: "ingresses"}
ingressResource := v1.GroupVersionResource{Group: networking.SchemeGroupVersion.Group, Version: networking.SchemeGroupVersion.Version, Resource: "ingresses"}

if ar.Request.Resource == ingressResource {
ar.Response = &v1beta1.AdmissionResponse{
UID: types.UID(uuid.New().String()),
Allowed: false,
}
ingress := extensions.Ingress{}
ingress := networking.Ingress{}
deserializer := codecs.UniversalDeserializer()
if _, _, err := deserializer.Decode(ar.Request.Object.Raw, nil, &ingress); err != nil {
ar.Response.Result = &v1.Status{Message: err.Error()}
Expand Down
Loading