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

feat(ocp): add optional flag to force platform as openshift #810

Merged
merged 1 commit into from
May 3, 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
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
Loading