Skip to content

Update module gopkg.in/yaml.v2 to v3 #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions build/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions cmd/sync/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions cmd/sync/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/sync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/sync/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sync/errormessages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Loading