Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: uses service module from the gen client #817

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions api/v1alpha1/serviceintegration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"reflect"

"github.com/aiven/go-client-codegen/handler/service"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clickhousekafkauserconfig "github.com/aiven/aiven-operator/api/v1alpha1/userconfig/integration/clickhouse_kafka"
Expand All @@ -26,7 +27,7 @@ type ServiceIntegrationSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:validation:Enum=alertmanager;autoscaler;caching;cassandra_cross_service_cluster;clickhouse_kafka;clickhouse_postgresql;dashboard;datadog;datasource;external_aws_cloudwatch_logs;external_aws_cloudwatch_metrics;external_elasticsearch_logs;external_google_cloud_logging;external_opensearch_logs;flink;flink_external_kafka;flink_external_postgresql;internal_connectivity;jolokia;kafka_connect;kafka_logs;kafka_mirrormaker;logs;m3aggregator;m3coordinator;metrics;opensearch_cross_cluster_replication;opensearch_cross_cluster_search;prometheus;read_replica;rsyslog;schema_registry_proxy;stresstester;thanosquery;thanosstore;vmalert
// Type of the service integration accepted by Aiven API. Some values may not be supported by the operator
IntegrationType string `json:"integrationType"`
IntegrationType service.IntegrationType `json:"integrationType"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:validation:MaxLength=36
Expand Down Expand Up @@ -127,17 +128,17 @@ func (in *ServiceIntegration) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *ServiceIntegration) getUserConfigFields() map[string]any {
return map[string]any{
"clickhouse_kafka": in.Spec.ClickhouseKafkaUserConfig,
"clickhouse_postgresql": in.Spec.ClickhousePostgreSQLUserConfig,
"datadog": in.Spec.DatadogUserConfig,
"external_aws_cloudwatch_metrics": in.Spec.ExternalAWSCloudwatchMetricsUserConfig,
"kafka_connect": in.Spec.KafkaConnectUserConfig,
"kafka_logs": in.Spec.KafkaLogsUserConfig,
"kafka_mirrormaker": in.Spec.KafkaMirrormakerUserConfig,
"logs": in.Spec.LogsUserConfig,
"metrics": in.Spec.MetricsUserConfig,
func (in *ServiceIntegration) getUserConfigFields() map[service.IntegrationType]any {
return map[service.IntegrationType]any{
service.IntegrationTypeClickhouseKafka: in.Spec.ClickhouseKafkaUserConfig,
service.IntegrationTypeClickhousePostgresql: in.Spec.ClickhousePostgreSQLUserConfig,
service.IntegrationTypeDatadog: in.Spec.DatadogUserConfig,
service.IntegrationTypeExternalAwsCloudwatchMetrics: in.Spec.ExternalAWSCloudwatchMetricsUserConfig,
service.IntegrationTypeKafkaConnect: in.Spec.KafkaConnectUserConfig,
service.IntegrationTypeKafkaLogs: in.Spec.KafkaLogsUserConfig,
service.IntegrationTypeKafkaMirrormaker: in.Spec.KafkaMirrormakerUserConfig,
service.IntegrationTypeLogs: in.Spec.LogsUserConfig,
service.IntegrationTypeMetrics: in.Spec.MetricsUserConfig,
}
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/serviceintegration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/aiven/aiven-go-client/v2"
avngen "github.com/aiven/go-client-codegen"
"github.com/aiven/go-client-codegen/handler/serviceintegration"
"github.com/aiven/go-client-codegen/handler/service"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -66,11 +66,11 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive
integration, err := avnGen.ServiceIntegrationCreate(
ctx,
si.Spec.Project,
&serviceintegration.ServiceIntegrationCreateIn{
&service.ServiceIntegrationCreateIn{
DestEndpointId: toPtr(si.Spec.DestinationEndpointID),
DestService: toPtr(si.Spec.DestinationServiceName),
DestProject: toPtr(si.Spec.DestinationProjectName),
IntegrationType: serviceintegration.IntegrationType(si.Spec.IntegrationType),
IntegrationType: si.Spec.IntegrationType,
SourceEndpointId: toPtr(si.Spec.SourceEndpointID),
SourceService: toPtr(si.Spec.SourceServiceName),
SourceProject: toPtr(si.Spec.SourceProjectName),
Expand All @@ -97,7 +97,7 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive
ctx,
si.Spec.Project,
si.Status.ID,
&serviceintegration.ServiceIntegrationUpdateIn{
&service.ServiceIntegrationUpdateIn{
UserConfig: userConfigMap,
},
)
Expand Down
8 changes: 4 additions & 4 deletions controllers/serviceintegrationendpoint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/aiven/aiven-go-client/v2"
avngen "github.com/aiven/go-client-codegen"
"github.com/aiven/go-client-codegen/handler/serviceintegration"
"github.com/aiven/go-client-codegen/handler/service"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -69,9 +69,9 @@ func (h ServiceIntegrationEndpointHandler) createOrUpdate(ctx context.Context, a
endpoint, err := avnGen.ServiceIntegrationEndpointCreate(
ctx,
si.Spec.Project,
&serviceintegration.ServiceIntegrationEndpointCreateIn{
&service.ServiceIntegrationEndpointCreateIn{
EndpointName: si.Spec.EndpointName,
EndpointType: serviceintegration.EndpointType(si.Spec.EndpointType),
EndpointType: service.EndpointType(si.Spec.EndpointType),
UserConfig: userConfigMap,
},
)
Expand All @@ -95,7 +95,7 @@ func (h ServiceIntegrationEndpointHandler) createOrUpdate(ctx context.Context, a
ctx,
si.Spec.Project,
si.Status.ID,
&serviceintegration.ServiceIntegrationEndpointUpdateIn{
&service.ServiceIntegrationEndpointUpdateIn{
UserConfig: userConfigMap,
},
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ClickHouse/clickhouse-go/v2 v2.28.2
github.com/aiven/aiven-go-client/v2 v2.26.0
github.com/aiven/go-api-schemas v1.85.0
github.com/aiven/go-client-codegen v0.27.0
github.com/aiven/go-client-codegen v0.31.0
github.com/dave/jennifer v1.7.1
github.com/docker/go-units v0.5.0
github.com/ghodss/yaml v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ github.com/aiven/aiven-go-client/v2 v2.26.0 h1:1dBlF0BULbPsRXEEmcKs71AE3VZ+AYt5z
github.com/aiven/aiven-go-client/v2 v2.26.0/go.mod h1:KdHfLIlIRZIfCSEBd39j1Q81jlSb6Nd+oCQKqERfnuA=
github.com/aiven/go-api-schemas v1.85.0 h1:wpTCQWjTLKQvVQq184u6Ji0ZksDZkNPqS6f6zrZ+nGU=
github.com/aiven/go-api-schemas v1.85.0/go.mod h1:/F7Rr8UVErsRxhgGN7CSo+Ac/uAg/OiAVCEKCfm3VAo=
github.com/aiven/go-client-codegen v0.27.0 h1:LSOrvMJUIRCTl2y6auiwtmKE3hzN1S/M5vxHTk58QaI=
github.com/aiven/go-client-codegen v0.27.0/go.mod h1:6AHM+oM2tNc10eOfPeyiTWFObkVz2dZY2gqRkTPQoVo=
github.com/aiven/go-client-codegen v0.31.0 h1:kFJnrdgVTmGoLfTnWV6Qxlzjg6APZ/321ApiOHLwIpM=
github.com/aiven/go-client-codegen v0.31.0/go.mod h1:FfbH32Xb+Hx5zeKTIug1Y8SfMeB+AKNRzxgrzkts2oA=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down
6 changes: 3 additions & 3 deletions tests/serviceintegrationendpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tests
import (
"testing"

"github.com/aiven/go-client-codegen/handler/serviceintegration"
"github.com/aiven/go-client-codegen/handler/service"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -39,7 +39,7 @@ func TestServiceIntegrationEndpointExternalPostgres(t *testing.T) {
// Validates ServiceIntegrationEndpoint externalPostgresql
endpointPg := new(v1alpha1.ServiceIntegrationEndpoint)
require.NoError(t, s.GetRunning(endpointPg, endpointPgName))
endpointPgAvn, err := avnGen.ServiceIntegrationEndpointGet(ctx, cfg.Project, endpointPg.Status.ID, serviceintegration.ServiceIntegrationEndpointGetIncludeSecrets(true))
endpointPgAvn, err := avnGen.ServiceIntegrationEndpointGet(ctx, cfg.Project, endpointPg.Status.ID, service.ServiceIntegrationEndpointGetIncludeSecrets(true))
require.NoError(t, err)
assert.Equal(t, "external_postgresql", string(endpointPgAvn.EndpointType))
assert.Equal(t, "username", endpointPg.Spec.ExternalPostgresql.Username)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestServiceIntegrationEndpoint(t *testing.T) {
// Validates ServiceIntegrationEndpoint externalSchemaRegistry
endpointRegistry := new(v1alpha1.ServiceIntegrationEndpoint)
require.NoError(t, s.GetRunning(endpointRegistry, endpointRegistryName))
endpointRegistryAvn, err := avnGen.ServiceIntegrationEndpointGet(ctx, cfg.Project, endpointRegistry.Status.ID, serviceintegration.ServiceIntegrationEndpointGetIncludeSecrets(true))
endpointRegistryAvn, err := avnGen.ServiceIntegrationEndpointGet(ctx, cfg.Project, endpointRegistry.Status.ID, service.ServiceIntegrationEndpointGetIncludeSecrets(true))
require.NoError(t, err)
assert.Equal(t, "external_schema_registry", string(endpointRegistryAvn.EndpointType))
assert.Equal(t, "https://schema-registry.example.com:8081", endpointRegistry.Spec.ExternalSchemaRegistry.Url)
Expand Down
8 changes: 0 additions & 8 deletions tests/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,3 @@ func parseObjs(src string) (map[string]client.Object, error) {
}
return objs, nil
}

func ptrValue[T any](v *T) T {
if v == nil {
var empty T
return empty
}
return *v
}
Loading