Skip to content

Commit

Permalink
Fix a bug where applied intents to the Kubernets API service couldn't…
Browse files Browse the repository at this point in the history
… be reported to the cloud properly (#459)
  • Loading branch information
omris94 authored Jul 29, 2024
1 parent 815e69d commit 83ff0b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/operator/api/v2alpha1/clientintents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -800,7 +805,6 @@ func (in *Target) ConvertToCloudFormat(ctx context.Context, k8sClient client.Cli
serverServiceIdentity = si
}
}

}

intentInput := graphqlclient.IntentInput{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 83ff0b1

Please sign in to comment.