Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create AddOn API #280

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/vshn/v1/dbaas_vshn_keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,7 @@ func (v *VSHNKeycloak) GetBillingName() string {
func (v *VSHNKeycloak) GetSLA() string {
return string(v.Spec.Parameters.Service.ServiceLevel)
}

func (v *VSHNKeycloak) GetEnabledAddOns() []AddOn {
return []AddOn{}
}
4 changes: 4 additions & 0 deletions apis/vshn/v1/dbaas_vshn_mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,7 @@ func (v *VSHNMariaDB) GetBillingName() string {
func (v *VSHNMariaDB) GetSLA() string {
return string(v.Spec.Parameters.Service.ServiceLevel)
}

func (v *VSHNMariaDB) GetEnabledAddOns() []AddOn {
return []AddOn{}
}
4 changes: 4 additions & 0 deletions apis/vshn/v1/dbaas_vshn_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,7 @@ func (v *VSHNPostgreSQL) GetBillingName() string {
func (v *VSHNPostgreSQL) GetSLA() string {
return string(v.Spec.Parameters.Service.ServiceLevel)
}

func (v *VSHNPostgreSQL) GetEnabledAddOns() []AddOn {
return []AddOn{}
}
4 changes: 4 additions & 0 deletions apis/vshn/v1/dbaas_vshn_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,7 @@ func (v *VSHNRedis) GetBillingName() string {
func (v *VSHNRedis) GetSLA() string {
return string(v.Spec.Parameters.Service.ServiceLevel)
}

func (v *VSHNRedis) GetEnabledAddOns() []AddOn {
return []AddOn{}
}
9 changes: 9 additions & 0 deletions apis/vshn/v1/non_gen_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ type PodTemplateLabelsManager interface {
client.Object
}

// +kubebuilder:skip
// +kubebuilder:skipclient
// +kubebuilder:skipdeepcopy
// +kubebuilder:object:generate=false
type AddOn interface {
GetName() string
GetInstances() int
}

// +kubebuilder:skip
// +kubebuilder:skipclient
// +kubebuilder:skipdeepcopy
Expand Down
4 changes: 4 additions & 0 deletions apis/vshn/v1/vshn_minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,7 @@ func (v *VSHNMinio) GetBillingName() string {
func (v *VSHNMinio) GetSLA() string {
return string(BestEffort)
}

func (v *VSHNMinio) GetEnabledAddOns() []AddOn {
return []AddOn{}
}
34 changes: 30 additions & 4 deletions apis/vshn/v1/vshn_nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ type VSHNNextcloudParameters struct {
// Security defines the security of a service
Security Security `json:"security,omitempty"`

// VSHNNextcloudAddOns are additional components, modules, or extensions that enhances the functionality of VSHN Nextcloud.
// Add-ons are designed to provide optional features or capabilities that are not part of the main product but
// can be installed as needed. Usually add-on are billed separately.
AddOns VSHNNextcloudAddOns `json:"addOns,omitempty"`

// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=3
Expand All @@ -90,8 +95,6 @@ type VSHNNextcloudParameters struct {

// VSHNNextcloudServiceSpec contains nextcloud DBaaS specific properties
type VSHNNextcloudServiceSpec struct {
// Collabora contains settings to control the Collabora integration.
Collabora CollaboraSpec `json:"collabora,omitempty"`
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1

Expand Down Expand Up @@ -152,6 +155,22 @@ type VSHNNextcloudSizeSpec struct {
Plan string `json:"plan,omitempty"`
}

// VSHNNextcloudAddOns are additional components, modules, or extensions that enhances the functionality of VSHN Services.
// Add-ons are designed to provide optional features or capabilities that are not part of the main product but
// can be installed as needed. Usually add-on are billed separately.
type VSHNNextcloudAddOns struct {
// Office contains settings to control the Collabora integration.
Office OfficeSpec `json:"office,omitempty"`
}

func (o OfficeSpec) GetName() string {
return "office"
}

func (o OfficeSpec) GetInstances() int {
return 1
}

// VSHNNextcloudStatus reflects the observed state of a VSHNNextcloud.
type VSHNNextcloudStatus struct {
// InstanceNamespace contains the name of the namespace where the instance resides
Expand Down Expand Up @@ -181,8 +200,8 @@ func (v *VSHNNextcloud) SetInstanceNamespaceStatus() {
v.Status.InstanceNamespace = v.GetInstanceNamespace()
}

// CollaboraSpec defines the desired state of a Collabora instance.
type CollaboraSpec struct {
// OfficeSpec defines the desired state of a Collabora instance.
type OfficeSpec struct {
// Enabled enables the Collabora integration. It will autoconfigure the Collabora server URL in Your Nextcloud instance.
//+kubebuilder:default=false
Enabled bool `json:"enabled"`
Expand Down Expand Up @@ -342,3 +361,10 @@ func (v *VSHNNextcloud) GetBillingName() string {
func (v *VSHNNextcloud) GetSLA() string {
return string(v.Spec.Parameters.Service.ServiceLevel)
}

func (v *VSHNNextcloud) GetEnabledAddOns() []AddOn {
if v.Spec.Parameters.AddOns.Office.Enabled {
return []AddOn{v.Spec.Parameters.AddOns.Office}
}
return []AddOn{}
}
48 changes: 32 additions & 16 deletions apis/vshn/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions crds/vshn.appcat.vshn.io_vshnnextclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ spec:
parameters:
description: Parameters are the configurable fields of a VSHNNextcloud.
properties:
addOns:
description: |-
VSHNNextcloudAddOns are additional components, modules, or extensions that enhances the functionality of VSHN Nextcloud.
Add-ons are designed to provide optional features or capabilities that are not part of the main product but
can be installed as needed. Usually add-on are billed separately.
properties:
office:
description: Office contains settings to control the Collabora integration.
properties:
enabled:
default: false
description: Enabled enables the Collabora integration. It will autoconfigure the Collabora server URL in Your Nextcloud instance.
type: boolean
fqdn:
description: FQDN contains the FQDN of the Collabora server. This is used to configure the Collabora server URL in Your Nextcloud instance.
type: string
required:
- enabled
type: object
type: object
backup:
description: Backup contains settings to control how the instance should get backed up.
properties:
Expand Down Expand Up @@ -4851,19 +4871,6 @@ spec:
service:
description: Service contains nextcloud DBaaS specific properties
properties:
collabora:
description: Collabora contains settings to control the Collabora integration.
properties:
enabled:
default: false
description: Enabled enables the Collabora integration. It will autoconfigure the Collabora server URL in Your Nextcloud instance.
type: boolean
fqdn:
description: FQDN contains the FQDN of the Collabora server. This is used to configure the Collabora server URL in Your Nextcloud instance.
type: string
required:
- enabled
type: object
fqdn:
description: |-
FQDN contains the FQDNs array, which will be used for the ingress.
Expand Down
43 changes: 25 additions & 18 deletions crds/vshn.appcat.vshn.io_xvshnnextclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ spec:
parameters:
description: Parameters are the configurable fields of a VSHNNextcloud.
properties:
addOns:
description: |-
VSHNNextcloudAddOns are additional components, modules, or extensions that enhances the functionality of VSHN Nextcloud.
Add-ons are designed to provide optional features or capabilities that are not part of the main product but
can be installed as needed. Usually add-on are billed separately.
properties:
office:
description: Office contains settings to control the Collabora
integration.
properties:
enabled:
default: false
description: Enabled enables the Collabora integration.
It will autoconfigure the Collabora server URL in Your
Nextcloud instance.
type: boolean
fqdn:
description: FQDN contains the FQDN of the Collabora server.
This is used to configure the Collabora server URL in
Your Nextcloud instance.
type: string
required:
- enabled
type: object
type: object
backup:
description: Backup contains settings to control how the instance
should get backed up.
Expand Down Expand Up @@ -5575,24 +5600,6 @@ spec:
service:
description: Service contains nextcloud DBaaS specific properties
properties:
collabora:
description: Collabora contains settings to control the Collabora
integration.
properties:
enabled:
default: false
description: Enabled enables the Collabora integration.
It will autoconfigure the Collabora server URL in Your
Nextcloud instance.
type: boolean
fqdn:
description: FQDN contains the FQDN of the Collabora server.
This is used to configure the Collabora server URL in
Your Nextcloud instance.
type: string
required:
- enabled
type: object
fqdn:
description: |-
FQDN contains the FQDNs array, which will be used for the ingress.
Expand Down
16 changes: 5 additions & 11 deletions pkg/comp-functions/functions/common/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ import (
controllerruntime "sigs.k8s.io/controller-runtime"
)

// ServiceAddOns describes an addOn for a services with necessary data for billing
type ServiceAddOns struct {
Name string
Instances int
}

// 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
func CreateBillingRecord(ctx context.Context, svc *runtime.ServiceRuntime, comp InfoGetter, addOns ...ServiceAddOns) *xfnproto.Result {
func CreateBillingRecord(ctx context.Context, svc *runtime.ServiceRuntime, comp InfoGetter) *xfnproto.Result {
log := controllerruntime.LoggerFrom(ctx)
log.Info("Enabling billing for service", "service", comp.GetName())

Expand Down Expand Up @@ -64,13 +58,13 @@ func CreateBillingRecord(ctx context.Context, svc *runtime.ServiceRuntime, comp
},
}

for _, addOn := range addOns {
log.Info("Adding billing addOn for service", "service", comp.GetName(), "addOn", addOn.Name)
exprAddOn := getVectorExpression(addOn.Instances)
for _, addOn := range comp.GetEnabledAddOns() {
log.Info("Adding billing addOn for service", "service", comp.GetName(), "addOn", addOn.GetName())
exprAddOn := getVectorExpression(addOn.GetInstances())
rg.Rules = append(rg.Rules, v1.Rule{
Record: "appcat:metering",
Expr: intstr.FromString(exprAddOn),
Labels: getLabels(svc, comp, org, addOn.Name),
Labels: getLabels(svc, comp, org, addOn.GetName()),
})
}

Expand Down
20 changes: 9 additions & 11 deletions pkg/comp-functions/functions/common/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestBilling(t *testing.T) {
comp *v1.VSHNNextcloud
svc *runtime.ServiceRuntime
org string
addOns []ServiceAddOns
expectedRuleGroup v2.RuleGroup
}{
{
Expand All @@ -40,17 +39,17 @@ func TestBilling(t *testing.T) {
Parameters: v1.VSHNNextcloudParameters{
Instances: 1,
Service: v1.VSHNNextcloudServiceSpec{ServiceLevel: v1.BestEffort},
AddOns: v1.VSHNNextcloudAddOns{
Office: v1.OfficeSpec{
Enabled: true,
FQDN: "example.com",
},
},
},
},
},
svc: commontest.LoadRuntimeFromFile(t, "common/billing.yaml"),
org: "APPUiO",
addOns: []ServiceAddOns{
{
Name: "office",
Instances: 1,
},
},
expectedRuleGroup: v2.RuleGroup{
Name: "appcat-metering-rules",
Rules: []v2.Rule{
Expand Down Expand Up @@ -105,9 +104,8 @@ func TestBilling(t *testing.T) {
},
},
},
svc: commontest.LoadRuntimeFromFile(t, "common/billing.yaml"),
org: "APPUiO",
addOns: []ServiceAddOns{},
svc: commontest.LoadRuntimeFromFile(t, "common/billing.yaml"),
org: "APPUiO",
expectedRuleGroup: v2.RuleGroup{
Name: "appcat-metering-rules",
Rules: []v2.Rule{
Expand All @@ -132,7 +130,7 @@ func TestBilling(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := CreateBillingRecord(context.Background(), tt.svc, tt.comp, tt.addOns...)
r := CreateBillingRecord(context.Background(), tt.svc, tt.comp)
assert.Equal(t, xfnproto.Severity_SEVERITY_NORMAL, r.Severity)
actual := &v2.PrometheusRule{}
err := tt.svc.GetDesiredKubeObject(actual, "nextcloud-gc9x4-billing")
Expand Down
Loading
Loading