diff --git a/README.md b/README.md index ecc1c4a8..4ed699ad 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ This also works when an instance is being terminated: the asg-sync will remove t > Because the asg-sync works on a polling-based model, there will be a delay between the instance going to a > terminating state and the asg-sync removing its IP from NGINX Plus. To guarantee that NGINX Plus doesn't send any > requests to a terminated instance, make sure the instance goes to the `Terminating:Wait` state for a period greater -> than the interval `sync_interval_in_seconds`. +> than the interval `sync_interval`. ## Configuration for Cloud Providers diff --git a/build/config.yaml.example b/build/config.yaml.example index 62b1db8d..77adfd6b 100644 --- a/build/config.yaml.example +++ b/build/config.yaml.example @@ -3,7 +3,7 @@ # cloud_provider: AWS # region: us-west-2 # api_endpoint: http://127.0.0.1:8080/api -# sync_interval_in_seconds: 5 +# sync_interval: 5s # upstreams: # - name: backend1 # autoscaling_group: backend-group-1 @@ -24,7 +24,7 @@ # subscription_id: my_subscription_id # resource_group_name: my_resource_group # api_endpoint: http://127.0.0.1:8080/api -# sync_interval_in_seconds: 5 +# sync_interval: 5s # upstreams: # - name: backend1 # virtual_machine_scale_set: backend-group-1 diff --git a/cmd/sync/aws.go b/cmd/sync/aws.go index 77d8516d..bd4fea40 100644 --- a/cmd/sync/aws.go +++ b/cmd/sync/aws.go @@ -14,7 +14,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/autoscaling" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/ec2/types" - yaml "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v3" ) // AWSClient allows you to get the list of IP addresses of instances of an Auto Scaling group. It implements the CloudProvider interface. @@ -242,20 +242,20 @@ func prepareBatches(maxItems int, items []string) [][]string { // Configuration for AWS Cloud Provider type awsConfig struct { - Region string - Upstreams []awsUpstream + Region string `yaml:"region"` + Upstreams []awsUpstream `yaml:"upstreams"` } type awsUpstream struct { - Name string + Name string `yaml:"name"` AutoscalingGroup string `yaml:"autoscaling_group"` - Kind string + Kind string `yaml:"kind"` FailTimeout string `yaml:"fail_timeout"` SlowStart string `yaml:"slow_start"` - Port int - MaxConns int `yaml:"max_conns"` - MaxFails int `yaml:"max_fails"` - InService bool `yaml:"in_service"` + Port int `yaml:"port"` + MaxConns int `yaml:"max_conns"` + MaxFails int `yaml:"max_fails"` + InService bool `yaml:"in_service"` } func validateAWSConfig(cfg *awsConfig) error { diff --git a/cmd/sync/azure.go b/cmd/sync/azure.go index a65b9c8e..76109a65 100644 --- a/cmd/sync/azure.go +++ b/cmd/sync/azure.go @@ -8,7 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute" "github.com/Azure/azure-sdk-for-go/profiles/latest/network/mgmt/network" "github.com/Azure/go-autorest/autorest/azure/auth" - yaml "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v3" ) // AzureClient allows you to get the list of IP addresses of VirtualMachines of a VirtualMachine Scale Set. It implements the CloudProvider interface. @@ -147,20 +147,20 @@ func (client *AzureClient) GetUpstreams() []Upstream { } type azureConfig struct { - SubscriptionID string `yaml:"subscription_id"` - ResourceGroupName string `yaml:"resource_group_name"` - Upstreams []azureUpstream + SubscriptionID string `yaml:"subscription_id"` + ResourceGroupName string `yaml:"resource_group_name"` + Upstreams []azureUpstream `yaml:"upstreams"` } type azureUpstream struct { - Name string + Name string `yaml:"name"` VMScaleSet string `yaml:"virtual_machine_scale_set"` - Kind string + Kind string `yaml:"kind"` FailTimeout string `yaml:"fail_timeout"` SlowStart string `yaml:"slow_start"` - Port int - MaxConns int `yaml:"max_conns"` - MaxFails int `yaml:"max_fails"` + Port int `yaml:"port"` + MaxConns int `yaml:"max_conns"` + MaxFails int `yaml:"max_fails"` } func validateAzureConfig(cfg *azureConfig) error { diff --git a/cmd/sync/config.go b/cmd/sync/config.go index d6935e31..97fa5fba 100644 --- a/cmd/sync/config.go +++ b/cmd/sync/config.go @@ -5,14 +5,14 @@ import ( "fmt" "time" - yaml "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v3" ) // commonConfig stores the configuration parameters common to all providers. type commonConfig struct { APIEndpoint string `yaml:"api_endpoint"` CloudProvider string `yaml:"cloud_provider"` - SyncInterval time.Duration `yaml:"sync_interval_in_seconds"` + SyncInterval time.Duration `yaml:"sync_interval"` } func parseCommonConfig(data []byte) (*commonConfig, error) { @@ -35,7 +35,7 @@ func validateCommonConfig(cfg *commonConfig) error { return fmt.Errorf(errorMsgFormat, "api_endpoint") } - if cfg.SyncInterval == 0 { + if cfg.SyncInterval <= 0 { return errors.New(intervalErrorMsg) } diff --git a/cmd/sync/config_test.go b/cmd/sync/config_test.go index 5d792c50..bc99edd8 100644 --- a/cmd/sync/config_test.go +++ b/cmd/sync/config_test.go @@ -5,7 +5,7 @@ import "testing" var validYaml = []byte(` cloud_provider: AWS api_endpoint: http://127.0.0.1:8080/api -sync_interval_in_seconds: 5 +sync_interval: 5s `) type testInputCommon struct { @@ -29,7 +29,7 @@ func getInvalidCommonConfigInput() []*testInputCommon { invalidSyncIntervalCfg := getValidCommonConfig() invalidSyncIntervalCfg.SyncInterval = 0 - input = append(input, &testInputCommon{invalidSyncIntervalCfg, "invalid sync_interval_in_seconds"}) + input = append(input, &testInputCommon{invalidSyncIntervalCfg, "invalid sync_interval"}) return input } diff --git a/cmd/sync/errormessages.go b/cmd/sync/errormessages.go index 184cfca6..236cd2b2 100644 --- a/cmd/sync/errormessages.go +++ b/cmd/sync/errormessages.go @@ -2,7 +2,7 @@ package main const ( errorMsgFormat = "the mandatory field %v is either empty or missing in the config file" - intervalErrorMsg = "the mandatory field sync_interval_in_seconds is either 0 or missing in the config file" + intervalErrorMsg = "the mandatory field sync_interval is either 0, negative or missing in the config file" cloudProviderErrorMsg = "the field cloud_provider has invalid value %v in the config file" defaultCloudProvider = "AWS" upstreamNameErrorMsg = "the mandatory field name is either empty or missing for an upstream in the config file" diff --git a/cmd/sync/main.go b/cmd/sync/main.go index ac61f3ee..abf2a2f5 100644 --- a/cmd/sync/main.go +++ b/cmd/sync/main.go @@ -163,7 +163,7 @@ func main() { } select { - case <-time.After(commonConfig.SyncInterval * time.Second): //nolint:durationcheck + case <-time.After(commonConfig.SyncInterval): case <-sigterm: log.Println("Terminating...") return diff --git a/examples/aws.md b/examples/aws.md index 927d0cde..42896b6c 100644 --- a/examples/aws.md +++ b/examples/aws.md @@ -25,7 +25,7 @@ nginx-asg-sync is configured in **/etc/nginx/config.yaml**. ```yaml region: us-west-2 api_endpoint: http://127.0.0.1:8080/api -sync_interval_in_seconds: 5 +sync_interval: 5s cloud_provider: AWS upstreams: - name: backend-one @@ -48,8 +48,8 @@ upstreams: ``` - The `api_endpoint` key defines the NGINX Plus API endpoint. -- The `sync_interval_in_seconds` key defines the synchronization interval: nginx-asg-sync checks for scaling updates - every 5 seconds. +- The `sync_interval` key defines the synchronization interval: nginx-asg-sync checks for scaling updates + every 5 seconds. The value is a string that represents a duration (e.g., `5s`). The maximum unit is hours. - The `cloud_provider` key defines a cloud provider that will be used. The default is `AWS`. This means the key can be empty if using AWS. Possible values are: `AWS`, `Azure`. - The `region` key defines the AWS region where we deploy NGINX Plus and the Auto Scaling groups. Setting `region` to diff --git a/examples/azure.md b/examples/azure.md index e15e8c62..8b083316 100644 --- a/examples/azure.md +++ b/examples/azure.md @@ -26,7 +26,7 @@ nginx-asg-sync is configured in **/etc/nginx/config.yaml**. ```yaml api_endpoint: http://127.0.0.1:8080/api -sync_interval_in_seconds: 5 +sync_interval: 5s cloud_provider: Azure subscription_id: my_subscription_id resource_group_name: my_resource_group @@ -50,8 +50,8 @@ upstreams: ``` - The `api_endpoint` key defines the NGINX Plus API endpoint. -- The `sync_interval_in_seconds` key defines the synchronization interval: nginx-asg-sync checks for scaling updates - every 5 seconds. +- The `sync_interval` key defines the synchronization interval: nginx-asg-sync checks for scaling updates + every 5 seconds. The value is a string that represents a duration (e.g., `5s`). The maximum unit is hours. - The `cloud_provider` key defines a Cloud Provider that will be used. The default is `AWS`. This means the key can be empty if using AWS. Possible values are: `AWS`, `Azure`. - The `subscription_id` key defines the Azure unique subscription id that identifies your Azure subscription. diff --git a/go.mod b/go.mod index f5cb7084..89260474 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/autoscaling v1.43.4 github.com/aws/aws-sdk-go-v2/service/ec2 v1.175.1 github.com/nginxinc/nginx-plus-go-client v1.3.0 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( diff --git a/go.sum b/go.sum index fd722629..54547545 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,7 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=