Skip to content

Commit 780caa2

Browse files
authored
Fix bug where reporting applied intents to the cloud could fail when using istio, due to a missing SharedServiceAccount annotation (#568)
1 parent aee63b3 commit 780caa2

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed

src/operator/api/v1alpha3/clientintents_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,13 @@ func clientIntentsStatusToCloudFormat(clientIntents ClientIntents, intent Intent
572572

573573
status.IstioStatus.ServiceAccountName = toPtrOrNil(serviceAccountName)
574574
isSharedValue, ok := clientIntents.Annotations[OtterizeSharedServiceAccountAnnotation]
575-
if !ok {
576-
return nil, false, errors.Errorf("missing annotation shared service account for client intents %s", clientIntents.Name)
577-
}
578-
579-
isShared, err := strconv.ParseBool(isSharedValue)
580-
if err != nil {
581-
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
575+
isShared := false
576+
if ok {
577+
parsedIsShared, err := strconv.ParseBool(isSharedValue)
578+
if err != nil {
579+
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
580+
}
581+
isShared = parsedIsShared
582582
}
583583
status.IstioStatus.IsServiceAccountShared = lo.ToPtr(isShared)
584584

src/operator/api/v1beta1/clientintents_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,13 @@ func clientIntentsStatusToCloudFormat(clientIntents ClientIntents, intent Intent
575575

576576
status.IstioStatus.ServiceAccountName = toPtrOrNil(serviceAccountName)
577577
isSharedValue, ok := clientIntents.Annotations[OtterizeSharedServiceAccountAnnotation]
578-
if !ok {
579-
return nil, false, errors.Errorf("missing annotation shared service account for client intents %s", clientIntents.Name)
580-
}
581-
582-
isShared, err := strconv.ParseBool(isSharedValue)
583-
if err != nil {
584-
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
578+
isShared := false
579+
if ok {
580+
parsedIsShared, err := strconv.ParseBool(isSharedValue)
581+
if err != nil {
582+
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
583+
}
584+
isShared = parsedIsShared
585585
}
586586
status.IstioStatus.IsServiceAccountShared = lo.ToPtr(isShared)
587587

src/operator/api/v2alpha1/clientintents_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,13 @@ func clientIntentsStatusToCloudFormat(clientIntents ClientIntents, intent Target
688688

689689
status.IstioStatus.ServiceAccountName = toPtrOrNil(serviceAccountName)
690690
isSharedValue, ok := clientIntents.Annotations[OtterizeSharedServiceAccountAnnotation]
691-
if !ok {
692-
return nil, false, errors.Errorf("missing annotation shared service account for client intents %s", clientIntents.Name)
693-
}
694-
695-
isShared, err := strconv.ParseBool(isSharedValue)
696-
if err != nil {
697-
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
691+
isShared := false
692+
if ok {
693+
parsedIsShared, err := strconv.ParseBool(isSharedValue)
694+
if err != nil {
695+
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
696+
}
697+
isShared = parsedIsShared
698698
}
699699
status.IstioStatus.IsServiceAccountShared = lo.ToPtr(isShared)
700700

src/operator/api/v2beta1/clientintents_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,13 @@ func clientIntentsStatusToCloudFormat(clientIntents ClientIntents, intent Target
688688

689689
status.IstioStatus.ServiceAccountName = toPtrOrNil(serviceAccountName)
690690
isSharedValue, ok := clientIntents.Annotations[OtterizeSharedServiceAccountAnnotation]
691-
if !ok {
692-
return nil, false, errors.Errorf("missing annotation shared service account for client intents %s", clientIntents.Name)
693-
}
694-
695-
isShared, err := strconv.ParseBool(isSharedValue)
696-
if err != nil {
697-
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
691+
isShared := false
692+
if ok {
693+
parsedIsShared, err := strconv.ParseBool(isSharedValue)
694+
if err != nil {
695+
return nil, false, errors.Errorf("failed to parse shared service account annotation for client intents %s", clientIntents.Name)
696+
}
697+
isShared = parsedIsShared
698698
}
699699
status.IstioStatus.IsServiceAccountShared = lo.ToPtr(isShared)
700700

src/operator/controllers/intents_reconcilers/cloud_reconciler_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,29 @@ func (s *CloudReconcilerTestSuite) TestIntentStatusFormattingError_MissingShared
476476
},
477477
}
478478

479-
s.expectReconcilerError(clientIntents)
479+
expectedIntent := graphqlclient.IntentInput{
480+
ClientName: lo.ToPtr(clientName),
481+
ServerName: lo.ToPtr(server),
482+
Namespace: lo.ToPtr(testNamespace),
483+
ServerNamespace: lo.ToPtr(testNamespace),
484+
Type: lo.ToPtr(graphqlclient.IntentTypeHttp),
485+
Resources: []*graphqlclient.HTTPConfigInput{
486+
{
487+
Path: lo.ToPtr("/login"),
488+
Methods: []*graphqlclient.HTTPMethod{lo.ToPtr(graphqlclient.HTTPMethodGet), lo.ToPtr(graphqlclient.HTTPMethodPost)},
489+
},
490+
},
491+
Status: &graphqlclient.IntentStatusInput{
492+
IstioStatus: &graphqlclient.IstioStatusInput{
493+
ServiceAccountName: lo.ToPtr(serviceAccountName),
494+
IsServiceAccountShared: lo.ToPtr(false),
495+
IsClientMissingSidecar: lo.ToPtr(false),
496+
IsServerMissingSidecar: lo.ToPtr(false),
497+
},
498+
},
499+
}
500+
501+
s.assertReportedIntents(clientIntents, []graphqlclient.IntentInput{expectedIntent})
480502
}
481503

482504
func (s *CloudReconcilerTestSuite) TestIntentStatusFormattingError_MissingSidecar() {

0 commit comments

Comments
 (0)