From 4a72b4cb25a24de390ad7098eeafa3437e851f6e Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Fri, 3 May 2024 15:45:12 -0400 Subject: [PATCH] feat(ocp): add optional flag to force platform as openshift (#810) --- config/manager/kustomization.yaml | 9 +++++++++ config/manager/patches/force_openshift_patch.yaml | 3 +++ internal/main.go | 9 +++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 config/manager/patches/force_openshift_patch.yaml diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 55c8015cb..1f89c6724 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -14,3 +14,12 @@ images: - name: controller newName: quay.io/cryostat/cryostat-operator newTag: 3.0.0-dev + +# patchesJson6902: +# - path: patches/force_openshift_patch.yaml +# target: +# group: apps +# kind: Deployment +# name: controller-manager +# namespace: system +# version: v1 diff --git a/config/manager/patches/force_openshift_patch.yaml b/config/manager/patches/force_openshift_patch.yaml new file mode 100644 index 000000000..c3d152ed6 --- /dev/null +++ b/config/manager/patches/force_openshift_patch.yaml @@ -0,0 +1,3 @@ +- op: add + path: /spec/template/spec/containers/0/args/- + value: --force-openshift diff --git a/internal/main.go b/internal/main.go index 51a746763..272f0a6b4 100644 --- a/internal/main.go +++ b/internal/main.go @@ -75,6 +75,7 @@ func main() { var probeAddr string var secureMetrics bool var enableHTTP2 bool + var forceOpenShift bool flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") flag.BoolVar(&enableLeaderElection, "leader-elect", false, @@ -83,6 +84,7 @@ func main() { flag.BoolVar(&secureMetrics, "metrics-secure", false, "If set the metrics endpoint is served securely") flag.BoolVar(&enableHTTP2, "enable-http2", false, "If HTTP/2 should be enabled for the metrics and webhook servers.") + flag.BoolVar(&forceOpenShift, "force-openshift", false, "Force the controller to consider current platform as OpenShift") opts := zap.Options{ Development: true, } @@ -138,7 +140,7 @@ func main() { os.Exit(1) } - openShift, err := isOpenShift(dc) + openShift, err := isOpenShift(dc, forceOpenShift) if err != nil { setupLog.Error(err, "could not determine whether manager is running on OpenShift") os.Exit(1) @@ -205,7 +207,10 @@ func main() { } } -func isOpenShift(client discovery.DiscoveryInterface) (bool, error) { +func isOpenShift(client discovery.DiscoveryInterface, forceOpenShift bool) (bool, error) { + if forceOpenShift { + return true, nil + } return discovery.IsResourceEnabled(client, routev1.GroupVersion.WithResource("routes")) }