Skip to content

Commit

Permalink
Added configurable request timeout for OpenStack
Browse files Browse the repository at this point in the history
Co-Authored-By: Axel Christ <[email protected]>
  • Loading branch information
2 people authored and yupeng.richard committed Mar 26, 2019
1 parent 02f7b93 commit f5b7d80
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/30-cloudprofile-openstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ spec:
- europe-1c
keystoneURL: https://url-to-keystone/v3/
# dhcpDomain: nova.local # DHCP domain of OpenStack system (only meaningful for Kubernetes 1.10.1, see https://github.com/kubernetes/kubernetes/pull/61890 for details)
# requestTimeout: 180s # Kubernetes OpenStack Cloudprovider Request Timeout
7 changes: 6 additions & 1 deletion hack/templates/resources/30-cloudprofile.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ spec:<% caBundle=value("spec.caBundle", "") %>
- europe-1b
- europe-1c
% endif
keystoneURL: ${value("spec.openstack.keyStoneURL", "https://url-to-keystone/v3/")}<% dnsServers=value("spec.openstack.dnsServers", []) %><% dhcpDomain=value("spec.openstack.dhcpDomain", "") %>
keystoneURL: ${value("spec.openstack.keyStoneURL", "https://url-to-keystone/v3/")}<% dnsServers=value("spec.openstack.dnsServers", []) %><% dhcpDomain=value("spec.openstack.dhcpDomain", "") %><% requestTimeout=value("spec.openstack.requestTimeout", "") %>
% if dnsServers != []:
dnsServers: ${dnsServers}
% endif
Expand All @@ -509,6 +509,11 @@ spec:<% caBundle=value("spec.caBundle", "") %>
% else:
# dhcpDomain: nova.local # DHCP domain of OpenStack system (only meaningful for Kubernetes 1.10.1, see https://github.com/kubernetes/kubernetes/pull/61890 for details)
% endif
% if requestTimeout != "":
requestTimeout: ${requestTimeout}
% else:
# requestTimeout: 180s # Kubernetes OpenStack Cloudprovider Request Timeout
% endif
% endif
% if cloud == "local":
local:
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/garden/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ type OpenStackProfile struct {
// Kubernetes 1.10.1+. See https://github.com/kubernetes/kubernetes/pull/61890 for details.
// +optional
DHCPDomain *string
// RequestTimeout specifies the HTTP timeout against the OpenStack API.
// +optional
RequestTimeout *string
}

// OpenStackConstraints is an object containing constraints for certain values in the Shoot specification.
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/garden/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ type OpenStackProfile struct {
// Kubernetes 1.10.1+. See https://github.com/kubernetes/kubernetes/pull/61890 for details.
// +optional
DHCPDomain *string `json:"dhcpDomain,omitempty"`
// RequestTimeout specifies the HTTP timeout against the OpenStack API.
// +optional
RequestTimeout *string `json:"requestTimeout,omitempty"`
}

// OpenStackConstraints is an object containing constraints for certain values in the Shoot specification.
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/garden/v1beta1/zz_generated.conversion.go

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

5 changes: 5 additions & 0 deletions pkg/apis/garden/v1beta1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions pkg/apis/garden/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ func ValidateCloudProfileSpec(spec *garden.CloudProfileSpec, fldPath *field.Path
if spec.OpenStack.DHCPDomain != nil && len(*spec.OpenStack.DHCPDomain) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("openstack", "dhcpDomain"), "must provide a dhcp domain when the key is specified"))
}

if spec.OpenStack.RequestTimeout != nil {
_, err := time.ParseDuration(*spec.OpenStack.RequestTimeout)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("openstack", "requestTimeout"), *spec.OpenStack.RequestTimeout, fmt.Sprintf("invalid duration: %v", err)))
}
}
}

if spec.CABundle != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/garden/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,19 @@ var _ = Describe("validation", func() {
}))
})
})

Context("requestTimeout validation", func() {
It("should reject invalid durations", func() {
openStackCloudProfile.Spec.OpenStack.RequestTimeout = makeStringPointer("1GiB")

errorList := ValidateCloudProfile(openStackCloudProfile)

Expect(errorList).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeInvalid),
"Field": Equal(fmt.Sprintf("spec.%s.requestTimeout", fldPath)),
}))))
})
})
})

Context("tests for Alicloud cloud profiles", func() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/garden/zz_generated.deepcopy.go

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

9 changes: 8 additions & 1 deletion pkg/openapi/openapi_generated.go

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

11 changes: 10 additions & 1 deletion pkg/operation/cloudbotanist/openstackbotanist/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ func (b *OpenStackBotanist) GenerateCloudProviderConfig() (string, error) {
return "", err
}

if needsDHCPDomain && b.Shoot.CloudProfile.Spec.OpenStack.DHCPDomain != nil || b.Shoot.CloudProfile.Spec.OpenStack.RequestTimeout != nil {
cloudProviderConfig += fmt.Sprintf(`
[Metadata]`)
}

if needsDHCPDomain && b.Shoot.CloudProfile.Spec.OpenStack.DHCPDomain != nil {
cloudProviderConfig += fmt.Sprintf(`
[Metadata]
dhcp-domain=%q`, *b.Shoot.CloudProfile.Spec.OpenStack.DHCPDomain)
}

if b.Shoot.CloudProfile.Spec.OpenStack.RequestTimeout != nil {
cloudProviderConfig += fmt.Sprintf(`
request-timeout=%s`, *b.Shoot.CloudProfile.Spec.OpenStack.RequestTimeout)
}

return cloudProviderConfig, nil
}

Expand Down

0 comments on commit f5b7d80

Please sign in to comment.