Skip to content

Commit

Permalink
fail soft when crds are not installed (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorLieberman authored Apr 15, 2024
1 parent 960a12a commit 15b873a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/i2gw/providers/istio/resource_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type reader struct {
Expand Down Expand Up @@ -126,6 +128,10 @@ func (r *reader) readGatewaysFromCluster(ctx context.Context) (map[types.Namespa

err := r.conf.Client.List(ctx, gatewayList)
if err != nil {
if client.IgnoreNotFound(err) == nil {
klog.Warningf("couldn't find %s CRD, it is likely not installed in the cluster", fmt.Sprintf("%s.%s", APIVersion, GatewayKind))
return map[types.NamespacedName]*istiov1beta1.Gateway{}, nil
}
return nil, fmt.Errorf("failed to list istio gateways: %w", err)
}

Expand All @@ -152,6 +158,10 @@ func (r *reader) readVirtualServicesFromCluster(ctx context.Context) (map[types.

err := r.conf.Client.List(ctx, virtualServicesList)
if err != nil {
if client.IgnoreNotFound(err) == nil {
klog.Warningf("couldn't find %s CRD, it is likely not installed in the cluster", fmt.Sprintf("%s.%s", APIVersion, VirtualServiceKind))
return map[types.NamespacedName]*istiov1beta1.VirtualService{}, nil
}
return nil, fmt.Errorf("failed to list istio virtual services: %w", err)
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/i2gw/providers/kong/resource_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

kongv1beta1 "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1beta1"
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
Expand Down Expand Up @@ -92,7 +94,11 @@ func (r *resourceReader) readTCPIngressesFromCluster(ctx context.Context) ([]kon

err := r.conf.Client.List(ctx, tcpIngressList)
if err != nil {
return nil, fmt.Errorf("failed to list Kong TCPIngresses: %w", err)
if client.IgnoreNotFound(err) == nil {
klog.Warningf("couldn't find %s CRD, it is likely not installed in the cluster", tcpIngressGVK.GroupKind().String())
return []kongv1beta1.TCPIngress{}, nil
}
return nil, fmt.Errorf("failed to list %s: %w", tcpIngressGVK.GroupKind().String(), err)
}

tcpIngresses := []kongv1beta1.TCPIngress{}
Expand Down

0 comments on commit 15b873a

Please sign in to comment.