diff --git a/src/operator/api/v2alpha1/clientintents_types.go b/src/operator/api/v2alpha1/clientintents_types.go index 87baacd53..47987668f 100644 --- a/src/operator/api/v2alpha1/clientintents_types.go +++ b/src/operator/api/v2alpha1/clientintents_types.go @@ -807,7 +807,7 @@ func (in *Target) ConvertToCloudFormat(ctx context.Context, k8sClient client.Cli ClientName: lo.ToPtr(clientServiceIdentity.Name), ClientWorkloadKind: lo.Ternary(clientServiceIdentity.Kind != serviceidentity.KindOtterizeLegacy, lo.ToPtr(clientServiceIdentity.Kind), nil), ServerName: lo.ToPtr(serverServiceIdentity.Name), - ServerWorkloadKind: lo.Ternary(serverServiceIdentity.Kind != serviceidentity.KindOtterizeLegacy, lo.ToPtr(clientServiceIdentity.Kind), nil), + ServerWorkloadKind: lo.Ternary(serverServiceIdentity.Kind != serviceidentity.KindOtterizeLegacy, lo.ToPtr(serverServiceIdentity.Kind), nil), Namespace: lo.ToPtr(clientServiceIdentity.Namespace), ServerNamespace: toPtrOrNil(in.GetTargetServerNamespace(clientServiceIdentity.Namespace)), ServerAlias: alias, diff --git a/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go b/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go index a4aae9a6b..2ef0a0439 100644 --- a/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go +++ b/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go @@ -12,7 +12,9 @@ import ( "github.com/samber/lo" "github.com/stretchr/testify/suite" "go.uber.org/mock/gomock" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" @@ -793,6 +795,35 @@ func (s *CloudReconcilerTestSuite) TestTargetNamespaceAsSourceNamespace() { s.Require().Equal(lo.FromPtr(cloudIntent.ServerNamespace), testNamespace) } +// TestReportKindAndAlias +func (s *CloudReconcilerTestSuite) TestReportKindAndAlias() { + serverName := "server" + intent := &otterizev2alpha1.Target{Service: &otterizev2alpha1.ServiceTarget{Name: serverName}} + s.client.EXPECT().Get(gomock.Any(), gomock.Eq(types.NamespacedName{Name: serverName, Namespace: testNamespace}), gomock.AssignableToTypeOf(&v1.Service{})).DoAndReturn(func(ctx context.Context, _ any, obj *v1.Service, _ ...any) error { + obj.Name = serverName + obj.Namespace = testNamespace + obj.Spec.Selector = map[string]string{"app": "test"} + return nil + }) + s.client.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, list *v1.PodList, _ ...any) error { + list.Items = []v1.Pod{{ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: testNamespace, OwnerReferences: []metav1.OwnerReference{{Name: serverName, Kind: "Deployment"}}}}} + return nil + }) + + s.client.EXPECT().Get(gomock.Any(), gomock.Eq(types.NamespacedName{Name: serverName, Namespace: testNamespace}), gomock.AssignableToTypeOf(&unstructured.Unstructured{})).DoAndReturn(func(ctx context.Context, _ any, obj *unstructured.Unstructured, _ ...any) error { + obj.SetName(serverName) + obj.SetNamespace(testNamespace) + obj.SetKind("Deployment") + return nil + }) + + cloudIntent, err := intent.ConvertToCloudFormat(context.Background(), s.client, serviceidentity.ServiceIdentity{Name: clientName, Namespace: testNamespace, Kind: "StatefulSet"}) + s.Require().NoError(err) + s.Require().Equal(lo.FromPtr(cloudIntent.ServerWorkloadKind), "Deployment") + s.Require().Equal(lo.FromPtr(cloudIntent.ServerAlias), graphqlclient.ServerAliasInput{Name: lo.ToPtr(serverName + "." + testNamespace), Kind: lo.ToPtr("Service")}) + s.Require().Equal(lo.FromPtr(cloudIntent.ClientWorkloadKind), "StatefulSet") +} + func (s *CloudReconcilerTestSuite) expectNoEvent() { select { case event := <-s.recorder.Events: