Skip to content

Commit

Permalink
feat(ocp): add optional flag to force platform as openshift (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo authored May 3, 2024
1 parent c1c350c commit 4a72b4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/manager/patches/force_openshift_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- op: add
path: /spec/template/spec/containers/0/args/-
value: --force-openshift
9 changes: 7 additions & 2 deletions internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
}

Expand Down

0 comments on commit 4a72b4c

Please sign in to comment.