Skip to content

Commit

Permalink
Fix a bug where applied intents with kind in their targets wouldn't b…
Browse files Browse the repository at this point in the history
…e reported properly (#458)
  • Loading branch information
omris94 authored Jul 28, 2024
1 parent 811ed42 commit 815e69d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/operator/api/v2alpha1/clientintents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 815e69d

Please sign in to comment.