Skip to content

Commit

Permalink
Export active domains (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraliv13 authored Nov 13, 2023
1 parent e85f96b commit dde9424
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions helm/crds/platform.totalsoft.ro_domains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
type: object
spec:
properties:
exportActiveDomains:
type: boolean
platformRef:
description: PlatformRef is the target platform.
type: string
Expand Down
15 changes: 7 additions & 8 deletions internal/controllers/platform/platform_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (c *PlatformController) syncHandler(key string) error {
}
domains = domains[:n]

platformCfgMap := c.genPlatformTenantsCfgMap(platform, tenants, domains)
platformCfgMap := c.genPlatformTenantsCfgMap(platform, tenants)
err = c.syncConfigMap(platformCfgMap, platform)

// If an error occurs we'll requeue the item so we can
Expand Down Expand Up @@ -459,16 +459,12 @@ func (c *PlatformController) enqueuePlatform(platform *platformv1.Platform) {
c.workqueue.Add(platform.Name)
}

func (c *PlatformController) genPlatformTenantsCfgMap(platform *platformv1.Platform, tenants []*platformv1.Tenant, domains []*platformv1.Domain) *corev1.ConfigMap {
func (c *PlatformController) genPlatformTenantsCfgMap(platform *platformv1.Platform, tenants []*platformv1.Tenant) *corev1.ConfigMap {
cfgMapName := fmt.Sprintf("%s-tenants", platform.Name)
tenantData := map[string]string{}
for _, tenant := range tenants {
tenantData[fmt.Sprintf("MultiTenancy__Tenants__%s__TenantId", tenant.Name)] = tenant.Spec.Id
tenantData[fmt.Sprintf("MultiTenancy__Tenants__%s__Enabled", tenant.Name)] = strconv.FormatBool(tenant.Spec.Enabled)
for _, domain := range domains {
tenantHasAccessToDomain := tenantHasAccessToDomain(tenant, domain.Name)
tenantData[fmt.Sprintf("MultiTenancy__Tenants__%s__Domains__%s__Enabled", tenant.Name, domain.Name)] = strconv.FormatBool(tenantHasAccessToDomain)
}
}

return &corev1.ConfigMap{
Expand All @@ -494,6 +490,11 @@ func (c *PlatformController) genDomainTenantsCfgMap(platform *platformv1.Platfor
for _, tenant := range tenants {
tenantEnabled := tenant.Spec.Enabled && tenantHasAccessToDomain(tenant, domain.Name)
tenantData[fmt.Sprintf("MultiTenancy__Tenants__%s__Enabled", tenant.Name)] = strconv.FormatBool(tenant.Spec.Enabled && tenantEnabled)
if domain.Spec.ExportActiveDomains && tenantEnabled {
for _, domain := range tenant.Spec.DomainRefs {
tenantData[fmt.Sprintf("MultiTenancy__Tenants__%s__Domains__%s__Enabled", tenant.Name, domain)] = strconv.FormatBool(true)
}
}
}

return &corev1.ConfigMap{
Expand All @@ -514,12 +515,10 @@ func (c *PlatformController) genDomainTenantsCfgMap(platform *platformv1.Platfor
}

func tenantHasAccessToDomain(tenant *platformv1.Tenant, domainName string) bool {

for _, d := range tenant.Spec.DomainRefs {
if d == domainName {
return true
}
}

return false
}
3 changes: 3 additions & 0 deletions pkg/apis/platform/v1alpha1/domainTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type DomainSpec struct {
// PlatformRef is the target platform.
// +required
PlatformRef string `json:"platformRef"`

// +optional
ExportActiveDomains bool `json:"exportActiveDomains"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
11 changes: 10 additions & 1 deletion pkg/generated/applyconfiguration/platform/v1alpha1/domainspec.go

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

0 comments on commit dde9424

Please sign in to comment.