From 99ea94764dd31bad9740ce3c09f72e178ec4ea93 Mon Sep 17 00:00:00 2001 From: Jorge Marey Date: Sun, 14 Jul 2024 00:05:41 +0200 Subject: [PATCH] Add name_attribute config option --- CHANGELOG.md | 8 +++++++- README.md | 4 ++-- plugin/openstack.go | 13 +++++++++---- plugin/plugin.go | 5 +++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9501c96..18e700a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ +## 0.4.2 (Jul 15, 2024) + +FEATURES: +* Add `name_attribute` to specify the attribute to use when selecting the instance name to +search for the instance to downscale + ## 0.4.1 (Jun 27, 2024) FEATURES: * Updated golang to 1.22.4 * Updated autoscaler dependendy to 0.4.4 -* floatingip_pool_name can now be specified to attach a floating ip for created instances +* `floatingip_pool_name` can now be specified to attach a floating ip for created instances * fix cache data being renoved after reload ## 0.4.0 (Nov 23, 2023) diff --git a/README.md b/README.md index 90e2abd..b022053 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ target "os-nova" { * `cacert_file` `(string: "")` - Location of the certificate to use for OS APIs verification * `insecure_skip_verify` `(string: "")` - Skip TLS certificate verification -* `id_attribute` `(string: "")` - The nomad attribute to use that maps the nomad client to an OS Compute instance. By default `unique.platform.aws.hostname` is used and a previous search is needed -to get the instance id using the instance name +* `name_attribute` `(string: "unique.platform.aws.hostname")` - The nomad attribute that reflects the instance name. This needs to be used for searching the instance ID in the proccess of downscaling +* `id_attribute` `(string: "")` - The nomad attribute to use that maps the nomad client to an OS Compute instance. If not specified then a previous search is needed to get the instance id using the instance name using `name_attribute`. If this is specified it takes priority over `name_attribute` * `action_timeout` `(string: "")` - The timeout to use when performing create and delete actions over servers. This should be specified as a duration. The default vaule is 90s * `ignored_states` `(string: "")` - A comma-separated list of server states to be ignored. The complete list can be seen [here](https://docs.openstack.org/api-guide/compute/server_concepts.html) diff --git a/plugin/openstack.go b/plugin/openstack.go index 53c4fb5..3cecc1a 100644 --- a/plugin/openstack.go +++ b/plugin/openstack.go @@ -30,13 +30,14 @@ import ( ) const ( - version = "v0.4.1" + version = "v0.4.2" ) const ( defaultActionTimeout = 120 * time.Second defaultStatusTImeout = 5 * time.Minute defaultScaleTimeout = 2 * time.Hour + defaultNameProperty = "unique.platform.aws.hostname" poolTag = "na_pool:%s" defaultConfigValueSeparator = "," configKVSeparator = "=" @@ -742,10 +743,14 @@ func (t *TargetPlugin) getInstancePortID(id string) (string, error) { // osNovaNodeIDMapBuilder is used to identify the Opensack Nova ID of a Nomad node using // the relevant attribute value. -func osNovaNodeIDMapBuilder(property string) scaleutils.ClusterNodeIDLookupFunc { +func osNovaNodeIDMapBuilder(nameProperty, idProperty string) scaleutils.ClusterNodeIDLookupFunc { var isMeta bool - if property == "" { - property = "unique.platform.aws.hostname" + property := defaultNameProperty + if nameProperty != "" { + property = nameProperty + } + if idProperty != "" { + property = idProperty } if strings.HasPrefix(property, "meta.") { isMeta = true diff --git a/plugin/plugin.go b/plugin/plugin.go index 55c8f88..14cc578 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -29,7 +29,8 @@ const ( configKeyCACertFile = "cacert_file" configKeyInsecure = "insecure_skip_verify" - configKeyNodeIDAttr = "id_attribute" + configKeyNodeIDAttr = "id_attribute" + configKeyNodeNameAttr = "name_attribute" configKeyName = "name" configKeyNamePrefix = "name_prefix" @@ -120,7 +121,7 @@ func (t *TargetPlugin) SetConfig(config map[string]string) error { // Store and set the remote ID callback function. t.clusterUtils = clusterUtils - t.clusterUtils.ClusterNodeIDLookupFunc = osNovaNodeIDMapBuilder(config[configKeyNodeIDAttr]) + t.clusterUtils.ClusterNodeIDLookupFunc = osNovaNodeIDMapBuilder(config[configKeyNodeNameAttr], config[configKeyNodeIDAttr]) t.idMapper = config[configKeyNodeIDAttr] != "" return nil