From 8dbe6c7b2274834ab97c8603ea2a582b4b1b8a31 Mon Sep 17 00:00:00 2001 From: Igal Tsoiref Date: Mon, 4 Dec 2023 17:01:11 +0200 Subject: [PATCH] Review fixes --- .../attrvalidators}/notemptymap_validator.go | 2 +- provider/defaultingress/ingress.go | 134 +++++++++--------- 2 files changed, 66 insertions(+), 70 deletions(-) rename provider/{defaultingress => common/attrvalidators}/notemptymap_validator.go (98%) diff --git a/provider/defaultingress/notemptymap_validator.go b/provider/common/attrvalidators/notemptymap_validator.go similarity index 98% rename from provider/defaultingress/notemptymap_validator.go rename to provider/common/attrvalidators/notemptymap_validator.go index dc623fcd..28e97584 100644 --- a/provider/defaultingress/notemptymap_validator.go +++ b/provider/common/attrvalidators/notemptymap_validator.go @@ -1,4 +1,4 @@ -package defaultingress +package attrvalidators import ( "context" diff --git a/provider/defaultingress/ingress.go b/provider/defaultingress/ingress.go index 6cfdd81d..deacdbb8 100644 --- a/provider/defaultingress/ingress.go +++ b/provider/defaultingress/ingress.go @@ -51,7 +51,71 @@ func (r *DefaultIngressResource) Metadata(ctx context.Context, req resource.Meta func (r *DefaultIngressResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Description: "Edit a cluster ingress (load balancer)", - Attributes: ingressResource(), + Attributes: map[string]schema.Attribute{ + "cluster": schema.StringAttribute{ + Description: "Identifier of the cluster.", + Required: true, + PlanModifiers: []planmodifier.String{ + common.Immutable(), + }, + }, + "id": schema.StringAttribute{ + Description: "Unique identifier of the ingress.", + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + // This passes the state through to the plan, preventing + // "known after apply" since we know it won't change. + stringplanmodifier.UseStateForUnknown(), + }, + }, + "route_selectors": schema.MapAttribute{ + Description: "Route Selectors for ingress. Format should be a comma-separated list of 'key=value'. " + + "If no label is specified, all routes will be exposed on both routers." + + "For legacy ingress support these are inclusion labels, otherwise they are treated as exclusion label.", + + ElementType: types.StringType, + Optional: true, + Validators: []validator.Map{attrvalidators.NotEmptyMapValidator()}, + }, + "excluded_namespaces": schema.ListAttribute{ + Description: "Excluded namespaces for ingress. Format should be a comma-separated list 'value1, value2...'. " + + "If no values are specified, all namespaces will be exposed.", + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + }, + }, + "route_wildcard_policy": schema.StringAttribute{ + Description: fmt.Sprintf("Wildcard Policy for ingress. Options are %s. Default is '%s'.", + strings.Join(validWildcardPolicies, ","), defaultWildcardPolicy), + Optional: true, + Computed: true, + Validators: []validator.String{attrvalidators.EnumValueValidator(validWildcardPolicies)}, + }, + "route_namespace_ownership_policy": schema.StringAttribute{ + Description: fmt.Sprintf("Namespace Ownership Policy for ingress. Options are %s. Default is '%s'.", + strings.Join(validNamespaceOwnershipPolicies, ","), defaultNamespaceOwnershipPolicy), + Optional: true, + Computed: true, + Validators: []validator.String{attrvalidators.EnumValueValidator(validNamespaceOwnershipPolicies)}, + }, + "cluster_routes_hostname": schema.StringAttribute{ + Description: "Components route hostname for oauth, console, download.", + Optional: true, + }, + "load_balancer_type": schema.StringAttribute{ + Description: fmt.Sprintf("Type of Load Balancer. Options are %s.", strings.Join(validLbTypes, ",")), + Optional: true, + Computed: true, + Validators: []validator.String{attrvalidators.EnumValueValidator(validLbTypes)}, + }, + "cluster_routes_tls_secret_ref": schema.StringAttribute{ + Description: "Components route TLS secret reference for oauth, console, download.", + Optional: true, + }, + }, } return } @@ -374,74 +438,6 @@ func getDefaultIngressBuilder(ctx context.Context, state *DefaultIngress) *cmv1. return ingressBuilder } -func ingressResource() map[string]schema.Attribute { - return map[string]schema.Attribute{ - "cluster": schema.StringAttribute{ - Description: "Identifier of the cluster.", - Required: true, - PlanModifiers: []planmodifier.String{ - common.Immutable(), - }, - }, - "id": schema.StringAttribute{ - Description: "Unique identifier of the ingress.", - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - // This passes the state through to the plan, preventing - // "known after apply" since we know it won't change. - stringplanmodifier.UseStateForUnknown(), - }, - }, - "route_selectors": schema.MapAttribute{ - Description: "Route Selectors for ingress. Format should be a comma-separated list of 'key=value'. " + - "If no label is specified, all routes will be exposed on both routers." + - "For legacy ingress support these are inclusion labels, otherwise they are treated as exclusion label.", - - ElementType: types.StringType, - Optional: true, - Validators: []validator.Map{NotEmptyMapValidator()}, - }, - "excluded_namespaces": schema.ListAttribute{ - Description: "Excluded namespaces for ingress. Format should be a comma-separated list 'value1, value2...'. " + - "If no values are specified, all namespaces will be exposed.", - ElementType: types.StringType, - Optional: true, - Validators: []validator.List{ - listvalidator.SizeAtLeast(1), - }, - }, - "route_wildcard_policy": schema.StringAttribute{ - Description: fmt.Sprintf("Wildcard Policy for ingress. Options are %s. Default is '%s'.", - strings.Join(validWildcardPolicies, ","), defaultWildcardPolicy), - Optional: true, - Computed: true, - Validators: []validator.String{attrvalidators.EnumValueValidator(validWildcardPolicies)}, - }, - "route_namespace_ownership_policy": schema.StringAttribute{ - Description: fmt.Sprintf("Namespace Ownership Policy for ingress. Options are %s. Default is '%s'.", - strings.Join(validNamespaceOwnershipPolicies, ","), defaultNamespaceOwnershipPolicy), - Optional: true, - Computed: true, - Validators: []validator.String{attrvalidators.EnumValueValidator(validNamespaceOwnershipPolicies)}, - }, - "cluster_routes_hostname": schema.StringAttribute{ - Description: "Components route hostname for oauth, console, download.", - Optional: true, - }, - "load_balancer_type": schema.StringAttribute{ - Description: fmt.Sprintf("Type of Load Balancer. Options are %s.", strings.Join(validLbTypes, ",")), - Optional: true, - Computed: true, - Validators: []validator.String{attrvalidators.EnumValueValidator(validLbTypes)}, - }, - "cluster_routes_tls_secret_ref": schema.StringAttribute{ - Description: "Components route TLS secret reference for oauth, console, download.", - Optional: true, - }, - } -} - func validateDefaultIngress(ctx context.Context, state *DefaultIngress) error { if common.IsStringAttributeUnknownOrEmpty(state.ClusterRoutesHostname) != common.IsStringAttributeUnknownOrEmpty(state.ClusterRoutesTlsSecretRef) { msg := fmt.Sprintf("default_ingress params: cluster_routes_hostname and cluster_routes_tls_secret_ref must be set together")