Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Update test case for Value Reference in Template
Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan committed Nov 2, 2023
commit 687d7c0f71a7e9bf33c8cfd897c038b6932d1a88
13 changes: 12 additions & 1 deletion controllers/operandrequest/operandrequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ = Describe("OperandRequest controller", func() {
namespace = "ibm-cloudpak"
registryName1 = "common-service"
registryName2 = "common-service-2"
registryNamespace = "ibm-common-services"
registryNamespace = "data-ns"
operatorNamespace = "ibm-operators"
)

Expand Down Expand Up @@ -319,6 +319,12 @@ var _ = Describe("OperandRequest controller", func() {
return err
}, testutil.Timeout, testutil.Interval).Should(Succeed())

Eventually(func() error {
jaegerConfigMap := &corev1.ConfigMap{}
err := k8sClient.Get(context.TODO(), types.NamespacedName{Name: "jaeger-configmap-reference", Namespace: registryNamespaceName}, jaegerConfigMap)
return err
}, testutil.Timeout, testutil.Interval).Should(Succeed())

By("Disabling the jaeger operator from first OperandRequest")
requestInstance1 := &operatorv1alpha1.OperandRequest{}
Expect(k8sClient.Get(ctx, requestKey1, requestInstance1)).Should(Succeed())
Expand Down Expand Up @@ -364,6 +370,11 @@ var _ = Describe("OperandRequest controller", func() {
err := k8sClient.Get(context.TODO(), types.NamespacedName{Name: "jaeger-configmap", Namespace: registryNamespaceName}, jaegerConfigMap)
return err != nil && errors.IsNotFound(err)
}, testutil.Timeout, testutil.Interval).Should(BeTrue())
Eventually(func() bool {
jaegerConfigMap := &corev1.ConfigMap{}
err := k8sClient.Get(context.TODO(), types.NamespacedName{Name: "jaeger-configmap-reference", Namespace: registryNamespaceName}, jaegerConfigMap)
return err != nil && errors.IsNotFound(err)
}, testutil.Timeout, testutil.Interval).Should(BeTrue())

By("Checking operators have been deleted")
Eventually(func() bool {
Expand Down
2 changes: 1 addition & 1 deletion controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,6 @@ func (m *ODLMOperator) GetValueRefFromObject(ctx context.Context, instanceType,
return "", errors.Errorf("failed to get path %v from %s %s/%s, the value is not found", path, obj.GetKind(), obj.GetNamespace(), obj.GetName())
}

klog.Infof("Get value %s from %s %s/%s", value, objKind, obj.GetNamespace(), obj.GetName())
klog.V(2).Infof("Get value %s from %s %s/%s", value, objKind, obj.GetNamespace(), obj.GetName())
return value, nil
}
45 changes: 43 additions & 2 deletions controllers/testutil/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var SubConfig = &olmv1alpha1.SubscriptionConfig{

// CreateNSName generates random namespace names. Namespaces are never deleted in test environment
func CreateNSName(prefix string) string {
suffix := make([]byte, 10)
suffix := make([]byte, 4)
_, err := rand.Read(suffix)
if err != nil {
panic(err)
Expand Down Expand Up @@ -142,7 +142,18 @@ func OperandConfigObj(name, namespace string) *apiv1alpha1.OperandConfig {
Name: "jaeger",
Spec: map[string]apiv1alpha1.ExtensionWithMarker{
"jaeger": {
RawExtension: runtime.RawExtension{Raw: []byte(`{"strategy": "streaming"}`)},
RawExtension: runtime.RawExtension{Raw: []byte(`{
"strategy": {
"templatingValueFrom": {
"required": true,
"configMapKeyRef": {
"name": "jaeger-configmap-reference",
"key": "putStrategy"
}
}
}
}`),
},
},
},
Resources: []apiv1alpha1.ConfigResource{
Expand All @@ -161,6 +172,36 @@ func OperandConfigObj(name, namespace string) *apiv1alpha1.OperandConfig {
},
Force: false,
},
{
Name: "jaeger-configmap-reference",
APIVersion: "v1",
Kind: "ConfigMap",
Labels: map[string]string{
"jaeger": "jaeger-configmap-reference",
},
Annotations: map[string]string{
"jaeger": "jaeger-configmap-reference",
},
Data: &runtime.RawExtension{
Raw: []byte(`{
"data": {
"getStrategy": {
"templatingValueFrom": {
"required": true,
"objectRef": {
"apiVersion": "v1",
"kind": "ConfigMap",
"name": "jaeger-configmap",
"path": "data.strategy"
}
}
},
"putStrategy": "streaming"
}
}`),
},
Force: false,
},
},
},
{
Expand Down