From 7f830503f63fdb1ebda996b2c3d4b139a502649d Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Fri, 13 Sep 2024 14:54:56 +0200 Subject: [PATCH] chore: uses service module from the gen client --- api/v1alpha1/serviceintegration_types.go | 25 ++++++++++--------- controllers/serviceintegration_controller.go | 8 +++--- .../serviceintegrationendpoint_controller.go | 8 +++--- go.mod | 2 +- go.sum | 4 +-- tests/serviceintegrationendpoint_test.go | 6 ++--- tests/session.go | 8 ------ 7 files changed, 27 insertions(+), 34 deletions(-) diff --git a/api/v1alpha1/serviceintegration_types.go b/api/v1alpha1/serviceintegration_types.go index 44a49f96..2519496a 100644 --- a/api/v1alpha1/serviceintegration_types.go +++ b/api/v1alpha1/serviceintegration_types.go @@ -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" @@ -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 @@ -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, } } diff --git a/controllers/serviceintegration_controller.go b/controllers/serviceintegration_controller.go index b0ab636d..c88dae9c 100644 --- a/controllers/serviceintegration_controller.go +++ b/controllers/serviceintegration_controller.go @@ -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" @@ -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), @@ -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, }, ) diff --git a/controllers/serviceintegrationendpoint_controller.go b/controllers/serviceintegrationendpoint_controller.go index 1ec73201..c8b49251 100644 --- a/controllers/serviceintegrationendpoint_controller.go +++ b/controllers/serviceintegrationendpoint_controller.go @@ -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" @@ -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, }, ) @@ -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, }, ) diff --git a/go.mod b/go.mod index 23435e31..e3f071dc 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e436a3f4..155bb06f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tests/serviceintegrationendpoint_test.go b/tests/serviceintegrationendpoint_test.go index bc172187..1fa0dfdb 100644 --- a/tests/serviceintegrationendpoint_test.go +++ b/tests/serviceintegrationendpoint_test.go @@ -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" @@ -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) @@ -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) diff --git a/tests/session.go b/tests/session.go index a9d318ea..dea60544 100644 --- a/tests/session.go +++ b/tests/session.go @@ -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 -}