diff --git a/src/operator/api/v2alpha1/clientintents_types.go b/src/operator/api/v2alpha1/clientintents_types.go index 47987668f..9b41c0765 100644 --- a/src/operator/api/v2alpha1/clientintents_types.go +++ b/src/operator/api/v2alpha1/clientintents_types.go @@ -775,7 +775,12 @@ func (in *Target) GetHTTPResources() []HTTPTarget { func (in *Target) ConvertToCloudFormat(ctx context.Context, k8sClient client.Client, clientServiceIdentity serviceidentity.ServiceIdentity) (graphqlclient.IntentInput, error) { serverServiceIdentity := in.ToServiceIdentity(clientServiceIdentity.Namespace) var alias *graphqlclient.ServerAliasInput - if in.IsTargetServerKubernetesService() { + if in.IsTargetTheKubernetesAPIServer(clientServiceIdentity.Namespace) { + alias = &graphqlclient.ServerAliasInput{ + Name: lo.ToPtr(serverServiceIdentity.GetNameAsServer()), + Kind: lo.ToPtr(serviceidentity.KindService), + } + } else if in.IsTargetServerKubernetesService() { // alias should be the kubernetes service alias = &graphqlclient.ServerAliasInput{ Name: lo.ToPtr(serverServiceIdentity.GetNameAsServer()), @@ -800,7 +805,6 @@ func (in *Target) ConvertToCloudFormat(ctx context.Context, k8sClient client.Cli serverServiceIdentity = si } } - } intentInput := graphqlclient.IntentInput{ diff --git a/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go b/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go index 2ef0a0439..0774d756b 100644 --- a/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go +++ b/src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go @@ -3,6 +3,7 @@ package intents_reconcilers import ( "context" "errors" + "fmt" otterizev2alpha1 "github.com/otterize/intents-operator/src/operator/api/v2alpha1" mocks "github.com/otterize/intents-operator/src/operator/controllers/intents_reconcilers/mocks" "github.com/otterize/intents-operator/src/shared/operator_cloud_client" @@ -824,6 +825,18 @@ func (s *CloudReconcilerTestSuite) TestReportKindAndAlias() { s.Require().Equal(lo.FromPtr(cloudIntent.ClientWorkloadKind), "StatefulSet") } +func (s *CloudReconcilerTestSuite) TestReportTargetKubernetesAPIServiceWithNoSelector() { + serverName := "kubernetes" + serverNamespace := "default" + intent := &otterizev2alpha1.Target{Service: &otterizev2alpha1.ServiceTarget{Name: fmt.Sprint(serverName, ".", serverNamespace)}} + cloudIntent, err := intent.ConvertToCloudFormat(context.Background(), s.client, serviceidentity.ServiceIdentity{Name: clientName, Namespace: testNamespace}) + s.Require().NoError(err) + s.Require().Equal(lo.FromPtr(cloudIntent.ServerWorkloadKind), "Service") + s.Require().Equal(lo.FromPtr(cloudIntent.ServerAlias), graphqlclient.ServerAliasInput{Name: lo.ToPtr(serverName + "." + serverNamespace), Kind: lo.ToPtr("Service")}) + s.Require().Equal(lo.FromPtr(cloudIntent.ServerNamespace), serverNamespace) + s.Require().Equal(lo.FromPtr(cloudIntent.ServerName), serverName) +} + func (s *CloudReconcilerTestSuite) expectNoEvent() { select { case event := <-s.recorder.Events: