From f5b7d8037c4277b6f6a39758e331db85ac716111 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Wed, 14 Nov 2018 14:00:27 +0100 Subject: [PATCH] Added configurable request timeout for OpenStack Co-Authored-By: Axel Christ --- example/30-cloudprofile-openstack.yaml | 1 + hack/templates/resources/30-cloudprofile.yaml.tpl | 7 ++++++- pkg/apis/garden/types.go | 3 +++ pkg/apis/garden/v1beta1/types.go | 3 +++ pkg/apis/garden/v1beta1/zz_generated.conversion.go | 2 ++ pkg/apis/garden/v1beta1/zz_generated.deepcopy.go | 5 +++++ pkg/apis/garden/validation/validation.go | 7 +++++++ pkg/apis/garden/validation/validation_test.go | 13 +++++++++++++ pkg/apis/garden/zz_generated.deepcopy.go | 5 +++++ pkg/openapi/openapi_generated.go | 9 ++++++++- .../cloudbotanist/openstackbotanist/controlplane.go | 11 ++++++++++- 11 files changed, 63 insertions(+), 3 deletions(-) diff --git a/example/30-cloudprofile-openstack.yaml b/example/30-cloudprofile-openstack.yaml index 780d0afb6fb..2ab935a2752 100644 --- a/example/30-cloudprofile-openstack.yaml +++ b/example/30-cloudprofile-openstack.yaml @@ -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 diff --git a/hack/templates/resources/30-cloudprofile.yaml.tpl b/hack/templates/resources/30-cloudprofile.yaml.tpl index 739cd20dbfa..6f6d9f3eb54 100644 --- a/hack/templates/resources/30-cloudprofile.yaml.tpl +++ b/hack/templates/resources/30-cloudprofile.yaml.tpl @@ -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 @@ -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: diff --git a/pkg/apis/garden/types.go b/pkg/apis/garden/types.go index a667b1d9454..3ac61bf664c 100644 --- a/pkg/apis/garden/types.go +++ b/pkg/apis/garden/types.go @@ -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. diff --git a/pkg/apis/garden/v1beta1/types.go b/pkg/apis/garden/v1beta1/types.go index d7816a00d26..78f8013ff2a 100644 --- a/pkg/apis/garden/v1beta1/types.go +++ b/pkg/apis/garden/v1beta1/types.go @@ -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. diff --git a/pkg/apis/garden/v1beta1/zz_generated.conversion.go b/pkg/apis/garden/v1beta1/zz_generated.conversion.go index 2a35de625c9..6d081a95265 100644 --- a/pkg/apis/garden/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/garden/v1beta1/zz_generated.conversion.go @@ -3793,6 +3793,7 @@ func autoConvert_v1beta1_OpenStackProfile_To_garden_OpenStackProfile(in *OpenSta out.KeyStoneURL = in.KeyStoneURL out.DNSServers = *(*[]string)(unsafe.Pointer(&in.DNSServers)) out.DHCPDomain = (*string)(unsafe.Pointer(in.DHCPDomain)) + out.RequestTimeout = (*string)(unsafe.Pointer(in.RequestTimeout)) return nil } @@ -3808,6 +3809,7 @@ func autoConvert_garden_OpenStackProfile_To_v1beta1_OpenStackProfile(in *garden. out.KeyStoneURL = in.KeyStoneURL out.DNSServers = *(*[]string)(unsafe.Pointer(&in.DNSServers)) out.DHCPDomain = (*string)(unsafe.Pointer(in.DHCPDomain)) + out.RequestTimeout = (*string)(unsafe.Pointer(in.RequestTimeout)) return nil } diff --git a/pkg/apis/garden/v1beta1/zz_generated.deepcopy.go b/pkg/apis/garden/v1beta1/zz_generated.deepcopy.go index 97d3f84f048..aad9193d8c1 100644 --- a/pkg/apis/garden/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/garden/v1beta1/zz_generated.deepcopy.go @@ -2335,6 +2335,11 @@ func (in *OpenStackProfile) DeepCopyInto(out *OpenStackProfile) { *out = new(string) **out = **in } + if in.RequestTimeout != nil { + in, out := &in.RequestTimeout, &out.RequestTimeout + *out = new(string) + **out = **in + } return } diff --git a/pkg/apis/garden/validation/validation.go b/pkg/apis/garden/validation/validation.go index efbe20fb65b..e9a9c4dacb9 100644 --- a/pkg/apis/garden/validation/validation.go +++ b/pkg/apis/garden/validation/validation.go @@ -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 { diff --git a/pkg/apis/garden/validation/validation_test.go b/pkg/apis/garden/validation/validation_test.go index 6750dcf33d8..86f9fb18895 100644 --- a/pkg/apis/garden/validation/validation_test.go +++ b/pkg/apis/garden/validation/validation_test.go @@ -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() { diff --git a/pkg/apis/garden/zz_generated.deepcopy.go b/pkg/apis/garden/zz_generated.deepcopy.go index 45995be39bb..94710a02014 100644 --- a/pkg/apis/garden/zz_generated.deepcopy.go +++ b/pkg/apis/garden/zz_generated.deepcopy.go @@ -2314,6 +2314,11 @@ func (in *OpenStackProfile) DeepCopyInto(out *OpenStackProfile) { *out = new(string) **out = **in } + if in.RequestTimeout != nil { + in, out := &in.RequestTimeout, &out.RequestTimeout + *out = new(string) + **out = **in + } return } diff --git a/pkg/openapi/openapi_generated.go b/pkg/openapi/openapi_generated.go index 5f97c2fe6ee..47eb2815d89 100644 --- a/pkg/openapi/openapi_generated.go +++ b/pkg/openapi/openapi_generated.go @@ -2849,7 +2849,7 @@ func schema_pkg_apis_garden_v1beta1_Hibernation(ref common.ReferenceCallback) co }, "schedules": { SchemaProps: spec.SchemaProps{ - Description: "Schedule determines the hibernation schedule.", + Description: "Schedules determine the hibernation schedules.", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ @@ -4280,6 +4280,13 @@ func schema_pkg_apis_garden_v1beta1_OpenStackProfile(ref common.ReferenceCallbac Format: "", }, }, + "requestTimeout": { + SchemaProps: spec.SchemaProps{ + Description: "RequestTimeout specifies the HTTP timeout against the OpenStack API.", + Type: []string{"string"}, + Format: "", + }, + }, }, Required: []string{"constraints", "keystoneURL"}, }, diff --git a/pkg/operation/cloudbotanist/openstackbotanist/controlplane.go b/pkg/operation/cloudbotanist/openstackbotanist/controlplane.go index f1d6fb736c1..4e782bfee68 100644 --- a/pkg/operation/cloudbotanist/openstackbotanist/controlplane.go +++ b/pkg/operation/cloudbotanist/openstackbotanist/controlplane.go @@ -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 }