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

Render: fail if no oauth image is found #1669

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
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type MultiClusterObservabilityReconciler struct {
CRDMap map[string]bool
APIReader client.Reader
RESTMapper meta.RESTMapper
ImageClient *imagev1client.ImageV1Client
ImageClient imagev1client.ImageV1Interface
}

// +kubebuilder:rbac:groups=observability.open-cluster-management.io,resources=multiclusterobservabilities,verbs=get;list;watch;create;update;patch;delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
migrationv1alpha1 "sigs.k8s.io/kube-storage-version-migrator/pkg/apis/migration/v1alpha1"

imagev1 "github.com/openshift/api/image/v1"
fakeimageclient "github.com/openshift/client-go/image/clientset/versioned/fake"
fakeimagev1client "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1/fake"
)

func init() {
Expand Down Expand Up @@ -350,8 +354,32 @@ func TestMultiClusterMonitoringCRUpdate(t *testing.T) {
).
Build()

// Create fake imagestream client
imageClient := &fakeimagev1client.FakeImageV1{Fake: &(fakeimageclient.NewSimpleClientset().Fake)}
_, err := imageClient.ImageStreams(config.OauthProxyImageStreamNamespace).Create(context.Background(),
&imagev1.ImageStream{
ObjectMeta: metav1.ObjectMeta{
Name: config.OauthProxyImageStreamName,
Namespace: config.OauthProxyImageStreamNamespace,
},
Spec: imagev1.ImageStreamSpec{
Tags: []imagev1.TagReference{
{
Name: "v4.4",
From: &corev1.ObjectReference{
Kind: "DockerImage",
Name: "quay.io/openshift-release-dev/ocp-v4.0-art-dev",
},
},
},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatal(err)
}

// Create a ReconcileMemcached object with the scheme and fake client.
r := &MultiClusterObservabilityReconciler{Client: cl, Scheme: s, CRDMap: map[string]bool{config.IngressControllerCRD: true}}
r := &MultiClusterObservabilityReconciler{Client: cl, Scheme: s, CRDMap: map[string]bool{config.IngressControllerCRD: true}, ImageClient: imageClient}
config.SetMonitoringCRName(name)
// Mock request to simulate Reconcile() being called on an event for a
// watched resource .
Expand All @@ -363,7 +391,7 @@ func TestMultiClusterMonitoringCRUpdate(t *testing.T) {

// Create empty client. The test secret specified in MCO is not yet created.
t.Log("Reconcile empty client")
_, err := r.Reconcile(context.TODO(), req)
_, err = r.Reconcile(context.TODO(), req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}
Expand Down Expand Up @@ -759,8 +787,32 @@ func TestImageReplaceForMCO(t *testing.T) {
// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithRuntimeObjects(objs...).Build()

// Create fake imagestream client
imageClient := &fakeimagev1client.FakeImageV1{Fake: &(fakeimageclient.NewSimpleClientset().Fake)}
_, err := imageClient.ImageStreams(config.OauthProxyImageStreamNamespace).Create(context.Background(),
&imagev1.ImageStream{
ObjectMeta: metav1.ObjectMeta{
Name: config.OauthProxyImageStreamName,
Namespace: config.OauthProxyImageStreamNamespace,
},
Spec: imagev1.ImageStreamSpec{
Tags: []imagev1.TagReference{
{
Name: "v4.4",
From: &corev1.ObjectReference{
Kind: "DockerImage",
Name: "quay.io/openshift-release-dev/ocp-v4.0-art-dev",
},
},
},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatal(err)
}

// Create a ReconcileMemcached object with the scheme and fake client.
r := &MultiClusterObservabilityReconciler{Client: cl, Scheme: s, CRDMap: map[string]bool{config.MCHCrdName: true, config.IngressControllerCRD: true}}
r := &MultiClusterObservabilityReconciler{Client: cl, Scheme: s, CRDMap: map[string]bool{config.MCHCrdName: true, config.IngressControllerCRD: true}, ImageClient: imageClient}
config.SetMonitoringCRName(name)

// Mock request to simulate Reconcile() being called on an event for a watched resource .
Expand All @@ -775,7 +827,7 @@ func TestImageReplaceForMCO(t *testing.T) {
config.SetImageManifests(testImagemanifestsMap)

// trigger another reconcile for MCH update event
_, err := r.Reconcile(context.TODO(), req)
_, err = r.Reconcile(context.TODO(), req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}
Expand Down
4 changes: 2 additions & 2 deletions operators/multiclusterobservability/pkg/rendering/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type RendererOptions struct {

type MCORenderer struct {
kubeClient client.Client
imageClient *imagev1client.ImageV1Client
imageClient imagev1client.ImageV1Interface
renderer *rendererutil.Renderer
cr *obv1beta2.MultiClusterObservability
rendererOptions *RendererOptions
Expand All @@ -40,7 +40,7 @@ type MCORenderer struct {
renderMCOAFns map[string]rendererutil.RenderFn
}

func NewMCORenderer(multipleClusterMonitoring *obv1beta2.MultiClusterObservability, kubeClient client.Client, imageClient *imagev1client.ImageV1Client) *MCORenderer {
func NewMCORenderer(multipleClusterMonitoring *obv1beta2.MultiClusterObservability, kubeClient client.Client, imageClient imagev1client.ImageV1Interface) *MCORenderer {
mcoRenderer := &MCORenderer{
renderer: rendererutil.NewRenderer(),
cr: multipleClusterMonitoring,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (r *MCORenderer) renderAlertManagerStatefulSet(res *resource.Resource, name
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 @@ -5,13 +5,17 @@
package rendering

import (
"context"
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"testing"

imagev1 "github.com/openshift/api/image/v1"
fakeimageclient "github.com/openshift/client-go/image/clientset/versioned/fake"
fakeimagev1client "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1/fake"
mcoshared "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/shared"
mcov1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2"
"github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/config"
Expand Down Expand Up @@ -288,7 +292,31 @@ func renderTemplates(t *testing.T, kubeClient client.Client, mco *mcov1beta2.Mul
defer os.Unsetenv(templatesutil.TemplatesPathEnvVar)

config.ReadImageManifestConfigMap(kubeClient, "v1")
renderer := NewMCORenderer(mco, kubeClient, nil)

imageClient := &fakeimagev1client.FakeImageV1{Fake: &(fakeimageclient.NewSimpleClientset().Fake)}
_, err = imageClient.ImageStreams(config.OauthProxyImageStreamNamespace).Create(context.Background(),
&imagev1.ImageStream{
ObjectMeta: metav1.ObjectMeta{
Name: config.OauthProxyImageStreamName,
Namespace: config.OauthProxyImageStreamNamespace,
},
Spec: imagev1.ImageStreamSpec{
Tags: []imagev1.TagReference{
{
Name: "v4.4",
From: &corev1.ObjectReference{
Kind: "DockerImage",
Name: "quay.io/openshift-release-dev/ocp-v4.0-art-dev",
},
},
},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatal(err)
}

renderer := NewMCORenderer(mco, kubeClient, imageClient)

//load and render alertmanager templates
alertTemplates, err := templates.GetOrLoadAlertManagerTemplates(templatesutil.GetTemplateRenderer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package rendering

import (
"fmt"

v1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -71,6 +73,8 @@ func (r *MCORenderer) renderGrafanaDeployments(res *resource.Resource,
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")
}
spec.Containers[2].ImagePullPolicy = imagePullPolicy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package rendering

import (
"fmt"
"strings"

v1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -96,6 +97,8 @@ func (r *MCORenderer) renderProxyDeployment(res *resource.Resource,
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")
}

for idx := range spec.Volumes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,30 @@ func TestRender(t *testing.T) {
}
kubeClient := fake.NewClientBuilder().WithObjects(clientCa).Build()

renderer := NewMCORenderer(mchcr, kubeClient, nil)
imageClient := &fakeimagev1client.FakeImageV1{Fake: &(fakeimageclient.NewSimpleClientset().Fake)}
_, err = imageClient.ImageStreams(config.OauthProxyImageStreamNamespace).Create(context.Background(),
&imagev1.ImageStream{
ObjectMeta: metav1.ObjectMeta{
Name: config.OauthProxyImageStreamName,
Namespace: config.OauthProxyImageStreamNamespace,
},
Spec: imagev1.ImageStreamSpec{
Tags: []imagev1.TagReference{
{
Name: "v4.4",
From: &corev1.ObjectReference{
Kind: "DockerImage",
Name: "quay.io/openshift-release-dev/ocp-v4.0-art-dev",
},
},
},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatal(err)
}

renderer := NewMCORenderer(mchcr, kubeClient, imageClient)
_, err = renderer.Render()
if err != nil {
t.Fatalf("failed to render MultiClusterObservability: %v", err)
Expand Down
Loading