Skip to content

Commit

Permalink
feat(runtime/k8s): only run Gateway API controllers if registered
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Dec 7, 2021
1 parent dc3cc3d commit ed2bd4a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/plugins/runtime/k8s/plugin_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
kube_ctrl "sigs.k8s.io/controller-runtime"
gatewayapi "sigs.k8s.io/gateway-api/apis/v1alpha2"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/core"
Expand All @@ -16,6 +18,20 @@ import (
gatewayapi_controllers "github.com/kumahq/kuma/pkg/plugins/runtime/k8s/controllers/gatewayapi"
)

func crdsPresent(mgr kube_ctrl.Manager) bool {
gk := schema.GroupKind{
Group: gatewayapi.SchemeGroupVersion.Group,
Kind: "Gateway",
}

mappings, _ := mgr.GetClient().RESTMapper().RESTMappings(
gk,
gatewayapi.SchemeGroupVersion.Version,
)

return len(mappings) > 0
}

func addGatewayReconciler(mgr kube_ctrl.Manager, rt core_runtime.Runtime, converter k8s_common.Converter) error {
// If we haven't registered our type, we're not reconciling gatewayapi
// objects.
Expand All @@ -26,6 +42,11 @@ func addGatewayReconciler(mgr kube_ctrl.Manager, rt core_runtime.Runtime, conver
}
}

if !crdsPresent(mgr) {
log.Info("Gateway API CRDs not registered")
return nil
}

cpURL := fmt.Sprintf("https://%s.%s:%d", rt.Config().Runtime.Kubernetes.ControlPlaneServiceName, rt.Config().Store.Kubernetes.SystemNamespace, rt.Config().DpServer.Port)

// TODO don't use injector config
Expand Down

0 comments on commit ed2bd4a

Please sign in to comment.