Skip to content

Commit

Permalink
Convert Kafka operation enum to cloud format (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelBollag authored Jan 24, 2023
1 parent d626fb4 commit 597f334
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion graphql
34 changes: 33 additions & 1 deletion src/operator/api/v1alpha2/intents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"github.com/otterize/intents-operator/src/shared/otterizecloud/graphqlclient"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"strings"
Expand Down Expand Up @@ -226,12 +227,43 @@ func toPtrOrNil(s string) *string {
return lo.ToPtr(s)
}

func kafkaOperationK8sToCloud(op KafkaOperation) graphqlclient.KafkaOperation {
switch op {
case KafkaOperationAll:
return graphqlclient.KafkaOperationAll
case KafkaOperationConsume:
return graphqlclient.KafkaOperationConsume
case KafkaOperationProduce:
return graphqlclient.KafkaOperationProduce
case KafkaOperationCreate:
return graphqlclient.KafkaOperationCreate
case KafkaOperationAlter:
return graphqlclient.KafkaOperationAlter
case KafkaOperationDelete:
return graphqlclient.KafkaOperationDelete
case KafkaOperationDescribe:
return graphqlclient.KafkaOperationDescribe
case KafkaOperationClusterAction:
return graphqlclient.KafkaOperationClusterAction
case KafkaOperationDescribeConfigs:
return graphqlclient.KafkaOperationDescribeConfigs
case KafkaOperationAlterConfigs:
return graphqlclient.KafkaOperationAlterConfigs
case KafkaOperationIdempotentWrite:
return graphqlclient.KafkaOperationIdempotentWrite
default:
logrus.Panic(fmt.Sprintf("Unknown KafkaOperation: %s", op))
return "" // We won't reach here
}
}

func (in *Intent) ConvertToCloudFormat(resourceNamespace string, clientName string) graphqlclient.IntentInput {
otterizeTopics := lo.Map(in.Topics, func(topic KafkaTopic, i int) *graphqlclient.KafkaConfigInput {
return lo.ToPtr(graphqlclient.KafkaConfigInput{
Name: lo.ToPtr(topic.Name),
Operations: lo.Map(topic.Operations, func(op KafkaOperation, i int) *graphqlclient.KafkaOperation {
return lo.ToPtr(graphqlclient.KafkaOperation(op))
operation := kafkaOperationK8sToCloud(op)
return &operation
}),
})
})
Expand Down
1 change: 1 addition & 0 deletions src/shared/otterizecloud/graphqlclient/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 597f334

Please sign in to comment.