Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail soft when crds are not installed #153

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading