From 5aef57b6fd881baaa0cd51d7db8e08645cd3504d Mon Sep 17 00:00:00 2001 From: Gabriel Saratura Date: Tue, 29 Oct 2024 14:07:18 +0100 Subject: [PATCH 1/2] Fix pg config --- pkg/comp-functions/functions/vshnpostgres/extensions.go | 8 ++++---- .../functions/vshnpostgres/extensions_test.go | 4 ++-- .../functions/vshnpostgres/postgresql_deploy.go | 2 +- .../functions/vshnpostgres/postgresql_deploy_test.go | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/comp-functions/functions/vshnpostgres/extensions.go b/pkg/comp-functions/functions/vshnpostgres/extensions.go index 1b027e53e..93780cf1e 100644 --- a/pkg/comp-functions/functions/vshnpostgres/extensions.go +++ b/pkg/comp-functions/functions/vshnpostgres/extensions.go @@ -52,7 +52,7 @@ func AddExtensions(ctx context.Context, comp *vshnv1.VSHNPostgreSQL, svc *runtim return runtime.NewFatalResult(fmt.Errorf("cannot add timescaldb to config: %w", err)) } } else { - err := disableTimescaleDB(ctx, svc) + err := disableTimescaleDB(ctx, svc, comp.GetName()) if err != nil { return runtime.NewFatalResult(fmt.Errorf("cannot ensure timescaldb absent from config: %w", err)) } @@ -105,10 +105,10 @@ func enableTimescaleDB(ctx context.Context, svc *runtime.ServiceRuntime, name st config.Spec.PostgresqlConf[sharedLibraries] = fmt.Sprintf("%s,%s", toAppend, timescaleExtName) } - return svc.SetDesiredKubeObjectWithName(config, name+"-"+configResourceName, configResourceName) + return svc.SetDesiredKubeObject(config, name+"-"+configResourceName) } -func disableTimescaleDB(ctx context.Context, svc *runtime.ServiceRuntime) error { +func disableTimescaleDB(ctx context.Context, svc *runtime.ServiceRuntime, name string) error { config := &stackgresv1.SGPostgresConfig{} @@ -135,5 +135,5 @@ func disableTimescaleDB(ctx context.Context, svc *runtime.ServiceRuntime) error config.Spec.PostgresqlConf[sharedLibraries] = strings.Join(finalElements, ", ") - return svc.SetDesiredKubeObject(config, configResourceName) + return svc.SetDesiredKubeObject(config, name+"-"+configResourceName) } diff --git a/pkg/comp-functions/functions/vshnpostgres/extensions_test.go b/pkg/comp-functions/functions/vshnpostgres/extensions_test.go index f95260b4c..d434203ee 100644 --- a/pkg/comp-functions/functions/vshnpostgres/extensions_test.go +++ b/pkg/comp-functions/functions/vshnpostgres/extensions_test.go @@ -50,7 +50,7 @@ func Test_enableTimescaleDB(t *testing.T) { config := &stackgresv1.SGPostgresConfig{} - assert.NoError(t, svc.GetDesiredKubeObject(config, configResourceName)) + assert.NoError(t, svc.GetDesiredKubeObject(config, comp.GetName()+"-"+configResourceName)) assert.Contains(t, config.Spec.PostgresqlConf[sharedLibraries], timescaleExtName) @@ -81,7 +81,7 @@ func Test_disableTimescaleDB(t *testing.T) { svc := commontest.LoadRuntimeFromFile(t, tt.iofFile) t.Run(tt.name, func(t *testing.T) { - if err := disableTimescaleDB(ctx, svc); (err != nil) != tt.wantErr { + if err := disableTimescaleDB(ctx, svc, configResourceName); (err != nil) != tt.wantErr { t.Errorf("disableTimescaleDB() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy.go b/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy.go index 36df5ca6f..2e1f7870c 100644 --- a/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy.go +++ b/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy.go @@ -334,7 +334,7 @@ func createSgPostgresConfig(comp *vshnv1.VSHNPostgreSQL, svc *runtime.ServiceRun }, } - err := svc.SetDesiredKubeObjectWithName(sgPostgresConfig, comp.GetName()+"-pgconf", "pg-conf") + err := svc.SetDesiredKubeObject(sgPostgresConfig, comp.GetName()+"-"+configResourceName) if err != nil { err = fmt.Errorf("cannot create sgInstanceProfile: %w", err) return err diff --git a/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy_test.go b/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy_test.go index bbe964d89..8ce0cee33 100644 --- a/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy_test.go +++ b/pkg/comp-functions/functions/vshnpostgres/postgresql_deploy_test.go @@ -82,7 +82,7 @@ func TestPostgreSqlDeploy(t *testing.T) { assert.Nil(t, sgInstanceProfile.Spec.HugePages) sgPostgresConfig := &sgv1.SGPostgresConfig{} - assert.NoError(t, svc.GetDesiredKubeObject(sgPostgresConfig, "pg-conf")) + assert.NoError(t, svc.GetDesiredKubeObject(sgPostgresConfig, comp.GetName()+"-"+configResourceName)) assert.Equal(t, comp.Spec.Parameters.Service.MajorVersion, sgPostgresConfig.Spec.PostgresVersion) assert.Equal(t, map[string]string{}, sgPostgresConfig.Spec.PostgresqlConf) @@ -113,7 +113,7 @@ func TestPostgreSqlDeployWithPgConfig(t *testing.T) { assert.NoError(t, svc.GetDesiredKubeObject(cluster, "cluster")) sgPostgresConfig := &sgv1.SGPostgresConfig{} - assert.NoError(t, svc.GetDesiredKubeObject(sgPostgresConfig, "pg-conf")) + assert.NoError(t, svc.GetDesiredKubeObject(sgPostgresConfig, "pgsql-gc9x4-"+configResourceName)) assert.Contains(t, sgPostgresConfig.Spec.PostgresqlConf, "timezone") assert.Equal(t, "Europe/Zurich", sgPostgresConfig.Spec.PostgresqlConf["timezone"]) } From d7eb68bd8e34738002613ffb7e908e07323f9682 Mon Sep 17 00:00:00 2001 From: Gabriel Saratura Date: Tue, 29 Oct 2024 14:48:21 +0100 Subject: [PATCH 2/2] Rename billing comp function --- pkg/comp-functions/functions/vshnkeycloak/billing.go | 4 ++-- pkg/comp-functions/functions/vshnkeycloak/register.go | 2 +- pkg/comp-functions/functions/vshnmariadb/billing.go | 4 ++-- pkg/comp-functions/functions/vshnmariadb/register.go | 2 +- pkg/comp-functions/functions/vshnminio/billing.go | 4 ++-- pkg/comp-functions/functions/vshnminio/register.go | 2 +- pkg/comp-functions/functions/vshnnextcloud/billing.go | 4 ++-- pkg/comp-functions/functions/vshnnextcloud/register.go | 2 +- pkg/comp-functions/functions/vshnpostgres/billing.go | 4 ++-- pkg/comp-functions/functions/vshnpostgres/register.go | 2 +- pkg/comp-functions/functions/vshnredis/billing.go | 4 ++-- pkg/comp-functions/functions/vshnredis/register.go | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pkg/comp-functions/functions/vshnkeycloak/billing.go b/pkg/comp-functions/functions/vshnkeycloak/billing.go index b3594b495..ebb3f1fcc 100644 --- a/pkg/comp-functions/functions/vshnkeycloak/billing.go +++ b/pkg/comp-functions/functions/vshnkeycloak/billing.go @@ -9,8 +9,8 @@ import ( "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" ) -// AddServiceBillingLabel adds billingLabel to all the objects of a services that must be billed -func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNKeycloak, svc *runtime.ServiceRuntime) *xfnproto.Result { +// AddBilling enables billing for this service +func AddBilling(ctx context.Context, comp *v1.VSHNKeycloak, svc *runtime.ServiceRuntime) *xfnproto.Result { err := svc.GetObservedComposite(comp) if err != nil { return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) diff --git a/pkg/comp-functions/functions/vshnkeycloak/register.go b/pkg/comp-functions/functions/vshnkeycloak/register.go index 695fa6cd1..b03ae5efc 100644 --- a/pkg/comp-functions/functions/vshnkeycloak/register.go +++ b/pkg/comp-functions/functions/vshnkeycloak/register.go @@ -41,7 +41,7 @@ func init() { }, { Name: "billing", - Execute: AddServiceBillingLabel, + Execute: AddBilling, }, }, }) diff --git a/pkg/comp-functions/functions/vshnmariadb/billing.go b/pkg/comp-functions/functions/vshnmariadb/billing.go index 96e8ad8a6..8d2ae1023 100644 --- a/pkg/comp-functions/functions/vshnmariadb/billing.go +++ b/pkg/comp-functions/functions/vshnmariadb/billing.go @@ -9,8 +9,8 @@ import ( "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" ) -// AddServiceBillingLabel adds billingLabel to all the objects of a services that must be billed -func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNMariaDB, svc *runtime.ServiceRuntime) *xfnproto.Result { +// AddBilling enables billing for this service +func AddBilling(ctx context.Context, comp *v1.VSHNMariaDB, svc *runtime.ServiceRuntime) *xfnproto.Result { err := svc.GetObservedComposite(comp) if err != nil { return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) diff --git a/pkg/comp-functions/functions/vshnmariadb/register.go b/pkg/comp-functions/functions/vshnmariadb/register.go index 4fe1f57ec..61d9188fe 100644 --- a/pkg/comp-functions/functions/vshnmariadb/register.go +++ b/pkg/comp-functions/functions/vshnmariadb/register.go @@ -37,7 +37,7 @@ func init() { }, { Name: "billing", - Execute: AddServiceBillingLabel, + Execute: AddBilling, }, { Name: "user-management", diff --git a/pkg/comp-functions/functions/vshnminio/billing.go b/pkg/comp-functions/functions/vshnminio/billing.go index 78eeaacd0..12063b271 100644 --- a/pkg/comp-functions/functions/vshnminio/billing.go +++ b/pkg/comp-functions/functions/vshnminio/billing.go @@ -9,8 +9,8 @@ import ( "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" ) -// AddServiceBillingLabel adds billingLabel to all the objects of a services that must be billed -func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNMinio, svc *runtime.ServiceRuntime) *xfnproto.Result { +// AddBilling enables billing for this service +func AddBilling(ctx context.Context, comp *v1.VSHNMinio, svc *runtime.ServiceRuntime) *xfnproto.Result { err := svc.GetObservedComposite(comp) if err != nil { return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) diff --git a/pkg/comp-functions/functions/vshnminio/register.go b/pkg/comp-functions/functions/vshnminio/register.go index 4ebf7ddd5..4d55e6a0f 100644 --- a/pkg/comp-functions/functions/vshnminio/register.go +++ b/pkg/comp-functions/functions/vshnminio/register.go @@ -45,7 +45,7 @@ func init() { }, { Name: "billing", - Execute: AddServiceBillingLabel, + Execute: AddBilling, }, }, }) diff --git a/pkg/comp-functions/functions/vshnnextcloud/billing.go b/pkg/comp-functions/functions/vshnnextcloud/billing.go index d81b38277..53920bb62 100644 --- a/pkg/comp-functions/functions/vshnnextcloud/billing.go +++ b/pkg/comp-functions/functions/vshnnextcloud/billing.go @@ -9,8 +9,8 @@ import ( "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" ) -// AddServiceBillingLabel adds billingLabel to all the objects of a services that must be billed -func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNNextcloud, svc *runtime.ServiceRuntime) *xfnproto.Result { +// AddBilling enables billing for this service +func AddBilling(ctx context.Context, comp *v1.VSHNNextcloud, svc *runtime.ServiceRuntime) *xfnproto.Result { err := svc.GetObservedComposite(comp) if err != nil { diff --git a/pkg/comp-functions/functions/vshnnextcloud/register.go b/pkg/comp-functions/functions/vshnnextcloud/register.go index 180d4758f..84b7a93b8 100644 --- a/pkg/comp-functions/functions/vshnnextcloud/register.go +++ b/pkg/comp-functions/functions/vshnnextcloud/register.go @@ -27,7 +27,7 @@ func init() { }, { Name: "billing", - Execute: AddServiceBillingLabel, + Execute: AddBilling, }, }, }) diff --git a/pkg/comp-functions/functions/vshnpostgres/billing.go b/pkg/comp-functions/functions/vshnpostgres/billing.go index 3b75630fd..eaa675bc3 100644 --- a/pkg/comp-functions/functions/vshnpostgres/billing.go +++ b/pkg/comp-functions/functions/vshnpostgres/billing.go @@ -9,8 +9,8 @@ import ( "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" ) -// AddServiceBillingLabel adds billingLabel to all the objects of a services that must be billed -func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNPostgreSQL, svc *runtime.ServiceRuntime) *xfnproto.Result { +// AddBilling enables billing for this service +func AddBilling(ctx context.Context, comp *v1.VSHNPostgreSQL, svc *runtime.ServiceRuntime) *xfnproto.Result { err := svc.GetObservedComposite(comp) if err != nil { return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) diff --git a/pkg/comp-functions/functions/vshnpostgres/register.go b/pkg/comp-functions/functions/vshnpostgres/register.go index 73331b90f..84da7d22b 100644 --- a/pkg/comp-functions/functions/vshnpostgres/register.go +++ b/pkg/comp-functions/functions/vshnpostgres/register.go @@ -79,7 +79,7 @@ func init() { }, { Name: "billing", - Execute: AddServiceBillingLabel, + Execute: AddBilling, }, }, }) diff --git a/pkg/comp-functions/functions/vshnredis/billing.go b/pkg/comp-functions/functions/vshnredis/billing.go index 1ead72e56..cda1221b3 100644 --- a/pkg/comp-functions/functions/vshnredis/billing.go +++ b/pkg/comp-functions/functions/vshnredis/billing.go @@ -9,8 +9,8 @@ import ( "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" ) -// AddServiceBillingLabel adds billingLabel to all the objects of a services that must be billed -func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNRedis, svc *runtime.ServiceRuntime) *xfnproto.Result { +// AddBilling enables billing for this service +func AddBilling(ctx context.Context, comp *v1.VSHNRedis, svc *runtime.ServiceRuntime) *xfnproto.Result { err := svc.GetObservedComposite(comp) if err != nil { return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) diff --git a/pkg/comp-functions/functions/vshnredis/register.go b/pkg/comp-functions/functions/vshnredis/register.go index 79aa603dd..87b917365 100644 --- a/pkg/comp-functions/functions/vshnredis/register.go +++ b/pkg/comp-functions/functions/vshnredis/register.go @@ -52,7 +52,7 @@ func init() { }, { Name: "billing", - Execute: AddServiceBillingLabel, + Execute: AddBilling, }, }, })