Skip to content

Commit

Permalink
feat: use generated go client in service integrations controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rriski committed Feb 12, 2024
1 parent 93a37d5 commit e9cb349
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
)

func checkServiceIsRunning(ctx context.Context, avn *aiven.Client, avnGen avngen.Client, project, serviceName string) (bool, error) {
s, err := avn.Services.Get(ctx, project, serviceName)
s, err := avnGen.ServiceGet(ctx, project, serviceName)
if err != nil {
// if service is not found, it is not running
if aiven.IsNotFound(err) {
Expand Down
29 changes: 14 additions & 15 deletions controllers/serviceintegration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive
}

var reason string
var integration *aiven.ServiceIntegration
if si.Status.ID == "" {
userConfigMap, err := CreateUserConfiguration(userConfig)
if err != nil {
return err
}

integration, err = avn.ServiceIntegrations.Create(
integration, err := avnGen.ServiceIntegrationCreate(
ctx,
si.Spec.Project,
aiven.CreateServiceIntegrationRequest{
DestinationEndpointID: anyOptional(si.Spec.DestinationEndpointID),
DestinationService: anyOptional(si.Spec.DestinationServiceName),
DestinationProject: anyOptional(si.Spec.DestinationProjectName),
IntegrationType: si.Spec.IntegrationType,
SourceEndpointID: anyOptional(si.Spec.SourceEndpointID),
SourceService: anyOptional(si.Spec.SourceServiceName),
SourceProject: anyOptional(si.Spec.SourceProjectName),
UserConfig: userConfigMap,
&serviceintegration.ServiceIntegrationCreateIn{
DestEndpointId: si.Spec.DestinationEndpointID,
DestService: si.Spec.DestinationServiceName,
DestProject: si.Spec.DestinationProjectName,
IntegrationType: serviceintegration.IntegrationType(si.Spec.IntegrationType),
SourceEndpointId: si.Spec.SourceEndpointID,
SourceService: si.Spec.SourceServiceName,
SourceProject: si.Spec.SourceProjectName,
UserConfig: &userConfigMap,
},
)
if err != nil {
return fmt.Errorf("cannot createOrUpdate service integration: %w", err)
}

reason = "Created"
si.Status.ID = integration.ServiceIntegrationId
} else {
// Not all service integrations have user_config available; skip the update if user_config is unavailable.
withUserConfig := []string{"clickhouse_kafka", "clickhouse_postgresql", "datadog", "kafka_connect", "kafka_logs", "kafka_mirrormaker", "logs", "metrics", "external_aws_cloudwatch_metrics"}
Expand All @@ -91,11 +91,11 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive
return err
}

integration, err = avn.ServiceIntegrations.Update(
updatedIntegration, err := avnGen.ServiceIntegrationUpdate(
ctx,
si.Spec.Project,
si.Status.ID,
aiven.UpdateServiceIntegrationRequest{
&serviceintegration.ServiceIntegrationUpdateIn{
UserConfig: userConfigMap,
},
)
Expand All @@ -106,10 +106,9 @@ func (h ServiceIntegrationHandler) createOrUpdate(ctx context.Context, avn *aive
}
return err
}
si.Status.ID = updatedIntegration.ServiceIntegrationId
}

si.Status.ID = integration.ServiceIntegrationID

meta.SetStatusCondition(&si.Status.Conditions,
getInitializedCondition(reason,
"Instance was created or update on Aiven side"))
Expand Down

0 comments on commit e9cb349

Please sign in to comment.