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

Ensure the OAuth Proxy image detection is run after the platform detection #2280

Merged
merged 2 commits into from
Aug 2, 2023
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
82 changes: 82 additions & 0 deletions pkg/autodetect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import (
"sync"
"time"

osimagev1 "github.com/openshift/api/image/v1"
"github.com/spf13/viper"
"go.opentelemetry.io/otel"
appsv1 "k8s.io/api/apps/v1"
authenticationapi "k8s.io/api/authentication/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"

v1 "github.com/jaegertracing/jaeger-operator/apis/v1"
"github.com/jaegertracing/jaeger-operator/pkg/inject"
"github.com/jaegertracing/jaeger-operator/pkg/tracing"
)

var listenedGroupsMap = map[string]bool{"logging.openshift.io": true, "kafka.strimzi.io": true, "route.openshift.io": true}
Expand Down Expand Up @@ -96,6 +100,8 @@ func (b *Background) autoDetectCapabilities() {
// the platform won't change during the execution of the operator, need to run it only once
b.detectPlatform(ctx, apiList)

b.detectOAuthProxyImageStream(ctx)

// the version of the APIs provided by the platform will not change
b.detectCronjobsVersion(ctx)
b.detectAutoscalingVersion(ctx)
Expand Down Expand Up @@ -216,6 +222,82 @@ func (b *Background) detectPlatform(ctx context.Context, apiList []*metav1.APIRe
)
}

func (b *Background) detectOAuthProxyImageStream(ctx context.Context) {
tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer)
ctx, span := tracer.Start(ctx, "detectOAuthProxyImageStream")
defer span.End()

if viper.GetString("platform") != v1.FlagPlatformOpenShift {
log.Log.V(-1).Info(
"Not running on OpenShift, so won't configure OAuthProxy imagestream.",
)
return
}

imageStreamNamespace := viper.GetString("openshift-oauth-proxy-imagestream-ns")
imageStreamName := viper.GetString("openshift-oauth-proxy-imagestream-name")
if imageStreamNamespace == "" || imageStreamName == "" {
log.Log.Info(
"OAuthProxy ImageStream namespace and/or name not defined",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

imageStream := &osimagev1.ImageStream{}
namespacedName := types.NamespacedName{
Name: imageStreamName,
Namespace: imageStreamNamespace,
}

if err := b.cl.Get(ctx, namespacedName, imageStream); err != nil {
log.Log.Error(
err,
"Failed to obtain OAuthProxy ImageStream",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
tracing.HandleError(err, span)
return
}

if len(imageStream.Status.Tags) == 0 {
log.Log.V(6).Info(
"OAuthProxy ImageStream has no tags",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

if len(imageStream.Status.Tags[0].Items) == 0 {
log.Log.V(6).Info(
"OAuthProxy ImageStream tag has no items",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

if len(imageStream.Status.Tags[0].Items[0].DockerImageReference) == 0 {
log.Log.V(5).Info(
"OAuthProxy ImageStream tag has no DockerImageReference",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

image := imageStream.Status.Tags[0].Items[0].DockerImageReference

viper.Set("openshift-oauth-proxy-image", image)
log.Log.Info(
"Updated OAuth Proxy image flag",
"image", image,
)
}

func (b *Background) detectElasticsearch(ctx context.Context, apiList []*metav1.APIResourceList) {
// detect whether the Elasticsearch operator is available
currentESProvision := viper.GetString("es-provision")
Expand Down
77 changes: 0 additions & 77 deletions pkg/cmd/start/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -129,89 +128,13 @@ func bootstrap(ctx context.Context) manager.Manager {
performUpgrades(ctx, mgr)
setupControllers(ctx, mgr)
setupWebhooks(ctx, mgr)
detectOAuthProxyImageStream(ctx, mgr)
err = opmetrics.Bootstrap(ctx, namespace, mgr.GetClient())
if err != nil {
log.Log.Error(err, "failed to initialize metrics")
}
return mgr
}

func detectOAuthProxyImageStream(ctx context.Context, mgr manager.Manager) {
tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer)
ctx, span := tracer.Start(ctx, "detectOAuthProxyImageStream")
defer span.End()

if viper.GetString("platform") != v1.FlagPlatformOpenShift {
log.Log.V(-1).Info(
"Not running on OpenShift, so won't configure OAuthProxy imagestream.",
)
return
}

imageStreamNamespace := viper.GetString("openshift-oauth-proxy-imagestream-ns")
imageStreamName := viper.GetString("openshift-oauth-proxy-imagestream-name")
if imageStreamNamespace == "" || imageStreamName == "" {
log.Log.Info(
"OAuthProxy ImageStream namespace and/or name not defined",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

imageStream := &osimagev1.ImageStream{}
namespacedName := types.NamespacedName{
Name: imageStreamName,
Namespace: imageStreamNamespace,
}
if err := mgr.GetAPIReader().Get(ctx, namespacedName, imageStream); err != nil {
log.Log.Error(
err,
"Failed to obtain OAuthProxy ImageStream",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
tracing.HandleError(err, span)
return
}

if len(imageStream.Status.Tags) == 0 {
log.Log.V(6).Info(
"OAuthProxy ImageStream has no tags",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

if len(imageStream.Status.Tags[0].Items) == 0 {
log.Log.V(6).Info(
"OAuthProxy ImageStream tag has no items",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

if len(imageStream.Status.Tags[0].Items[0].DockerImageReference) == 0 {
log.Log.V(5).Info(
"OAuthProxy ImageStream tag has no DockerImageReference",
"namespace", imageStreamNamespace,
"name", imageStreamName,
)
return
}

image := imageStream.Status.Tags[0].Items[0].DockerImageReference

viper.Set("openshift-oauth-proxy-image", image)
log.Log.Info(
"Updated OAuth Proxy image flag",
"image", image,
)
}

func detectNamespacePermissions(ctx context.Context, mgr manager.Manager) {
tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer)
ctx, span := tracer.Start(ctx, "detectNamespacePermissions")
Expand Down