diff --git a/docs/docs/api-reference/examples/serviceintegration.autoscaler.yaml b/docs/docs/api-reference/examples/serviceintegration.autoscaler.yaml new file mode 100644 index 00000000..dd9c4ba5 --- /dev/null +++ b/docs/docs/api-reference/examples/serviceintegration.autoscaler.yaml @@ -0,0 +1,29 @@ +apiVersion: aiven.io/v1alpha1 +kind: ServiceIntegration +metadata: + name: my-service-integration +spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + integrationType: autoscaler + sourceServiceName: my-pg + # Look up autoscaler integration endpoint ID via Console + destinationEndpointId: my-destination-endpoint-id + +--- + +apiVersion: aiven.io/v1alpha1 +kind: PostgreSQL +metadata: + name: my-pg +spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + cloudName: google-europe-west1 + plan: startup-4 diff --git a/docs/docs/api-reference/examples/serviceintegrationendpoint.autoscaler.yaml b/docs/docs/api-reference/examples/serviceintegrationendpoint.autoscaler.yaml new file mode 100644 index 00000000..299d1b1a --- /dev/null +++ b/docs/docs/api-reference/examples/serviceintegrationendpoint.autoscaler.yaml @@ -0,0 +1,17 @@ +apiVersion: aiven.io/v1alpha1 +kind: ServiceIntegrationEndpoint +metadata: + name: my-service-integration-endpoint +spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + endpointName: my-autoscaler + endpointType: autoscaler + + autoscaler: + autoscaling: + - type: autoscale_disk + cap_gb: 100 diff --git a/docs/docs/api-reference/serviceintegration.md b/docs/docs/api-reference/serviceintegration.md index 8f37c469..d2bea8f8 100644 --- a/docs/docs/api-reference/serviceintegration.md +++ b/docs/docs/api-reference/serviceintegration.md @@ -4,6 +4,59 @@ title: "ServiceIntegration" ## Usage examples +??? example "autoscaler" + ```yaml + apiVersion: aiven.io/v1alpha1 + kind: ServiceIntegration + metadata: + name: my-service-integration + spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + integrationType: autoscaler + sourceServiceName: my-pg + # Specify autoscaler integration endpoint ID + destinationEndpointId: e8417f8c-513f-487a-9213-5a903a8e62d9 + + --- + + apiVersion: aiven.io/v1alpha1 + kind: ServiceIntegrationEndpoint + metadata: + name: my-service-integration-endpoint + spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + endpointName: my-autoscaler + endpointType: autoscaler + + autoscaler: + autoscaling: + - type: autoscale_disk + cap_gb: 100 + + --- + + apiVersion: aiven.io/v1alpha1 + kind: PostgreSQL + metadata: + name: my-pg + spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + cloudName: google-europe-west1 + plan: startup-4 + ``` + ??? example "clickhouse_postgresql" ```yaml apiVersion: aiven.io/v1alpha1 @@ -225,8 +278,8 @@ kubectl get serviceintegrations my-service-integration The output is similar to the following: ```shell -Name Project Type Source Service Name Destination Service Name -my-service-integration aiven-project-name clickhouse_postgresql my-pg my-clickhouse +Name Project Type Source Service Name Destination Endpoint ID +my-service-integration aiven-project-name autoscaler my-pg e8417f8c-513f-487a-9213-5a903a8e62d9 ``` ## ServiceIntegration {: #ServiceIntegration } diff --git a/docs/docs/api-reference/serviceintegrationendpoint.md b/docs/docs/api-reference/serviceintegrationendpoint.md index 10144680..8e048fc2 100644 --- a/docs/docs/api-reference/serviceintegrationendpoint.md +++ b/docs/docs/api-reference/serviceintegrationendpoint.md @@ -4,6 +4,27 @@ title: "ServiceIntegrationEndpoint" ## Usage examples +??? example "autoscaler" + ```yaml + apiVersion: aiven.io/v1alpha1 + kind: ServiceIntegrationEndpoint + metadata: + name: my-service-integration-endpoint + spec: + authSecretRef: + name: aiven-token + key: token + + project: aiven-project-name + endpointName: my-autoscaler + endpointType: autoscaler + + autoscaler: + autoscaling: + - type: autoscale_disk + cap_gb: 100 + ``` + ??? example "external_postgresql" ```yaml apiVersion: aiven.io/v1alpha1 @@ -66,8 +87,8 @@ kubectl get serviceintegrationendpoints my-service-integration-endpoint The output is similar to the following: ```shell -Name Project Endpoint Name Endpoint Type ID -my-service-integration-endpoint aiven-project-name my-external-postgresql external_postgresql +Name Project Endpoint Name Endpoint Type ID +my-service-integration-endpoint aiven-project-name my-autoscaler autoscaler ``` ## ServiceIntegrationEndpoint {: #ServiceIntegrationEndpoint } diff --git a/tests/serviceintegration_test.go b/tests/serviceintegration_test.go index ee164f74..cc6ed15c 100644 --- a/tests/serviceintegration_test.go +++ b/tests/serviceintegration_test.go @@ -225,6 +225,64 @@ func TestServiceIntegrationKafkaConnect(t *testing.T) { assert.Equal(t, "__connect_offsets", *si.Spec.KafkaConnectUserConfig.KafkaConnect.OffsetStorageTopic) } +func TestServiceIntegrationAutoscaler(t *testing.T) { + t.Parallel() + defer recoverPanic(t) + + endpointID := os.Getenv("AUTOSCALER_ENDPOINT_ID") + if endpointID == "" { + t.Skip("Provide AUTOSCALER_ENDPOINT_ID for this test") + } + + // GIVEN + ctx, cancel := testCtx() + defer cancel() + + pgName := randName("postgresql") + siName := randName("autoscaler") + + yml, err := loadExampleYaml("serviceintegration.autoscaler.yaml", map[string]string{ + "aiven-project-name": cfg.Project, + "google-europe-west1": cfg.PrimaryCloudName, + "my-pg": pgName, + "my-service-integration": siName, + "my-destination-endpoint-id": endpointID, + }) + require.NoError(t, err) + s := NewSession(ctx, k8sClient, cfg.Project) + + // Cleans test afterward + defer s.Destroy(t) + + // WHEN + // Applies given manifest + require.NoError(t, s.Apply(yml)) + + // Waits kube objects + pg := new(v1alpha1.PostgreSQL) + require.NoError(t, s.GetRunning(pg, pgName)) + + si := new(v1alpha1.ServiceIntegration) + require.NoError(t, s.GetRunning(si, siName)) + + // THEN + // Validates PostgreSQL + pgAvn, err := avnGen.ServiceGet(ctx, cfg.Project, pgName) + require.NoError(t, err) + assert.Equal(t, pgAvn.ServiceName, pg.GetName()) + assert.Contains(t, serviceRunningStatesAiven, pgAvn.State) + + // Validates ServiceIntegration + siAvn, err := avnGen.ServiceIntegrationGet(ctx, cfg.Project, si.Status.ID) + require.NoError(t, err) + assert.EqualValues(t, "autoscaler", siAvn.IntegrationType) + assert.EqualValues(t, siAvn.IntegrationType, si.Spec.IntegrationType) + assert.Equal(t, pgName, siAvn.SourceService) + assert.Equal(t, endpointID, *siAvn.DestEndpointId) + assert.True(t, siAvn.Active) + assert.True(t, siAvn.Enabled) +} + // todo: refactor when ServiceIntegrationEndpoint released func TestServiceIntegrationDatadog(t *testing.T) { t.Parallel() diff --git a/tests/serviceintegrationendpoint_test.go b/tests/serviceintegrationendpoint_test.go index 1fa0dfdb..59a4f87f 100644 --- a/tests/serviceintegrationendpoint_test.go +++ b/tests/serviceintegrationendpoint_test.go @@ -95,3 +95,45 @@ func TestServiceIntegrationEndpoint(t *testing.T) { assert.EqualValues(t, endpointRegistryAvn.UserConfig["basic_auth_username"], *endpointRegistry.Spec.ExternalSchemaRegistry.BasicAuthUsername) assert.EqualValues(t, endpointRegistryAvn.UserConfig["basic_auth_password"], *endpointRegistry.Spec.ExternalSchemaRegistry.BasicAuthPassword) } + +func TestServiceIntegrationEndpointAutoscaler(t *testing.T) { + t.Parallel() + defer recoverPanic(t) + + // GIVEN + ctx, cancel := testCtx() + defer cancel() + + endpointName := randName("autoscaler") + + yml, err := loadExampleYaml("serviceintegrationendpoint.autoscaler.yaml", map[string]string{ + "aiven-project-name": cfg.Project, + "my-service-integration-endpoint": endpointName, + }) + require.NoError(t, err) + s := NewSession(ctx, k8sClient, cfg.Project) + + // Cleans test afterward + defer s.Destroy(t) + + // WHEN + // Applies given manifest + require.NoError(t, s.Apply(yml)) + + // THEN + + // Validates autoscaler ServiceIntegrationEndpoint + endpointAutoscaler := new(v1alpha1.ServiceIntegrationEndpoint) + require.NoError(t, s.GetRunning(endpointAutoscaler, endpointName)) + + endpointAvn, err := avnGen.ServiceIntegrationEndpointGet(ctx, cfg.Project, endpointAutoscaler.Status.ID, service.ServiceIntegrationEndpointGetIncludeSecrets(true)) + require.NoError(t, err) + + assert.EqualValues(t, "autoscaler", endpointAvn.EndpointType) + assert.EqualValues(t, endpointAvn.EndpointType, endpointAutoscaler.Spec.EndpointType) + // TODO: remove type assertions once generated client has full user config typing + assert.EqualValues(t, "autoscale_disk", endpointAutoscaler.Spec.Autoscaler.Autoscaling[0].Type) + assert.EqualValues(t, "autoscale_disk", endpointAvn.UserConfig["autoscaling"].([]interface{})[0].(map[string]interface{})["type"]) + assert.EqualValues(t, 100, endpointAutoscaler.Spec.Autoscaler.Autoscaling[0].CapGb) + assert.EqualValues(t, 100, endpointAvn.UserConfig["autoscaling"].([]interface{})[0].(map[string]interface{})["cap_gb"]) +}