-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multi-tenancy in TempoMonolithic CR
Signed-off-by: Andreas Gerstmayr <agerstmayr@redhat.com>
- Loading branch information
1 parent
03d8e5f
commit 1767cad
Showing
30 changed files
with
1,364 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. operator, github action) | ||
component: operator | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Support multi-tenancy in TempoMonolithic CR | ||
|
||
# One or more tracking issues related to the change | ||
issues: [816] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
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,74 @@ | ||
package monolithic | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/grafana/tempo-operator/apis/tempo/v1alpha1" | ||
"github.com/grafana/tempo-operator/internal/manifests/gateway" | ||
"github.com/grafana/tempo-operator/internal/manifests/manifestutils" | ||
"github.com/grafana/tempo-operator/internal/manifests/naming" | ||
) | ||
|
||
const ( | ||
opaPackage = "tempomonolithic" | ||
) | ||
|
||
// BuildGatewayObjects builds auxiliary objects required for multitenancy. | ||
// | ||
// Enabling multi-tenancy (multitenancy.enabled=true) and configuring at least one tenant has the following effect on the deployment: | ||
// * a tempo-$name-gateway ConfigMap (rbac.yaml) and Secret (tenants.yaml) will be created | ||
// * a tempo-gateway container is added to the StatefulSet | ||
// * a tempo-$name-gateway service will be created and the tempo-$name and tempo-$name-jaegerui will be removed | ||
// | ||
// additionally, if mode=openshift | ||
// * a tempo-gateway-opa container is added to the StatefulSet | ||
// * the ServiceAccount will get additional annotations (serviceaccounts.openshift.io/oauth-redirectreference.$tenantName) | ||
// * a ClusterRole (tokenreviews/create and subjectaccessreviews/create) and ClusterRoleBinding will be created for the ServiceAccount. | ||
func BuildGatewayObjects(opts Options) ([]client.Object, map[string]string, error) { | ||
tempo := opts.Tempo | ||
manifests := []client.Object{} | ||
extraAnnotations := map[string]string{} | ||
labels := ComponentLabels(manifestutils.GatewayComponentName, tempo.Name) | ||
gatewayObjectName := naming.Name(manifestutils.GatewayComponentName, tempo.Name) | ||
|
||
cfgOpts := gateway.NewConfigOptions( | ||
tempo.Namespace, | ||
tempo.Name, | ||
naming.DefaultServiceAccountName(tempo.Name), | ||
naming.RouteFqdn(tempo.Namespace, tempo.Name, "jaegerui", opts.CtrlConfig.Gates.OpenShift.BaseDomain), | ||
opaPackage, | ||
tempo.Spec.Multitenancy.TenantsSpec, | ||
opts.GatewayTenantSecret, | ||
opts.GatewayTenantsData, | ||
) | ||
|
||
rbacConfigMap, rbacHash, err := gateway.NewRBACConfigMap(cfgOpts, tempo.Namespace, gatewayObjectName, labels) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
extraAnnotations["tempo.grafana.com/rbacConfig.hash"] = rbacHash | ||
manifests = append(manifests, rbacConfigMap) | ||
|
||
tenantsSecret, tenantsHash, err := gateway.NewTenantsSecret(cfgOpts, tempo.Namespace, gatewayObjectName, labels) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
extraAnnotations["tempo.grafana.com/tenantsConfig.hash"] = tenantsHash | ||
manifests = append(manifests, tenantsSecret) | ||
|
||
if tempo.Spec.Multitenancy.TenantsSpec.Mode == v1alpha1.ModeOpenShift { | ||
manifests = append(manifests, gateway.NewAccessReviewClusterRole( | ||
gatewayObjectName, | ||
ComponentLabels(manifestutils.GatewayComponentName, tempo.Name), | ||
)) | ||
|
||
manifests = append(manifests, gateway.NewAccessReviewClusterRoleBinding( | ||
gatewayObjectName, | ||
ComponentLabels(manifestutils.GatewayComponentName, tempo.Name), | ||
tempo.Namespace, | ||
naming.DefaultServiceAccountName(tempo.Name), | ||
)) | ||
} | ||
|
||
return manifests, extraAnnotations, nil | ||
} |
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,53 @@ | ||
package monolithic | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
configv1alpha1 "github.com/grafana/tempo-operator/apis/config/v1alpha1" | ||
"github.com/grafana/tempo-operator/apis/tempo/v1alpha1" | ||
) | ||
|
||
func TestGateway(t *testing.T) { | ||
opts := Options{ | ||
CtrlConfig: configv1alpha1.ProjectConfig{ | ||
Gates: configv1alpha1.FeatureGates{ | ||
OpenShift: configv1alpha1.OpenShiftFeatureGates{ | ||
ServingCertsService: true, | ||
}, | ||
}, | ||
}, | ||
Tempo: v1alpha1.TempoMonolithic{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "sample", | ||
Namespace: "default", | ||
}, | ||
Spec: v1alpha1.TempoMonolithicSpec{ | ||
Multitenancy: &v1alpha1.MonolithicMultitenancySpec{ | ||
Enabled: true, | ||
TenantsSpec: v1alpha1.TenantsSpec{ | ||
Mode: v1alpha1.ModeOpenShift, | ||
Authentication: []v1alpha1.AuthenticationSpec{ | ||
{ | ||
TenantName: "dev", | ||
TenantID: "1610b0c3-c509-4592-a256-a1871353dbfa", | ||
}, | ||
{ | ||
TenantName: "prod", | ||
TenantID: "1610b0c3-c509-4592-a256-a1871353dbfb", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
objs, annotations, err := BuildGatewayObjects(opts) | ||
require.NoError(t, err) | ||
require.Len(t, objs, 4) | ||
|
||
require.Contains(t, annotations, "tempo.grafana.com/rbacConfig.hash") | ||
require.Contains(t, annotations, "tempo.grafana.com/tenantsConfig.hash") | ||
} |
Oops, something went wrong.