Skip to content

Commit

Permalink
feat(ocp): add optional flag to force platform as openshift
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed May 3, 2024
1 parent d455719 commit 01565ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMG)
ifeq ($(BUNDLE_MODE), ocp)
cd config/manifests && $(KUSTOMIZE) edit add base ../openshift
cd config/manager && $(KUSTOMIZE) edit add patch \
--path patches/force_openshift_patch.yaml \
--group apps \
--version v1 \
--kind Deployment \
--name controller-manager \
--namespace system
endif
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(OPERATOR_SDK) bundle validate ./bundle
Expand Down
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 01565ca

Please sign in to comment.