From 47fcdec403904189e9d4e44da113895f8be9e60e Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Thu, 25 Jul 2024 12:14:37 +0200 Subject: [PATCH] refactor: use gen client to check service is operational --- controllers/clickhousedatabase_controller.go | 2 +- controllers/clickhousegrant_controller.go | 2 +- controllers/clickhouserole_controller.go | 2 +- controllers/clickhouseuser_controller.go | 2 +- controllers/common.go | 2 +- controllers/connectionpool_controller.go | 2 +- controllers/database_controller.go | 2 +- controllers/generic_service_handler.go | 2 +- controllers/kafkaacl_controller.go | 2 +- controllers/kafkaconnector_controller.go | 2 +- controllers/kafkaschema_controller.go | 2 +- controllers/kafkaschemaregistryacl_controller.go | 2 +- controllers/serviceintegration_controller.go | 4 ++-- controllers/serviceuser_controller.go | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/controllers/clickhousedatabase_controller.go b/controllers/clickhousedatabase_controller.go index 3a92f3f5..fb47b1ff 100644 --- a/controllers/clickhousedatabase_controller.go +++ b/controllers/clickhousedatabase_controller.go @@ -115,7 +115,7 @@ func (h *ClickhouseDatabaseHandler) checkPreconditions(ctx context.Context, avn meta.SetStatusCondition(&db.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, db.Spec.Project, db.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, db.Spec.Project, db.Spec.ServiceName) } func (h *ClickhouseDatabaseHandler) convert(i client.Object) (*v1alpha1.ClickhouseDatabase, error) { diff --git a/controllers/clickhousegrant_controller.go b/controllers/clickhousegrant_controller.go index bf3415bc..f79a2690 100644 --- a/controllers/clickhousegrant_controller.go +++ b/controllers/clickhousegrant_controller.go @@ -125,7 +125,7 @@ func (h *ClickhouseGrantHandler) checkPreconditions(ctx context.Context, avn *ai meta.SetStatusCondition(&g.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - serviceIsRunning, err := checkServiceIsOperational(ctx, avn, avnGen, g.Spec.Project, g.Spec.ServiceName) + serviceIsRunning, err := checkServiceIsOperational(ctx, avnGen, g.Spec.Project, g.Spec.ServiceName) if !serviceIsRunning || err != nil { return false, err } diff --git a/controllers/clickhouserole_controller.go b/controllers/clickhouserole_controller.go index c7b70e4e..63700042 100644 --- a/controllers/clickhouserole_controller.go +++ b/controllers/clickhouserole_controller.go @@ -111,7 +111,7 @@ func (h *clickhouseRoleHandler) checkPreconditions(ctx context.Context, avn *aiv meta.SetStatusCondition(&role.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, role.Spec.Project, role.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, role.Spec.Project, role.Spec.ServiceName) } func (h *clickhouseRoleHandler) convert(i client.Object) (*v1alpha1.ClickhouseRole, error) { diff --git a/controllers/clickhouseuser_controller.go b/controllers/clickhouseuser_controller.go index 728e90f4..0b635ccd 100644 --- a/controllers/clickhouseuser_controller.go +++ b/controllers/clickhouseuser_controller.go @@ -156,7 +156,7 @@ func (h *clickhouseUserHandler) checkPreconditions(ctx context.Context, avn *aiv meta.SetStatusCondition(&user.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, user.Spec.Project, user.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, user.Spec.Project, user.Spec.ServiceName) } func (h *clickhouseUserHandler) convert(i client.Object) (*v1alpha1.ClickhouseUser, error) { diff --git a/controllers/common.go b/controllers/common.go index 0c81de74..6d2c50ea 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -48,7 +48,7 @@ const ( var errTerminationProtectionOn = errors.New("termination protection is on") -func checkServiceIsOperational(ctx context.Context, _ *aiven.Client, avnGen avngen.Client, project, serviceName string) (bool, error) { +func checkServiceIsOperational(ctx context.Context, avnGen avngen.Client, project, serviceName string) (bool, error) { s, err := avnGen.ServiceGet(ctx, project, serviceName) if err != nil { // if service is not found, it is not running diff --git a/controllers/connectionpool_controller.go b/controllers/connectionpool_controller.go index 95a03508..3813af87 100644 --- a/controllers/connectionpool_controller.go +++ b/controllers/connectionpool_controller.go @@ -211,7 +211,7 @@ func (h ConnectionPoolHandler) checkPreconditions(ctx context.Context, avn *aive meta.SetStatusCondition(&cp.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - isRunning, err := checkServiceIsOperational(ctx, avn, avnGen, cp.Spec.Project, cp.Spec.ServiceName) + isRunning, err := checkServiceIsOperational(ctx, avnGen, cp.Spec.Project, cp.Spec.ServiceName) if err != nil { return false, err } diff --git a/controllers/database_controller.go b/controllers/database_controller.go index 1c371d65..041f5729 100644 --- a/controllers/database_controller.go +++ b/controllers/database_controller.go @@ -136,7 +136,7 @@ func (h DatabaseHandler) checkPreconditions(ctx context.Context, avn *aiven.Clie meta.SetStatusCondition(&db.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, db.Spec.Project, db.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, db.Spec.Project, db.Spec.ServiceName) } func (h DatabaseHandler) convert(i client.Object) (*v1alpha1.Database, error) { diff --git a/controllers/generic_service_handler.go b/controllers/generic_service_handler.go index 4b4da58d..0ed24d10 100644 --- a/controllers/generic_service_handler.go +++ b/controllers/generic_service_handler.go @@ -232,7 +232,7 @@ func (h *genericServiceHandler) checkPreconditions(ctx context.Context, avn *aiv // Validates that read_replica is running // If not, the wrapper controller will try later if s.IntegrationType == "read_replica" { - r, err := checkServiceIsOperational(ctx, avn, avnGen, spec.Project, s.SourceServiceName) + r, err := checkServiceIsOperational(ctx, avnGen, spec.Project, s.SourceServiceName) if !r || err != nil { return false, err } diff --git a/controllers/kafkaacl_controller.go b/controllers/kafkaacl_controller.go index 124d9515..dbb13de8 100644 --- a/controllers/kafkaacl_controller.go +++ b/controllers/kafkaacl_controller.go @@ -165,7 +165,7 @@ func (h KafkaACLHandler) checkPreconditions(ctx context.Context, avn *aiven.Clie meta.SetStatusCondition(&acl.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, acl.Spec.Project, acl.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, acl.Spec.Project, acl.Spec.ServiceName) } func (h KafkaACLHandler) convert(i client.Object) (*v1alpha1.KafkaACL, error) { diff --git a/controllers/kafkaconnector_controller.go b/controllers/kafkaconnector_controller.go index 723ad542..9fb84031 100644 --- a/controllers/kafkaconnector_controller.go +++ b/controllers/kafkaconnector_controller.go @@ -220,7 +220,7 @@ func (h KafkaConnectorHandler) checkPreconditions(ctx context.Context, avn *aive meta.SetStatusCondition(&conn.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, conn.Spec.Project, conn.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, conn.Spec.Project, conn.Spec.ServiceName) } func (h KafkaConnectorHandler) convert(o client.Object) (*v1alpha1.KafkaConnector, error) { diff --git a/controllers/kafkaschema_controller.go b/controllers/kafkaschema_controller.go index 46993a77..d103a2d8 100644 --- a/controllers/kafkaschema_controller.go +++ b/controllers/kafkaschema_controller.go @@ -134,7 +134,7 @@ func (h KafkaSchemaHandler) checkPreconditions(ctx context.Context, avn *aiven.C return false, err } - return checkServiceIsOperational(ctx, avn, avnGen, schema.Spec.Project, schema.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, schema.Spec.Project, schema.Spec.ServiceName) } func (h KafkaSchemaHandler) convert(i client.Object) (*v1alpha1.KafkaSchema, error) { diff --git a/controllers/kafkaschemaregistryacl_controller.go b/controllers/kafkaschemaregistryacl_controller.go index 2e6ef5e1..41f89097 100644 --- a/controllers/kafkaschemaregistryacl_controller.go +++ b/controllers/kafkaschemaregistryacl_controller.go @@ -157,7 +157,7 @@ func (h KafkaSchemaRegistryACLHandler) checkPreconditions(ctx context.Context, a meta.SetStatusCondition(&acl.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, acl.Spec.Project, acl.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, acl.Spec.Project, acl.Spec.ServiceName) } func (h KafkaSchemaRegistryACLHandler) convert(i client.Object) (*v1alpha1.KafkaSchemaRegistryACL, error) { diff --git a/controllers/serviceintegration_controller.go b/controllers/serviceintegration_controller.go index 8867e773..b0ab636d 100644 --- a/controllers/serviceintegration_controller.go +++ b/controllers/serviceintegration_controller.go @@ -174,7 +174,7 @@ func (h ServiceIntegrationHandler) checkPreconditions(ctx context.Context, avn * if project == "" { project = si.Spec.Project } - running, err := checkServiceIsOperational(ctx, avn, avnGen, project, si.Spec.SourceServiceName) + running, err := checkServiceIsOperational(ctx, avnGen, project, si.Spec.SourceServiceName) if !running || err != nil { return false, err } @@ -185,7 +185,7 @@ func (h ServiceIntegrationHandler) checkPreconditions(ctx context.Context, avn * if project == "" { project = si.Spec.Project } - running, err := checkServiceIsOperational(ctx, avn, avnGen, project, si.Spec.DestinationServiceName) + running, err := checkServiceIsOperational(ctx, avnGen, project, si.Spec.DestinationServiceName) if !running || err != nil { return false, err } diff --git a/controllers/serviceuser_controller.go b/controllers/serviceuser_controller.go index 8bc5342a..d378cad9 100644 --- a/controllers/serviceuser_controller.go +++ b/controllers/serviceuser_controller.go @@ -161,7 +161,7 @@ func (h ServiceUserHandler) checkPreconditions(ctx context.Context, avn *aiven.C meta.SetStatusCondition(&user.Status.Conditions, getInitializedCondition("Preconditions", "Checking preconditions")) - return checkServiceIsOperational(ctx, avn, avnGen, user.Spec.Project, user.Spec.ServiceName) + return checkServiceIsOperational(ctx, avnGen, user.Spec.Project, user.Spec.ServiceName) } func (h ServiceUserHandler) convert(i client.Object) (*v1alpha1.ServiceUser, error) {