Change Ingress version from v1beta1 to v1 for K8s 1.22+ compatibility (#2124)
* Change Ingress version from v1beta1 to v1 for K8s 1.22+ compatibility Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Minor fix Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -43,7 +43,7 @@ func createIngress(logger *zap.Logger, trigger *fv1.HTTPTrigger, kubeClient *kub
|
||||
if !trigger.Spec.CreateIngress {
|
||||
return
|
||||
}
|
||||
_, err := kubeClient.ExtensionsV1beta1().Ingresses(podNamespace).Create(context.TODO(), util.GetIngressSpec(podNamespace, trigger), v1.CreateOptions{})
|
||||
_, err := kubeClient.NetworkingV1().Ingresses(podNamespace).Create(context.TODO(), util.GetIngressSpec(podNamespace, trigger), v1.CreateOptions{})
|
||||
if err != nil && !k8serrors.IsAlreadyExists(err) {
|
||||
logger.Error("failed to create ingress", zap.Error(err))
|
||||
return
|
||||
@@ -56,13 +56,13 @@ func deleteIngress(logger *zap.Logger, trigger *fv1.HTTPTrigger, kubeClient *kub
|
||||
return
|
||||
}
|
||||
|
||||
ingress, err := kubeClient.ExtensionsV1beta1().Ingresses(podNamespace).Get(context.TODO(), trigger.ObjectMeta.Name, v1.GetOptions{})
|
||||
ingress, err := kubeClient.NetworkingV1().Ingresses(podNamespace).Get(context.TODO(), trigger.ObjectMeta.Name, v1.GetOptions{})
|
||||
if err != nil && !k8serrors.IsNotFound(err) {
|
||||
logger.Error("failed to get ingress when deleting trigger", zap.Error(err), zap.String("trigger", trigger.ObjectMeta.Name))
|
||||
return
|
||||
}
|
||||
|
||||
err = kubeClient.ExtensionsV1beta1().Ingresses(podNamespace).Delete(context.TODO(), ingress.Name, v1.DeleteOptions{})
|
||||
err = kubeClient.NetworkingV1().Ingresses(podNamespace).Delete(context.TODO(), ingress.Name, v1.DeleteOptions{})
|
||||
if err != nil && !k8serrors.IsNotFound(err) {
|
||||
logger.Error("failed to delete ingress for trigger",
|
||||
zap.Error(err),
|
||||
@@ -86,7 +86,7 @@ func updateIngress(logger *zap.Logger, oldT *fv1.HTTPTrigger, newT *fv1.HTTPTrig
|
||||
return
|
||||
}
|
||||
|
||||
oldIngress, err := kubeClient.ExtensionsV1beta1().Ingresses(podNamespace).Get(context.TODO(), oldT.ObjectMeta.Name, v1.GetOptions{})
|
||||
oldIngress, err := kubeClient.NetworkingV1().Ingresses(podNamespace).Get(context.TODO(), oldT.ObjectMeta.Name, v1.GetOptions{})
|
||||
if err != nil {
|
||||
if k8serrors.IsNotFound(err) {
|
||||
createIngress(logger, newT, kubeClient)
|
||||
@@ -123,7 +123,7 @@ func updateIngress(logger *zap.Logger, oldT *fv1.HTTPTrigger, newT *fv1.HTTPTrig
|
||||
}
|
||||
|
||||
if changes {
|
||||
_, err = kubeClient.ExtensionsV1beta1().Ingresses(podNamespace).Update(context.TODO(), oldIngress, v1.UpdateOptions{})
|
||||
_, err = kubeClient.NetworkingV1().Ingresses(podNamespace).Update(context.TODO(), oldIngress, v1.UpdateOptions{})
|
||||
if err != nil {
|
||||
logger.Error("failed to update ingress for trigger", zap.Error(err), zap.String("trigger", oldT.ObjectMeta.Name))
|
||||
return
|
||||
|
||||
+17
-16
@@ -17,14 +17,14 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
v1 "k8s.io/api/networking/v1"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
)
|
||||
|
||||
func GetIngressSpec(namespace string, trigger *fv1.HTTPTrigger) *v1beta1.Ingress {
|
||||
func GetIngressSpec(namespace string, trigger *fv1.HTTPTrigger) *v1.Ingress {
|
||||
// TODO: remove backward compatibility
|
||||
host, path := trigger.Spec.Host, trigger.Spec.RelativeURL
|
||||
if trigger.Spec.Prefix != nil && *trigger.Spec.Prefix != "" {
|
||||
@@ -41,9 +41,9 @@ func GetIngressSpec(namespace string, trigger *fv1.HTTPTrigger) *v1beta1.Ingress
|
||||
host = "" // wildcard Ingress host
|
||||
}
|
||||
|
||||
var ingTLS []v1beta1.IngressTLS
|
||||
var ingTLS []v1.IngressTLS
|
||||
if len(trigger.Spec.IngressConfig.TLS) > 0 {
|
||||
ingTLS = []v1beta1.IngressTLS{
|
||||
ingTLS = []v1.IngressTLS{
|
||||
{
|
||||
Hosts: []string{
|
||||
trigger.Spec.IngressConfig.Host,
|
||||
@@ -53,7 +53,7 @@ func GetIngressSpec(namespace string, trigger *fv1.HTTPTrigger) *v1beta1.Ingress
|
||||
}
|
||||
}
|
||||
|
||||
ing := &v1beta1.Ingress{
|
||||
ing := &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: GetDeployLabels(trigger),
|
||||
Name: trigger.ObjectMeta.Name,
|
||||
@@ -63,20 +63,21 @@ func GetIngressSpec(namespace string, trigger *fv1.HTTPTrigger) *v1beta1.Ingress
|
||||
Namespace: namespace,
|
||||
Annotations: trigger.Spec.IngressConfig.Annotations,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Spec: v1.IngressSpec{
|
||||
TLS: ingTLS,
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: host,
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: path,
|
||||
|
||||
@@ -20,9 +20,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
v1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
)
|
||||
@@ -35,7 +34,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *v1beta1.Ingress
|
||||
want *v1.Ingress
|
||||
}{
|
||||
{
|
||||
name: "host-backward-compatibility",
|
||||
@@ -58,7 +57,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -69,19 +68,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
Namespace: "foobarNS",
|
||||
Annotations: nil,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "test.com",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/bar",
|
||||
@@ -116,7 +116,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -129,19 +129,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
"key": "value",
|
||||
},
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/bar",
|
||||
@@ -176,7 +177,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -187,19 +188,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
Namespace: "foobarNS",
|
||||
Annotations: nil,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "test.com",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/bar",
|
||||
@@ -234,7 +236,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -245,19 +247,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
Namespace: "foobarNS",
|
||||
Annotations: nil,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/{bar}",
|
||||
@@ -292,7 +295,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -303,19 +306,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
Namespace: "foobarNS",
|
||||
Annotations: nil,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/{bar}",
|
||||
@@ -351,7 +355,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -362,19 +366,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
Namespace: "foobarNS",
|
||||
Annotations: nil,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "test.com",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/bar",
|
||||
@@ -409,7 +414,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -420,19 +425,20 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
Namespace: "foobarNS",
|
||||
Annotations: nil,
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Spec: v1.IngressSpec{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/bar",
|
||||
@@ -469,7 +475,7 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &v1beta1.Ingress{
|
||||
want: &v1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"triggerName": "foo",
|
||||
@@ -482,8 +488,8 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
"key": "value",
|
||||
},
|
||||
},
|
||||
Spec: v1beta1.IngressSpec{
|
||||
TLS: []v1beta1.IngressTLS{
|
||||
Spec: v1.IngressSpec{
|
||||
TLS: []v1.IngressTLS{
|
||||
{
|
||||
Hosts: []string{
|
||||
"test.com",
|
||||
@@ -491,18 +497,19 @@ func TestGetIngressSpec(t *testing.T) {
|
||||
SecretName: "foobar",
|
||||
},
|
||||
},
|
||||
Rules: []v1beta1.IngressRule{
|
||||
Rules: []v1.IngressRule{
|
||||
{
|
||||
Host: "",
|
||||
IngressRuleValue: v1beta1.IngressRuleValue{
|
||||
HTTP: &v1beta1.HTTPIngressRuleValue{
|
||||
Paths: []v1beta1.HTTPIngressPath{
|
||||
IngressRuleValue: v1.IngressRuleValue{
|
||||
HTTP: &v1.HTTPIngressRuleValue{
|
||||
Paths: []v1.HTTPIngressPath{
|
||||
{
|
||||
Backend: v1beta1.IngressBackend{
|
||||
ServiceName: "router",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Backend: v1.IngressBackend{
|
||||
Service: &v1.IngressServiceBackend{
|
||||
Name: "router",
|
||||
Port: v1.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
Path: "/foo/bar",
|
||||
|
||||
Reference in New Issue
Block a user