Skip to content

Commit

Permalink
Create AddOn API
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Saratura committed Dec 5, 2024
1 parent 90a90f4 commit 66071cf
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 92 deletions.
4 changes: 4 additions & 0 deletions apis/vshn/v1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (n *VSHNDBaaSMaintenanceScheduleSpec) SetMaintenanceTimeOfDay(tod TimeOfDay
n.TimeOfDay = tod
}

// VSHNAddOns 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.

// VSHNSizeSpec contains settings to control the sizing of a service.
type VSHNSizeSpec struct {
// CPU defines the amount of Kubernetes CPUs for an instance.
Expand Down
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 @@ -353,3 +353,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 @@ -306,3 +306,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 @@ -317,3 +317,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 @@ -269,3 +269,7 @@ func (v *VSHNMinio) GetBillingName() string {
func (v *VSHNMinio) GetSLA() string {
return string(BestEffort)
}

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

// VSHNAddOns defines the add-ons of a service
AddOns VSHNNextcloudAddOns `json:"addOns,omitempty"`

// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=3
Expand All @@ -88,8 +91,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 @@ -150,6 +151,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 @@ -179,8 +196,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 @@ -338,3 +355,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.

30 changes: 17 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,23 @@ spec:
parameters:
description: Parameters are the configurable fields of a VSHNNextcloud.
properties:
addOns:
description: VSHNAddOns defines the add-ons of a service
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 +4868,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
40 changes: 22 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,28 @@ spec:
parameters:
description: Parameters are the configurable fields of a VSHNNextcloud.
properties:
addOns:
description: VSHNAddOns defines the add-ons of a service
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 +5597,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
Loading

0 comments on commit 66071cf

Please sign in to comment.