diff --git a/pkg/comp-functions/functions/common/billing.go b/pkg/comp-functions/functions/common/billing.go index a77020eb86..8cb6032187 100644 --- a/pkg/comp-functions/functions/common/billing.go +++ b/pkg/comp-functions/functions/common/billing.go @@ -5,15 +5,11 @@ import ( "context" _ "embed" "fmt" - v12 "github.com/crossplane/crossplane-runtime/apis/common/v1" xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" - xkube "github.com/vshn/appcat/v4/apis/kubernetes/v1alpha2" "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" "k8s.io/apimachinery/pkg/util/intstr" - "reflect" controllerruntime "sigs.k8s.io/controller-runtime" - "strings" "text/template" ) @@ -25,45 +21,6 @@ type Billing struct { Instances int } -const billingLabel = "appcat.io/billing" - -// TODO remove this function as soon as we have automated release pipeline in prod according to maintenance -// InjectBillingLabelToService adds billing label to a service (StatefulSet or Deployment). -// It uses a kube Object to achieve post provisioning labelling -func InjectBillingLabelToService(ctx context.Context, svc *runtime.ServiceRuntime, comp InfoGetter) *xfnproto.Result { - - s := comp.GetWorkloadPodTemplateLabelsManager() - s.SetName(comp.GetWorkloadName()) - s.SetNamespace(comp.GetInstanceNamespace()) - kubeName := comp.GetName() + "-" + getType(s) - - _ = svc.GetObservedKubeObject(s, kubeName) - mp := v12.ManagementPolicies{v12.ManagementActionObserve} - labels := s.GetPodTemplateLabels() - _, exists := labels[billingLabel] - if !s.GetCreationTimestamp().Time.IsZero() { - if !exists { - labels[billingLabel] = "true" - s.SetPodTemplateLabels(labels) - mp = append(mp, v12.ManagementActionCreate, v12.ManagementActionUpdate) - } - } - - err := svc.SetDesiredKubeObject(s.GetObject(), kubeName, func(obj *xkube.Object) { - obj.Spec.ManagementPolicies = mp - }) - - if err != nil && !exists { - runtime.NewWarningResult(fmt.Sprintf("cannot add billing to service object %s", s.GetName())) - } - - return runtime.NewNormalResult("billing enabled") -} - -func getType(myvar interface{}) (res string) { - return strings.ToLower(reflect.TypeOf(myvar).Elem().Field(0).Name) -} - // CreateBillingRecord creates a new prometheus rule per each instance namespace // The rule is skipped for any secondary service such as postgresql instance for nextcloud // The skipping is based on whether label appuio.io/billing-name is set or not on instance namespace diff --git a/pkg/comp-functions/functions/vshnkeycloak/billing.go b/pkg/comp-functions/functions/vshnkeycloak/billing.go index 66c30e3139..b3594b4951 100644 --- a/pkg/comp-functions/functions/vshnkeycloak/billing.go +++ b/pkg/comp-functions/functions/vshnkeycloak/billing.go @@ -16,7 +16,5 @@ func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNKeycloak, svc *run return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) } - common.InjectBillingLabelToService(ctx, svc, comp) - return common.CreateBillingRecord(ctx, svc, comp) } diff --git a/pkg/comp-functions/functions/vshnmariadb/billing.go b/pkg/comp-functions/functions/vshnmariadb/billing.go index 5eda049e21..96e8ad8a69 100644 --- a/pkg/comp-functions/functions/vshnmariadb/billing.go +++ b/pkg/comp-functions/functions/vshnmariadb/billing.go @@ -16,7 +16,5 @@ func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNMariaDB, svc *runt return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) } - common.InjectBillingLabelToService(ctx, svc, comp) - return common.CreateBillingRecord(ctx, svc, comp) } diff --git a/pkg/comp-functions/functions/vshnminio/billing.go b/pkg/comp-functions/functions/vshnminio/billing.go index a9a99a349c..78eeaacd00 100644 --- a/pkg/comp-functions/functions/vshnminio/billing.go +++ b/pkg/comp-functions/functions/vshnminio/billing.go @@ -16,7 +16,5 @@ func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNMinio, svc *runtim return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) } - common.InjectBillingLabelToService(ctx, svc, comp) - return common.CreateBillingRecord(ctx, svc, comp) } diff --git a/pkg/comp-functions/functions/vshnnextcloud/billing.go b/pkg/comp-functions/functions/vshnnextcloud/billing.go index 58c99678cb..d81b382778 100644 --- a/pkg/comp-functions/functions/vshnnextcloud/billing.go +++ b/pkg/comp-functions/functions/vshnnextcloud/billing.go @@ -11,6 +11,7 @@ import ( // 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 { + 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/billing.go b/pkg/comp-functions/functions/vshnpostgres/billing.go index a56f557d57..3b75630fd2 100644 --- a/pkg/comp-functions/functions/vshnpostgres/billing.go +++ b/pkg/comp-functions/functions/vshnpostgres/billing.go @@ -16,7 +16,5 @@ func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNPostgreSQL, svc *r return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) } - common.InjectBillingLabelToService(ctx, svc, comp) - return common.CreateBillingRecord(ctx, svc, comp) } diff --git a/pkg/comp-functions/functions/vshnredis/billing.go b/pkg/comp-functions/functions/vshnredis/billing.go index eb75ac3ea4..1ead72e563 100644 --- a/pkg/comp-functions/functions/vshnredis/billing.go +++ b/pkg/comp-functions/functions/vshnredis/billing.go @@ -16,7 +16,5 @@ func AddServiceBillingLabel(ctx context.Context, comp *v1.VSHNRedis, svc *runtim return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) } - common.InjectBillingLabelToService(ctx, svc, comp) - return common.CreateBillingRecord(ctx, svc, comp) }