Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to disable auto-creation of domain claims #330

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this name, but I don't have a better suggestion. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same :(. If we can come up with something better before we make this "beta", that'd be nice.


// 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