Skip to content

Commit

Permalink
Renderer: detect if imagestream is available
Browse files Browse the repository at this point in the history
Only try to get the oauth image from the OCP imagestream, if the
image.openshift.io api type is available. Otherwise, it likely means
we're running a non-ocp system (for kind tests for example) and in this
case we accept using the base template image.

Signed-off-by: Jacob Baungard Hansen <[email protected]>
  • Loading branch information
jacobbaungard committed Nov 25, 2024
1 parent 7e1868f commit a32e046
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
20 changes: 20 additions & 0 deletions operators/multiclusterobservability/pkg/rendering/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/discovery"
logf "sigs.k8s.io/controller-runtime/pkg/log"

obv1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2"
Expand Down Expand Up @@ -193,3 +194,22 @@ func (r *MCORenderer) MCOAResources(namespace string, labels map[string]string)

return mcoaResources, nil
}

func (r *MCORenderer) HasImagestream() (bool, error) {
dcl := discovery.NewDiscoveryClient(r.imageClient.RESTClient())

apiList, err := dcl.ServerGroups()
if err != nil {
log.Error(err, "unable to get ServerGroups from imagestream detection")
return false, err
}

apiGroups := apiList.Groups
for i := 0; i < len(apiGroups); i++ {
if apiGroups[i].Name == "image.openshift.io" {
return true, nil
}
}

return false, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,21 @@ func (r *MCORenderer) renderAlertManagerStatefulSet(res *resource.Resource, name
configReloaderContainer.Image = image
}

found, image = mcoconfig.GetOauthProxyImage(r.imageClient)
if found {
oauthProxyContainer.Image = image
} else {
return nil, fmt.Errorf("failed to get OAuth image for alertmanager")
hasImagestream, err := r.HasImagestream()
if err != nil {
return nil, err
}

// If we're on OCP and has imagestreams, we always want the oauth image
// from the imagestream, and fail the reconcile if we don't find it.
// If we're on non-OCP (tests) we use the base template image
if hasImagestream {
found, image = mcoconfig.GetOauthProxyImage(r.imageClient)
if found {
oauthProxyContainer.Image = image
} else {
return nil, fmt.Errorf("failed to get OAuth image for alertmanager")
}
}
oauthProxyContainer.ImagePullPolicy = imagePullPolicy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@ func (r *MCORenderer) renderGrafanaDeployments(res *resource.Resource,
}
spec.Containers[1].ImagePullPolicy = imagePullPolicy

found, image = config.GetOauthProxyImage(r.imageClient)
if found {
spec.Containers[2].Image = image
} else {
return nil, fmt.Errorf("failed to get OAuth image for Grafana")
hasImagestream, err := r.HasImagestream()
if err != nil {
return nil, err
}

// If we're on OCP and has imagestreams, we always want the oauth image
// from the imagestream, and fail the reconcile if we don't find it.
// If we're on non-OCP (tests) we use the base template image
if hasImagestream {
found, image = config.GetOauthProxyImage(r.imageClient)
if found {
spec.Containers[2].Image = image
} else {
return nil, fmt.Errorf("failed to get OAuth image for alertmanager")
}
}
spec.Containers[2].ImagePullPolicy = imagePullPolicy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,21 @@ func (r *MCORenderer) renderProxyDeployment(res *resource.Resource,
spec.Containers[0].Image = image
}

found, image = mcoconfig.GetOauthProxyImage(r.imageClient)
if found {
spec.Containers[1].Image = image
} else {
return nil, fmt.Errorf("failed to get OAuth image for rbacqueryproxy")
hasImagestream, err := r.HasImagestream()
if err != nil {
return nil, err
}

// If we're on OCP and has imagestreams, we always want the oauth image
// from the imagestream, and fail the reconcile if we don't find it.
// If we're on non-OCP (tests) we use the base template image
if hasImagestream {
found, image = mcoconfig.GetOauthProxyImage(r.imageClient)
if found {
spec.Containers[1].Image = image
} else {
return nil, fmt.Errorf("failed to get OAuth image for alertmanager")
}
}

for idx := range spec.Volumes {
Expand Down

0 comments on commit a32e046

Please sign in to comment.