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

Added capability of detecting the platform #217

Merged
merged 2 commits into from
Feb 22, 2019
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
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ e2e-tests: cassandra es crd build docker push
run: crd
@bash -c 'trap "exit 0" INT; OPERATOR_NAME=${OPERATOR_NAME} KUBERNETES_CONFIG=${KUBERNETES_CONFIG} WATCH_NAMESPACE=${WATCH_NAMESPACE} go run -ldflags ${LD_FLAGS} main.go start'

.PHONY: run-openshift
run-openshift: crd
@bash -c 'trap "exit 0" INT; OPERATOR_NAME=${OPERATOR_NAME} KUBERNETES_CONFIG=${KUBERNETES_CONFIG} WATCH_NAMESPACE=${WATCH_NAMESPACE} go run -ldflags ${LD_FLAGS} main.go start --platform=openshift'

.PHONY: es
es:
@kubectl create -f ./test/elasticsearch.yml 2>&1 | grep -v "already exists" || true
Expand Down
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The operator is now ready to create Jaeger instances!

=== OpenShift

The instructions from the previous section also work on OpenShift given that the `operator-openshift.yaml` is used instead of `operator.yaml`. Make sure to install the RBAC rules, the CRD and the operator as a privileged user, such as `system:admin`.
The instructions from the previous section also work on OpenShift. Make sure to install the RBAC rules, the CRD and the operator as a privileged user, such as `system:admin`.
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved

[source,bash]
----
Expand All @@ -55,7 +55,7 @@ oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/mas
oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/service_account.yaml
oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/role.yaml
oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/role_binding.yaml
oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/operator-openshift.yaml
oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/operator.yaml
----
<1> This creates the namespace used by default in the deployment files.

Expand Down Expand Up @@ -252,7 +252,7 @@ NAME HOSTS ADDRESS PORTS AGE
simplest-query * 192.168.122.34 80 3m
----

IMPORTANT: an `Ingress` object is *not* created when the operator is started with the `--platform=openshift` flag, such as when using the resource `operator-openshift.yaml`.
IMPORTANT: an `Ingress` object is *not* created when the operator is running on OpenShift

In this example, the Jaeger UI is available at http://192.168.122.34

Expand Down
33 changes: 0 additions & 33 deletions deploy/operator-openshift.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions pkg/apis/io/v1alpha1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const (
// FlagPlatformOpenShift represents the value for the 'platform' flag for OpenShift
FlagPlatformOpenShift = "openshift"

// FlagPlatformAutoDetect represents the "auto-detect" value for the platform flag
FlagPlatformAutoDetect = "auto-detect"

// IngressSecurityNone disables any form of security for ingress objects (default)
IngressSecurityNone IngressSecurityType = ""

Expand Down
44 changes: 42 additions & 2 deletions pkg/cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package start

import (
"runtime"
"strings"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"github.com/jaegertracing/jaeger-operator/pkg/apis"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
"github.com/jaegertracing/jaeger-operator/pkg/controller"
"github.com/jaegertracing/jaeger-operator/pkg/version"
)
Expand Down Expand Up @@ -57,7 +61,7 @@ func NewStartCommand() *cobra.Command {
cmd.Flags().String("openshift-oauth-proxy-image", "openshift/oauth-proxy:latest", "The Docker image location definition for the OpenShift OAuth Proxy")
viper.BindPFlag("openshift-oauth-proxy-image", cmd.Flags().Lookup("openshift-oauth-proxy-image"))

cmd.Flags().String("platform", "kubernetes", "The target platform the operator will run. Possible values: 'kubernetes' and 'openshift'")
cmd.Flags().String("platform", "auto-detect", "The target platform the operator will run. Possible values: 'kubernetes', 'openshift', 'auto-detect'")
viper.BindPFlag("platform", cmd.Flags().Lookup("platform"))

cmd.Flags().String("log-level", "info", "The log-level for the operator. Possible values: trace, debug, info, warning, error, fatal, panic")
Expand Down Expand Up @@ -99,7 +103,23 @@ func start(cmd *cobra.Command, args []string) {
log.Fatal(err)
}

log.Print("Registering Components.")
if strings.EqualFold(viper.GetString("platform"), v1alpha1.FlagPlatformAutoDetect) {
log.Debug("Attempting to auto-detect the platform")
os, err := detectOpenShift(mgr.GetConfig())
if err != nil {
log.WithError(err).Info("failed to auto-detect the platform, falling back to 'kubernetes'")
}

if os {
viper.Set("platform", v1alpha1.FlagPlatformOpenShift)
} else {
viper.Set("platform", v1alpha1.FlagPlatformKubernetes)
}

log.WithField("platform", viper.GetString("platform")).Info("Auto-detected the platform")
} else {
log.WithField("platform", viper.GetString("platform")).Debug("The 'platform' option is set")
}

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
Expand All @@ -116,3 +136,23 @@ func start(cmd *cobra.Command, args []string) {
// Start the Cmd
log.Fatal(mgr.Start(signals.SetupSignalHandler()))
}

// copied from Snowdrop's Component Operator
// https://github.com/snowdrop/component-operator/blob/744a9501c58f60877aa2b3a7e6c75da669519e8e/pkg/util/kubernetes/config.go
func detectOpenShift(kubeconfig *rest.Config) (bool, error) {
discoveryClient, err := discovery.NewDiscoveryClientForConfig(kubeconfig)
if err != nil {
return false, err
}
apiList, err := discoveryClient.ServerGroups()
if err != nil {
return false, err
}
apiGroups := apiList.Groups
for i := 0; i < len(apiGroups); i++ {
if apiGroups[i].Name == "route.openshift.io" {
return true, nil
}
}
return false, nil
}