From c0b9aa1e1c83b8d7fdfbace2f76c110b9b5738a2 Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Sat, 8 Jun 2024 12:25:27 +0200 Subject: [PATCH] Set APIDefaultTimeout default value through webhooks Like we did for CronJobs and ContainerImage, this patch enforces the same default defined by kubebuilder to make sure we don't end up creating the CR with wrong values (e.g., apiTimeout = 0). Signed-off-by: Francesco Pantano --- api/v1beta1/common_types.go | 2 ++ api/v1beta1/manila_webhook.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index f00a770a..b74f652c 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -33,6 +33,8 @@ const ( DBPurgeDefaultAge = 30 //DBPurgeDefaultSchedule is in crontab format, and the default runs the job once every day DBPurgeDefaultSchedule = "1 0 * * *" + // APIDefaultTimeout indicates the default APITimeout for HAProxy and Apache, defaults to 60 seconds + APIDefaultTimeout = 60 ) // ManilaTemplate defines common input parameters used by all Manila services diff --git a/api/v1beta1/manila_webhook.go b/api/v1beta1/manila_webhook.go index 0e02fa96..6af18cd1 100644 --- a/api/v1beta1/manila_webhook.go +++ b/api/v1beta1/manila_webhook.go @@ -44,6 +44,7 @@ type ManilaDefaults struct { ShareContainerImageURL string DBPurgeAge int DBPurgeSchedule string + APITimeout int } var manilaDefaults ManilaDefaults @@ -61,6 +62,7 @@ func SetupDefaults() { ShareContainerImageURL: util.GetEnvVar("RELATED_IMAGE_MANILA_SHARE_IMAGE_URL_DEFAULT", ManilaShareContainerImage), DBPurgeAge: DBPurgeDefaultAge, DBPurgeSchedule: DBPurgeDefaultSchedule, + APITimeout: APIDefaultTimeout, } manilalog.Info("Manila defaults initialized", "defaults", manilaDefaults) @@ -109,6 +111,10 @@ func (spec *ManilaSpec) Default() { // Default - set defaults for this Manila spec base func (spec *ManilaSpecBase) Default() { + if spec.APITimeout == 0 { + spec.APITimeout = manilaDefaults.APITimeout + } + if spec.DBPurge.Age == 0 { spec.DBPurge.Age = manilaDefaults.DBPurgeAge }