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
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package backends
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package certs
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package general
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package info
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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, "")
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package logs
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue