diff --git a/helm/crds/platform.totalsoft.ro_domains.yaml b/helm/crds/platform.totalsoft.ro_domains.yaml index 2fc8fcf..6120207 100644 --- a/helm/crds/platform.totalsoft.ro_domains.yaml +++ b/helm/crds/platform.totalsoft.ro_domains.yaml @@ -32,6 +32,8 @@ spec: type: object spec: properties: + exportActiveDomains: + type: boolean platformRef: description: PlatformRef is the target platform. type: string diff --git a/internal/controllers/platform/platform_controller.go b/internal/controllers/platform/platform_controller.go index aed8ba7..a49fb18 100644 --- a/internal/controllers/platform/platform_controller.go +++ b/internal/controllers/platform/platform_controller.go @@ -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 @@ -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{ @@ -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{ @@ -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 } diff --git a/pkg/apis/platform/v1alpha1/domainTypes.go b/pkg/apis/platform/v1alpha1/domainTypes.go index 2d91e28..e68aae4 100644 --- a/pkg/apis/platform/v1alpha1/domainTypes.go +++ b/pkg/apis/platform/v1alpha1/domainTypes.go @@ -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 diff --git a/pkg/generated/applyconfiguration/platform/v1alpha1/domainspec.go b/pkg/generated/applyconfiguration/platform/v1alpha1/domainspec.go index 24e23fc..a57ed0f 100644 --- a/pkg/generated/applyconfiguration/platform/v1alpha1/domainspec.go +++ b/pkg/generated/applyconfiguration/platform/v1alpha1/domainspec.go @@ -21,7 +21,8 @@ package v1alpha1 // DomainSpecApplyConfiguration represents an declarative configuration of the DomainSpec type for use // with apply. type DomainSpecApplyConfiguration struct { - PlatformRef *string `json:"platformRef,omitempty"` + PlatformRef *string `json:"platformRef,omitempty"` + ExportActiveDomains *bool `json:"exportActiveDomains,omitempty"` } // DomainSpecApplyConfiguration constructs an declarative configuration of the DomainSpec type for use with @@ -37,3 +38,11 @@ func (b *DomainSpecApplyConfiguration) WithPlatformRef(value string) *DomainSpec b.PlatformRef = &value return b } + +// WithExportActiveDomains sets the ExportActiveDomains field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ExportActiveDomains field is set to the value of the last call. +func (b *DomainSpecApplyConfiguration) WithExportActiveDomains(value bool) *DomainSpecApplyConfiguration { + b.ExportActiveDomains = &value + return b +}