Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added function getIngressClass which set default or nginx ingress class to jaeger define ingress for providing loadbalancer IP.

Signed-off-by: Gaurav Singh <gauravsinghbr@hotmail.com>
  • Loading branch information
Gaurav Singh committed Feb 12, 2024
1 parent d12b812 commit b47a81e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ rules:
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
- ingresses
verbs:
- create
Expand Down
2 changes: 1 addition & 1 deletion controllers/jaegertracing/jaeger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewReconciler(client client.Client, clientReader client.Reader, scheme *run
// +kubebuilder:rbac:groups=apps,resources=deployments;daemonsets;replicasets;statefulsets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=extensions,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=autoscaling,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses;ingressclasses,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=console.openshift.io,resources=consolelinks,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=batch,resources=jobs;cronjobs,verbs=get;list;watch;create;update;patch;delete
Expand Down
45 changes: 45 additions & 0 deletions pkg/ingress/query.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ingress

import (
"context"
"fmt"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -52,6 +56,11 @@ func (i *QueryIngress) Get() *networkingv1.Ingress {

if i.jaeger.Spec.Ingress.IngressClassName != nil {
spec.IngressClassName = i.jaeger.Spec.Ingress.IngressClassName
} else {
ingressClass, err := getIngressClass()
if !err {
spec.IngressClassName = &ingressClass
}
}

return &networkingv1.Ingress{
Expand Down Expand Up @@ -150,3 +159,39 @@ func getRule(host string, path string, pathType *networkingv1.PathType, backend
}
return rule
}

func getIngressClass() (string, bool) {
ingressClass := ""
nginxIngressAvailable := false
config, err := rest.InClusterConfig()
if err != nil {
return "", true
}
clientSet, err := kubernetes.NewForConfig(config)
if err != nil {
return "", true
}
ingressList, err := clientSet.NetworkingV1().IngressClasses().List(context.Background(), metav1.ListOptions{})
if err != nil {
return "", true
}
for _, ingress := range ingressList.Items {
if ingress.Name == "nginx" {
nginxIngressAvailable = true
}
for k, v := range ingress.Annotations {
if k == "ingressclass.kubernetes.io/is-default-class" {
if v == "true" {
ingressClass = ingress.Name
break
}
}
}
}
if len(ingressClass) > 0 {
return ingressClass, false
} else if nginxIngressAvailable {
return "nginx", false
}
return "", true
}

0 comments on commit b47a81e

Please sign in to comment.