-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriel Saratura
committed
Oct 7, 2024
1 parent
7dd0eb1
commit 8bf3da6
Showing
21 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
v12 "github.com/crossplane/crossplane-runtime/apis/common/v1" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
xkube "github.com/vshn/appcat/v4/apis/kubernetes/v1alpha2" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/runtime" | ||
) | ||
|
||
const billingLabel = "appcat.io/billing" | ||
|
||
func InjectBillingLabelToObjects(svc *runtime.ServiceRuntime, comp InfoGetter) *xfnproto.Result { | ||
s := comp.GetServiceKubeType() | ||
s.SetName(comp.GetName()) | ||
s.SetNamespace(comp.GetInstanceNamespace()) | ||
|
||
_ = svc.GetObservedKubeObject(s, s.GetName()+"-service") | ||
mp := v12.ManagementPolicies{v12.ManagementActionObserve} | ||
_, exists := s.GetLabels()[billingLabel] | ||
if !s.GetCreationTimestamp().Time.IsZero() { | ||
if !exists { | ||
labels := s.GetLabels() | ||
labels[billingLabel] = "true" | ||
s.SetLabels(labels) | ||
mp = append(mp, v12.ManagementActionCreate, v12.ManagementActionUpdate) | ||
} | ||
} | ||
|
||
err := svc.SetDesiredKubeObject(s, s.GetName()+"-service", 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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vshnkeycloak | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
v1 "github.com/vshn/appcat/v4/apis/vshn/v1" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
"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(_ 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)) | ||
} | ||
|
||
return common.InjectBillingLabelToObjects(svc, comp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vshnmariadb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
v1 "github.com/vshn/appcat/v4/apis/vshn/v1" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
"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(_ 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)) | ||
} | ||
|
||
return common.InjectBillingLabelToObjects(svc, comp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vshnminio | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
v1 "github.com/vshn/appcat/v4/apis/vshn/v1" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
"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(_ 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)) | ||
} | ||
|
||
return common.InjectBillingLabelToObjects(svc, comp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vshnnextcloud | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
v1 "github.com/vshn/appcat/v4/apis/vshn/v1" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
"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(_ 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)) | ||
} | ||
|
||
return common.InjectBillingLabelToObjects(svc, comp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vshnpostgres | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
v1 "github.com/vshn/appcat/v4/apis/vshn/v1" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
"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(_ 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)) | ||
} | ||
|
||
return common.InjectBillingLabelToObjects(svc, comp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vshnredis | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
v1 "github.com/vshn/appcat/v4/apis/vshn/v1" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
"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(_ 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)) | ||
} | ||
|
||
return common.InjectBillingLabelToObjects(svc, comp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters