Skip to content

Commit

Permalink
Move "databaseName" specification from the database-integration to th…
Browse files Browse the repository at this point in the history
…e database-typed intent. (#299)
  • Loading branch information
omris94 authored Nov 26, 2023
1 parent 10d2606 commit 37abd4d
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 82 deletions.
2 changes: 2 additions & 0 deletions src/operator/api/v1alpha2/clientintents_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func convertDatabaseResourcesV1alpha2toV1alpha3(srcResources []DatabaseResource)
dstResources := make([]v1alpha3.DatabaseResource, len(srcResources))
for i, resource := range srcResources {
dstResources[i].Table = resource.Table
dstResources[i].DatabaseName = resource.DatabaseName
dstResources[i].Operations = lo.Map(resource.Operations, func(operation DatabaseOperation, _ int) v1alpha3.DatabaseOperation {
return v1alpha3.DatabaseOperation(operation)
})
Expand Down Expand Up @@ -102,6 +103,7 @@ func (in *ClientIntents) ConvertFrom(srcRaw conversion.Hub) error {
func convertDatabaseResourcesV1alpha3toV1alpha2(srcResources []v1alpha3.DatabaseResource) []DatabaseResource {
dstResources := make([]DatabaseResource, len(srcResources))
for i, resource := range srcResources {
dstResources[i].DatabaseName = resource.DatabaseName
dstResources[i].Table = resource.Table
dstResources[i].Operations = lo.Map(resource.Operations, func(operation v1alpha3.DatabaseOperation, _ int) DatabaseOperation {
return DatabaseOperation(operation)
Expand Down
5 changes: 3 additions & 2 deletions src/operator/api/v1alpha2/intents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ type Intent struct {
}

type DatabaseResource struct {
Table string `json:"table" yaml:"table"`
Operations []DatabaseOperation `json:"operations" yaml:"operations"`
DatabaseName string `json:"databaseName" yaml:"databaseName"`
Table string `json:"table" yaml:"table"`
Operations []DatabaseOperation `json:"operations" yaml:"operations"`
}

type HTTPResource struct {
Expand Down
8 changes: 5 additions & 3 deletions src/operator/api/v1alpha3/clientintents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ type Intent struct {
}

type DatabaseResource struct {
Table string `json:"table" yaml:"table"`
Operations []DatabaseOperation `json:"operations" yaml:"operations"`
DatabaseName string `json:"databaseName" yaml:"databaseName"`
Table string `json:"table" yaml:"table"`
Operations []DatabaseOperation `json:"operations" yaml:"operations"`
}

type HTTPResource struct {
Expand Down Expand Up @@ -484,7 +485,8 @@ func (in *Intent) ConvertToCloudFormat(resourceNamespace string, clientName stri
if in.DatabaseResources != nil {
intentInput.DatabaseResources = lo.Map(in.DatabaseResources, func(resource DatabaseResource, _ int) *graphqlclient.DatabaseConfigInput {
databaseConfigInput := graphqlclient.DatabaseConfigInput{
Table: lo.ToPtr(resource.Table),
Table: lo.ToPtr(resource.Table),
Dbname: lo.ToPtr(resource.DatabaseName),
Operations: lo.Map(resource.Operations, func(operation DatabaseOperation, _ int) *graphqlclient.DatabaseOperation {
cloudOperation := databaseOperationToCloud(operation)
return &cloudOperation
Expand Down
6 changes: 6 additions & 0 deletions src/operator/config/crd/k8s.otterize.com_clientintents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
databaseResources:
items:
properties:
databaseName:
type: string
operations:
items:
enum:
Expand All @@ -54,6 +56,7 @@ spec:
table:
type: string
required:
- databaseName
- operations
- table
type: object
Expand Down Expand Up @@ -196,6 +199,8 @@ spec:
databaseResources:
items:
properties:
databaseName:
type: string
operations:
items:
enum:
Expand All @@ -209,6 +214,7 @@ spec:
table:
type: string
required:
- databaseName
- operations
- table
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
clientName string = "test-client"
integrationName string = "test-integration"
tableName string = "test-table"
dbName string = "testdb"
)

type DatabaseReconcilerTestSuite struct {
Expand Down Expand Up @@ -85,7 +86,8 @@ func (s *DatabaseReconcilerTestSuite) TestSimpleDatabase() {
Name: integrationName,
Type: otterizev1alpha3.IntentTypeDatabase,
DatabaseResources: []otterizev1alpha3.DatabaseResource{{
Table: tableName,
DatabaseName: dbName,
Table: tableName,
Operations: []otterizev1alpha3.DatabaseOperation{
otterizev1alpha3.DatabaseOperationSelect,
otterizev1alpha3.DatabaseOperationInsert,
Expand All @@ -103,7 +105,8 @@ func (s *DatabaseReconcilerTestSuite) TestSimpleDatabase() {
ServerNamespace: lo.ToPtr(testNamespace),
Type: lo.ToPtr(graphqlclient.IntentTypeDatabase),
DatabaseResources: []*graphqlclient.DatabaseConfigInput{{
Table: lo.ToPtr(tableName),
Table: lo.ToPtr(tableName),
Dbname: lo.ToPtr(dbName),
Operations: []*graphqlclient.DatabaseOperation{
lo.ToPtr(graphqlclient.DatabaseOperationSelect),
lo.ToPtr(graphqlclient.DatabaseOperationInsert),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
databaseResources:
items:
properties:
databaseName:
type: string
operations:
items:
enum:
Expand All @@ -59,6 +61,7 @@ spec:
table:
type: string
required:
- databaseName
- operations
- table
type: object
Expand Down Expand Up @@ -196,6 +199,8 @@ spec:
databaseResources:
items:
properties:
databaseName:
type: string
operations:
items:
enum:
Expand All @@ -209,6 +214,7 @@ spec:
table:
type: string
required:
- databaseName
- operations
- table
type: object
Expand Down
2 changes: 1 addition & 1 deletion src/shared/otterizecloud/graphqlclient/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package graphqlclient

import _ "github.com/suessflorian/gqlfetch"

//go:generate sh -c "go run github.com/suessflorian/gqlfetch/gqlfetch --endpoint https://app.staging.otterize.com/api/graphql/v1beta > schema.graphql"
//go:generate sh -c "go run github.com/suessflorian/gqlfetch/gqlfetch --endpoint http://app.staging.otterize.com/api/graphql/v1beta > schema.graphql"
//go:generate go run github.com/Khan/genqlient ./genqlient.yaml
4 changes: 4 additions & 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.

Loading

0 comments on commit 37abd4d

Please sign in to comment.