Skip to content

Commit

Permalink
Merge pull request #43 from SunSince90/retrieve-network
Browse files Browse the repository at this point in the history
Support Cloud Metadata
  • Loading branch information
ljakab authored Jun 25, 2021
2 parents c39790a + c5e5fe8 commit aaead37
Show file tree
Hide file tree
Showing 23 changed files with 742 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ bin
*~
deploy/settings/*.json
deploy/*_generated.yaml

# All backup file, including bak1, bak2 and whatever
*.bak*
3 changes: 3 additions & 0 deletions deploy/settings/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ serviceRegistry:
gcpServiceDirectory:
defaultRegion: <region>
projectID: <project>
cloudMetadata:
network: auto
subNetwork: auto

9 changes: 9 additions & 0 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [Namespace Lists](#namespace-lists)
* [Namespace List Policy](#namespace-list-policy)
* [Allowed Annotations](#allowed-annotations)
* [Cloud Metadata](#cloud-metadata)
* [Deploy](#deploy)

## How it Works
Expand Down Expand Up @@ -130,6 +131,14 @@ If a service does not have **at least** one of the allowed annotations, then it

You can define which annotations are allowed by setting up [configurations](./configuration.md#allow-annotations).

## Cloud Metadata

As the name suggests, *Cloud Metadata* are data that contain information about the Kubernetes cluster that is hosting the operator and the services that are going to be registered.
Such data can be the *Network*, *Subnetwork*, etc. The operator is able to retrieve some values automatically, depending on the Kubernetes platform, e.g. *GKE* or *EKS* but you can also provide some values manually through configuration.
These values will be stored in all registered services to be consumed by anyone interested in them, e.g. the CN-WAN Reader and the CN-WAN Adaptor.

To learn how to define them look at this [section](./configuration.md#cloud-metadata).

## Deploy

There are two ways to deploy the operator, according to your use case and knowledge of Kubernetes:
Expand Down
35 changes: 35 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This section will guide you through the steps you need to take to configure the
* [Format](#format)
* [Set the Namespace List Policy](#set-the-namespace-list-policy)
* [Allow Annotations](#allow-annotations)
* [Cloud Metadata](#cloud-metadata)
* [Service registry settings](#service-registry-settings)
* [Deploy settings](#deploy-settings)
* [Update settings](#update-settings)
Expand All @@ -32,6 +33,9 @@ serviceRegistry:
gcpServiceDirectory:
defaultRegion: <region>
projectID: <project>
cloudMetadata:
network: auto
subNetwork: auto
```
## Set the Namespace List Policy
Expand Down Expand Up @@ -98,6 +102,37 @@ name-with-no-prefix: simple-value

Finally, if you leave this empty - as `annotations: []`, then no service will match this and, therefore, no service will be registered.

## Cloud Metadata

Cloud Metadata can be registered automatically through the `cloudMetadata` setting.

You can provide manual values by entering the information you want like this:

```yaml
cloudMetadata:
network: my-vpc-id
subNetwork: my-subnet-id
```

or automatically as:

```yaml
cloudMetadata:
network: auto
subNetwork: auto
```

and the Operator will try to detect such information on its own. You can remove a field, e.g. `subNetwork`, from the settings if you don't want that to be registered.

These values will be registered on a service metadata as:

```text
cnwan.io/network: <name-or-id>
cnwan.io/sub-network: <name-or-id>
```

Additionally, `cnwan.io/platform: <name>` will also be included if the operator detects you are running in a managed cluster.

## Service registry settings

Under `serviceRegistry` you define which service registry to use and how the operator should connect to it or manage its objects.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
cloud.google.com/go v0.72.0
github.com/aws/aws-sdk-go v1.38.60
github.com/go-logr/logr v0.1.0
github.com/googleapis/gax-go v1.0.3
github.com/grpc-ecosystem/grpc-gateway v1.14.6 // indirect
Expand All @@ -14,6 +15,7 @@ require (
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
go.uber.org/zap v1.10.0
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5 // indirect
golang.org/x/tools v0.1.0 // indirect
google.golang.org/api v0.36.0
google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc
google.golang.org/grpc v1.34.0
Expand Down
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.38.60 h1:MgyEsX0IMwivwth1VwEnesBpH0vxbjp5a0w1lurMOXY=
github.com/aws/aws-sdk-go v1.38.60/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -313,6 +315,10 @@ github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -402,6 +408,8 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down Expand Up @@ -605,6 +613,8 @@ golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
Expand Down Expand Up @@ -676,6 +686,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3 h1:kzM6+9dur93BcC2kVlYl34cHU+TYZLanmpSJHVMmL64=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -745,6 +757,8 @@ golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82u
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a h1:+77BOOi9CMFjpy3D2P/OnfSSmC/Hx/fGAQJUAQaM2gc=
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
12 changes: 11 additions & 1 deletion internal/types/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type Settings struct {

// DEPRECATED: include this under serviceRegistry instead of here.
// TODO: remove this on v0.6.0
Gcloud *GcloudSettings `yaml:"gcloud"`
Gcloud *GcloudSettings `yaml:"gcloud"`
CloudMetadata *CloudMetadata `yaml:"cloudMetadata"`
}

// GcloudSettings holds gcloud settings
Expand Down Expand Up @@ -142,3 +143,12 @@ type EtcdEndpoint struct {
Host string `yaml:"host"`
Port *int `yaml:"port"`
}

// CloudMetadata contains data and configuration about the cloud provider
// that is hosting the cluster, if any.
type CloudMetadata struct {
// Network name
Network *string `yaml:"network"`
// SubNetwork name
SubNetwork *string `yaml:"subNetwork"`
}
16 changes: 16 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ func ParseAndValidateSettings(settings *types.Settings) (*types.Settings, error)
}

finalSettings := &types.Settings{}
if settings.CloudMetadata != nil {
clCfg := settings.CloudMetadata
finalCfg := &types.CloudMetadata{}

if clCfg.Network != nil && *clCfg.Network != "" {
finalCfg.Network = clCfg.Network
}
if clCfg.SubNetwork != nil && *clCfg.SubNetwork != "" {
finalCfg.SubNetwork = clCfg.SubNetwork
}

if finalCfg.Network != nil || finalCfg.SubNetwork != nil {
finalSettings.CloudMetadata = finalCfg
}
}

if settings.Namespace.ListPolicy != types.AllowList && settings.Namespace.ListPolicy != types.BlockList {
// Probably we could revert to using a default value here, but I think
// it's better not to confuse the user with unexpected behaviors and
Expand Down
Loading

0 comments on commit aaead37

Please sign in to comment.