Skip to content

Commit

Permalink
Add config to disable auto-creation of domain claims (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
julz authored Jan 12, 2021
1 parent 3a89509 commit 4c4c237
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
13 changes: 12 additions & 1 deletion config/config-network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ metadata:
labels:
serving.knative.dev/release: devel
annotations:
knative.dev/example-checksum: "eaf5fb3f"
knative.dev/example-checksum: "14cd8fa3"
data:
_example: |
################################
Expand Down Expand Up @@ -108,3 +108,14 @@ data:
# rolloutDuration contains the minimal duration in seconds over which the
# Configuration traffic targets are rolled out to the newest revision.
rolloutDuration: "0"
# autocreateClusterDomainClaims controls whether ClusterDomainClaims should
# be automatically created (and deleted) as needed when DomainMappings are
# reconciled.
#
# If this is "false", the cluster administrator is responsible for creating
# ClusterDomainClaims and delegating them to namespaces via their
# spec.Namespace field. This is useful for multitenant environments
# which need to control which namespace can use a particular domain name in
# a domain mapping.
autocreateClusterDomainClaims: "true"
25 changes: 19 additions & 6 deletions pkg/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ const (
// constructing the Knative Route's tag names.
DefaultTagTemplate = "{{.Tag}}-{{.Name}}"

// AutocreateClusterDomainClaimsKey is the key for the
// AutocreateClusterDomainClaims property.
AutocreateClusterDomainClaimsKey = "autocreateClusterDomainClaims"

// AutoTLSKey is the name of the configuration entry
// that specifies enabling auto-TLS or not.
AutoTLSKey = "autoTLS"
Expand Down Expand Up @@ -235,6 +239,13 @@ type Config struct {

// RolloutDurationSecs specifies the default duration for the rollout.
RolloutDurationSecs int

// AutocreateClusterDomainClaims specifies whether cluster-wide DomainClaims
// should be automatically created (and deleted) as needed when a
// DomainMapping is reconciled. If this is false, the
// cluster administrator is responsible for pre-creating ClusterDomainClaims
// and delegating them to namespaces via their spec.Namespace field.
AutocreateClusterDomainClaims bool
}

// HTTPProtocol indicates a type of HTTP endpoint behavior
Expand All @@ -254,12 +265,13 @@ const (

func defaultConfig() *Config {
return &Config{
DefaultIngressClass: IstioIngressClassName,
DefaultCertificateClass: CertManagerCertificateClassName,
DomainTemplate: DefaultDomainTemplate,
TagTemplate: DefaultTagTemplate,
AutoTLS: false,
HTTPProtocol: HTTPEnabled,
DefaultIngressClass: IstioIngressClassName,
DefaultCertificateClass: CertManagerCertificateClassName,
DomainTemplate: DefaultDomainTemplate,
TagTemplate: DefaultTagTemplate,
AutoTLS: false,
HTTPProtocol: HTTPEnabled,
AutocreateClusterDomainClaims: true,
}
}

Expand All @@ -280,6 +292,7 @@ func NewConfigFromMap(data map[string]string) (*Config, error) {
cm.AsString(DomainTemplateKey, &nc.DomainTemplate),
cm.AsString(TagTemplateKey, &nc.TagTemplate),
cm.AsInt(RolloutDurationKey, &nc.RolloutDurationSecs),
cm.AsBool(AutocreateClusterDomainClaimsKey, &nc.AutocreateClusterDomainClaims),
); err != nil {
return nil, err
}
Expand Down
19 changes: 18 additions & 1 deletion pkg/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestConfiguration(t *testing.T) {
return c
}(),
}, {
name: "network configuration with non-default rolout duration",
name: "network configuration with non-default rollout duration",
data: map[string]string{
RolloutDurationKey: "211",
},
Expand All @@ -95,6 +95,23 @@ func TestConfiguration(t *testing.T) {
RolloutDurationKey: "-444",
},
wantErr: true,
}, {
name: "network configuration with non-default autocreateClusterDomainClaim value",
data: map[string]string{
AutocreateClusterDomainClaimsKey: "false",
},
wantErr: false,
wantConfig: func() *Config {
c := defaultConfig()
c.AutocreateClusterDomainClaims = false
return c
}(),
}, {
name: "network configuration with invalid autocreateClusterDomainClaim value",
data: map[string]string{
AutocreateClusterDomainClaimsKey: "salad",
},
wantErr: true,
}, {
name: "network configuration with non-Cert-Manager Certificate type",
data: map[string]string{
Expand Down

0 comments on commit 4c4c237

Please sign in to comment.