Skip to content

Commit

Permalink
Related to issue kubernetes-sigs#117
Browse files Browse the repository at this point in the history
  • Loading branch information
Varun1300211 committed Feb 13, 2024
1 parent 72d2753 commit ecccd24
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ require (
github.com/google/go-cmp v0.6.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
istio.io/api v1.20.0
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/cli-runtime v0.28.4
k8s.io/client-go v0.28.4
k8s.io/cli-runtime v0.24.2
k8s.io/client-go v0.28.3
k8s.io/utils v0.0.0-20231121161247-cf03d44ff3cf
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/gateway-api v1.0.0
)

require (
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
istio.io/api v1.20.0 // indirect
)

require (
Expand Down Expand Up @@ -56,21 +57,20 @@ require (
go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.31.0
gopkg.in/evanphx/json-patch.v5 v5.7.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
istio.io/client-go v1.19.0-alpha.1.0.20231130185426-9f1859c8ff42
k8s.io/klog/v2 v2.110.1 // indirect
istio.io/client-go v1.16.6
k8s.io/klog/v2 v2.110.1
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.15.0 // indirect
Expand Down
31 changes: 28 additions & 3 deletions pkg/i2gw/providers/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,50 @@ limitations under the License.
package common

import (
"context"
"fmt"
"regexp"

networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/kubernetes"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

var k8sClientset *kubernetes.Clientset

func GetDefaultIngressClass() (string, error) {
ingressClasses, err := k8sClientset.NetworkingV1().IngressClasses().List(context.Background(), metav1.ListOptions{})
if err != nil {
return "", err
}

for _, ic := range ingressClasses.Items {
if ic.Spec.Parameters != nil && ic.Spec.Parameters.APIGroup != nil {
if *ic.Spec.Parameters.APIGroup == "networking.k8s.io" && ic.Annotations["ingressclass.kubernetes.io/is-default-class"] == "true" {
return ic.Name, nil
}
}
}

return "", fmt.Errorf("no default IngressClass found")
}

func GetIngressClass(ingress networkingv1.Ingress) string {
var ingressClass string
ingressClass := ""

if ingress.Spec.IngressClassName != nil && *ingress.Spec.IngressClassName != "" {
ingressClass = *ingress.Spec.IngressClassName
} else if _, ok := ingress.Annotations[networkingv1beta1.AnnotationIngressClass]; ok {
ingressClass = ingress.Annotations[networkingv1beta1.AnnotationIngressClass]
} else {
ingressClass = ingress.Name
defaultIngressClass, err := GetDefaultIngressClass()
if err != nil {
return ""
}
ingressClass = defaultIngressClass
}

return ingressClass
Expand Down Expand Up @@ -81,7 +107,6 @@ func GetRuleGroups(ingresses []networkingv1.Ingress) map[string]IngressRuleGroup

ruleGroups[rgKey] = rg
}

}

return ruleGroups
Expand Down

0 comments on commit ecccd24

Please sign in to comment.