From 9b7c9d7e1ce097d7b2351f0b9e8f4b0b0e080550 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Mon, 20 Sep 2021 09:17:17 +0200 Subject: [PATCH 01/10] Move "enable" "monitor" Rename "enable" to "monitor" Signed-off-by: Elis Lulja --- artifacts/settings/settings.yaml | 2 +- controllers/namespace_controller.go | 44 +++++++++---------- controllers/service_controller.go | 16 +++---- docs/concepts.md | 18 ++++---- docs/configuration.md | 12 ++--- docs/etcd/operator_configuration.md | 4 +- docs/etcd/quickstart.md | 6 +-- .../configure_with_operator.md | 4 +- docs/gcp_service_directory/quickstart.md | 8 ++-- internal/types/settings.go | 6 +-- internal/utils/utils.go | 2 +- internal/utils/utils_test.go | 22 +++++----- main.go | 20 ++++----- 13 files changed, 82 insertions(+), 82 deletions(-) diff --git a/artifacts/settings/settings.yaml b/artifacts/settings/settings.yaml index bb64227..bd1263a 100644 --- a/artifacts/settings/settings.yaml +++ b/artifacts/settings/settings.yaml @@ -1,4 +1,4 @@ -enableNamespaceByDefault: false +monitorNamespacesByDefault: false serviceAnnotations: [] serviceRegistry: etcd: diff --git a/controllers/namespace_controller.go b/controllers/namespace_controller.go index c1cafea..2180422 100644 --- a/controllers/namespace_controller.go +++ b/controllers/namespace_controller.go @@ -32,18 +32,18 @@ import ( ) const ( - enabledLabel string = "operator.cnwan.io/enabled" + monitorLabel string = "operator.cnwan.io/monitor" ) // NamespaceReconciler reconciles a Namespace object type NamespaceReconciler struct { client.Client - Log logr.Logger - Scheme *runtime.Scheme - EnableNamespaceByDefault bool - nsLastConf map[string]bool - lock sync.Mutex - ServRegBroker *sr.Broker + Log logr.Logger + Scheme *runtime.Scheme + MonitorNamespacesByDefault bool + nsLastConf map[string]bool + lock sync.Mutex + ServRegBroker *sr.Broker } // +kubebuilder:rbac:groups=core,resources=namespaces,verbs=get;list;watch;create;update;patch;delete @@ -95,27 +95,27 @@ func (r *NamespaceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { return ctrl.Result{}, nil } - change, nsIsEnabled := func() (bool, bool) { - var currentlyEnabled bool - switch strings.ToLower(ns.Labels[enabledLabel]) { - case "yes": - currentlyEnabled = true - case "no": - currentlyEnabled = false + change, nsIsMonitored := func() (bool, bool) { + var currentlyMonitored bool + switch strings.ToLower(ns.Labels[monitorLabel]) { + case "true": + currentlyMonitored = true + case "false": + currentlyMonitored = false default: - currentlyEnabled = r.EnableNamespaceByDefault + currentlyMonitored = r.MonitorNamespacesByDefault } r.lock.Lock() defer r.lock.Unlock() - previouslyEnabled, existed := r.nsLastConf[ns.Name] + previouslyMonitored, existed := r.nsLastConf[ns.Name] if !existed { - previouslyEnabled = r.EnableNamespaceByDefault + previouslyMonitored = r.MonitorNamespacesByDefault } - changed := currentlyEnabled != previouslyEnabled - r.nsLastConf[ns.Name] = currentlyEnabled - return changed, currentlyEnabled + changed := currentlyMonitored != previouslyMonitored + r.nsLastConf[ns.Name] = currentlyMonitored + return changed, currentlyMonitored }() if !change { return ctrl.Result{}, nil @@ -129,7 +129,7 @@ func (r *NamespaceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { // First, check the services for _, serv := range servList.Items { - if !nsIsEnabled { + if !nsIsMonitored { if err := r.ServRegBroker.RemoveServ(serv.Namespace, serv.Name, true); err != nil { l.Error(err, "error while deleting service") } @@ -161,7 +161,7 @@ func (r *NamespaceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { } } - if !nsIsEnabled { + if !nsIsMonitored { if err := r.ServRegBroker.RemoveNs(ns.Name, true); err != nil { l.Error(err, "error while deleting service") } diff --git a/controllers/service_controller.go b/controllers/service_controller.go index 7910fb0..2d5cac4 100644 --- a/controllers/service_controller.go +++ b/controllers/service_controller.go @@ -35,10 +35,10 @@ import ( // ServiceReconciler reconciles a Service object type ServiceReconciler struct { client.Client - Log logr.Logger - Scheme *runtime.Scheme - ServRegBroker *sr.Broker - EnableNamespaceByDefault bool + Log logr.Logger + Scheme *runtime.Scheme + ServRegBroker *sr.Broker + MonitorNamespacesByDefault bool } // +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete @@ -82,13 +82,13 @@ func (r *ServiceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { } var shouldWatchNs bool - switch strings.ToLower(ns.Labels[enabledLabel]) { - case "yes": + switch strings.ToLower(ns.Labels[monitorLabel]) { + case "true": shouldWatchNs = true - case "no": + case "false": shouldWatchNs = false default: - shouldWatchNs = r.EnableNamespaceByDefault + shouldWatchNs = r.MonitorNamespacesByDefault } if !shouldWatchNs { diff --git a/docs/concepts.md b/docs/concepts.md index b9c5a3a..7cf2bb3 100644 --- a/docs/concepts.md +++ b/docs/concepts.md @@ -7,7 +7,7 @@ * [Metadata](#metadata) * [Annotations vs Labels](#annotations-vs-labels) * [Ownership](#ownership) -* [Enable namespaces](#enable-namespaces) +* [Monitor namespaces](#monitor-namespaces) * [Allowed Annotations](#allowed-annotations) * [Cloud Metadata](#cloud-metadata) * [Deploy](#deploy) @@ -80,28 +80,28 @@ That being said, the operator will still insert child resources even if the pare Finally, if you wish the operator to manage your pre-existing resources on your service registry, please update all the necessary resources by inserting `owner: cnwan-operator` among their metadata. -## Enable namespaces +## Monitor namespaces -The CN-WAN Operator watches service updates only on *enabled* namespaces. To do so, you need to label a namespace with our reserved label key `operator.cnwan.io/enabled`. +The CN-WAN Operator watches service updates only on *monitored* namespaces. To do so, you need to label a namespace with our reserved label key `operator.cnwan.io/monitor`. -If a namespace is labeled as `operator.cnwan.io/enabled=yes` then the operator will watch service updates happening on that namespace. On the contrary, `operator.cnwan.io/enabled=no` will instruct the operator to stay away from that namespace. +If a namespace is labeled as `operator.cnwan.io/monitor=true` then the operator will watch service updates happening on that namespace. On the contrary, `operator.cnwan.io/monitor=false` will instruct the operator to stay away from that namespace. -This being said, you don't need to rush labelling all namespaces as `operator.cnwan.io/enabled=no` in fear of potentially exposing sensitive data on the service registry: namespaces that do not have such label will be ignored by default, as the operator will pretend it is seeing `operator.cnwan.io/enabled=no`. This is useful in case you think you have few namespaces you want to enable or if you prefer to retain control, even have lots of namespaces to enable. +This being said, you don't need to rush labelling all namespaces as `operator.cnwan.io/monitor=false` in fear of potentially exposing sensitive data on the service registry: namespaces that do not have such label will be ignored by default, as the operator will pretend it is seeing `operator.cnwan.io/monitor=false`. This is useful in case you think you have few namespaces you want to monitor or if you prefer to retain control, even have lots of namespaces to monitor. -Instead, if you have many namespaces to enable and/or find it tedious to manually do so for every single one of them, you can override this behavior via `enableNamespaceByDefault: true` on the [operator settings](./configuration.md#enable-namespace-by-default): this means that the operator will pretend it is seeing `operator.cnwan.io/enabled=yes` and thus watch events in the namespace by default, unless instructed otherwise. This is the opposite scenario from above: now you will need to manually *disable* them. +Instead, if you have many namespaces to monitor and/or find it tedious to manually do so for every single one of them, you can override this behavior via `monitorNamespacesByDefault: true` on the [operator settings](./configuration.md#monitor-namespaces-by-default): this means that the operator will pretend it is seeing `operator.cnwan.io/monitor=true` and thus watch events in the namespace by default, unless instructed otherwise. This is the opposite scenario from above: now you will need to manually *disable* them. Let's see some examples. -To _enable_ monitoring on namespace `hr`, do the following: +To _monitor_ monitoring on namespace `hr`, do the following: ```bash -kubectl label ns hr operator.cnwan.io/enabled=yes +kubectl label ns hr operator.cnwan.io/monitor=true ``` To _disable_ monitoring on namespace `hr`: ```bash -kubectl label ns hr operator.cnwan.io/enabled=no +kubectl label ns hr operator.cnwan.io/monitor=false ``` Note: append `--overwrite` in case the label already exists. diff --git a/docs/configuration.md b/docs/configuration.md index bf4e162..d00e5eb 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -5,7 +5,7 @@ This section will guide you through the steps you need to take to configure the ## Table of Contents * [Format](#format) -* [Enable namespace by default](#enable-namespace-by-default) +* [Monitor namespaces by default](#monitor-namespace-by-default) * [Allow Annotations](#allow-annotations) * [Cloud Metadata](#cloud-metadata) * [Service registry settings](#service-registry-settings) @@ -17,7 +17,7 @@ This section will guide you through the steps you need to take to configure the The CN-WAN Operator can be configured with the following YAML format. ```yaml -enableNamespaceByDefault: false +monitorNamespacesByDefault: false serviceAnnotations: [] serviceRegistry: etcd: @@ -36,13 +36,13 @@ cloudMetadata: subNetwork: auto ``` -## Enable namespace by default +## Monitor namespace by default -The operator will watch service events only on namespaces that are *enabled*, and to do so you need to explicitly label namespaces with the reserved `operator.cnwan.io/enabled` label key. +The operator will watch service events only on namespaces that are *monitored*, and to do so you need to explicitly label namespaces with the reserved `operator.cnwan.io/monitor` label key. -`enableNamespaceByDefault` will tell the operator what to do when such label is not found: if it does not exist or is false, then the operator will ignore the namespace by default. Otherwise it will watch events inside it. +`monitorNamespacesByDefault` will tell the operator what to do when such label is not found: if it does not exist or is false, then the operator will ignore the namespace by default. Otherwise it will watch events inside it. -if you haven't already, please take a look at [this section](./concepts.md#enable-namespaces) to learn more about this concept. +if you haven't already, please take a look at [this section](./concepts.md#monitor-namespaces) to learn more about this concept. ## Allow Annotations diff --git a/docs/etcd/operator_configuration.md b/docs/etcd/operator_configuration.md index 08bbeec..a078acf 100644 --- a/docs/etcd/operator_configuration.md +++ b/docs/etcd/operator_configuration.md @@ -9,7 +9,7 @@ The included directory `deploy/settings` contains a `settings.yaml` for you to m For your convenience, here is how the settings for the CN-WAN Operator looks like: ```yaml -enableNamespaceByDefault: false +monitorNamespacesByDefault: false serviceAnnotations: [] serviceRegistry: etcd: @@ -28,7 +28,7 @@ serviceRegistry: We will only cover etcd settings here, so you can go ahead and remove the whole `gcpServiceDirectory` settings: ```yaml -enableNamespaceByDefault: false +monitorNamespacesByDefault: false serviceAnnotations: [] serviceRegistry: etcd: diff --git a/docs/etcd/quickstart.md b/docs/etcd/quickstart.md index db7a394..a956c28 100644 --- a/docs/etcd/quickstart.md +++ b/docs/etcd/quickstart.md @@ -39,7 +39,7 @@ metadata: name: training-app-namespace labels: purpose: "test" - operator.cnwan.io/enabled: "yes" + operator.cnwan.io/monitor: "true" --- kind: Service apiVersion: v1 @@ -63,7 +63,7 @@ spec: EOF ``` -Please notice that the namespace has this label: `operator.cnwan.io/enabled: yes` which inserts the namespace in the opeartor's [allowlist](../concepts.md#namespace-lists). Also notice that the service has annotations that will be registered as [metadata](../concepts.md#metadata): +Please notice that the namespace has this label: `operator.cnwan.io/monitor: true` which inserts the namespace in the opeartor's [allowlist](../concepts.md#namespace-lists). Also notice that the service has annotations that will be registered as [metadata](../concepts.md#metadata): ```yaml annotations: @@ -97,7 +97,7 @@ It doesn't really matter that there is no pod backing this service for now, as t From the root directory navigate to `deploy/settings` and modify the file `settings.yaml` to look like this - please provide appropriate values for `host` and `port` keys with your etcd cluster's addresses: ```yaml -enableNamespaceByDefault: false +monitorNamespacesByDefault: false servicennotations: - traffic-profile - version diff --git a/docs/gcp_service_directory/configure_with_operator.md b/docs/gcp_service_directory/configure_with_operator.md index 27ce204..e746597 100644 --- a/docs/gcp_service_directory/configure_with_operator.md +++ b/docs/gcp_service_directory/configure_with_operator.md @@ -9,7 +9,7 @@ The included directory `deploy/settings` contains a `settings.yaml` for you to m For your convenience, here is how the settings for the CN-WAN Operator looks like: ```yaml -enableNamespaceByDefaut: false +monitorNamespacesByDefault: false serviceAnnotations: [] serviceRegistry: etcd: @@ -28,7 +28,7 @@ serviceRegistry: We will only cover Service Directory settings here, so you can go ahead and remove the whole `etcd` settings: ```yaml -enableNamespaceByDefaut: false +monitorNamespacesByDefault: false serviceAnnotations: [] serviceRegistry: gcpServiceDirectory: diff --git a/docs/gcp_service_directory/quickstart.md b/docs/gcp_service_directory/quickstart.md index 4fd5e4f..789ad6b 100644 --- a/docs/gcp_service_directory/quickstart.md +++ b/docs/gcp_service_directory/quickstart.md @@ -41,7 +41,7 @@ metadata: name: training-app-namespace labels: purpose: "test" - operator.cnwan.io/enabled: "yes" + operator.cnwan.io/monitor: "true" --- kind: Service apiVersion: v1 @@ -65,7 +65,7 @@ spec: EOF ``` -Please notice that the namespace has this label: `operator.cnwan.io/enabled: yes` which inserts the namespace in the opeartor's [allowlist](./concepts.md#namespace-lists). Also notice that the service has annotations that will be registered as [metadata](./concepts.md#metadata): +Please notice that the namespace has this label: `operator.cnwan.io/monitor: true` which inserts the namespace in the opeartor's [allowlist](./concepts.md#namespace-lists). Also notice that the service has annotations that will be registered as [metadata](./concepts.md#metadata): ```yaml annotations: @@ -107,7 +107,7 @@ serviceRegistry: gcpServiceDirectory: defaultRegion: projectID: -enableNamespaceByDefault: false +monitorNamespacesByDefault: false serviceAnnotations: - traffic-profile - version @@ -127,7 +127,7 @@ If you plan to run the operator in GKE, you can just write: ```yaml serviceRegistry: gcpServiceDirectory: {} -enableNamespaceByDefault: false +monitorNamespacesByDefault: false serviceAnnotations: - traffic-profile - version diff --git a/internal/types/settings.go b/internal/types/settings.go index 9e4afda..86e76ab 100644 --- a/internal/types/settings.go +++ b/internal/types/settings.go @@ -42,9 +42,9 @@ const ( // Settings of the application type Settings struct { - EnableNamespaceByDefault bool `yaml:"enableNamespaceByDefault"` - Service ServiceSettings `yaml:",inline"` - *ServiceRegistrySettings `yaml:"serviceRegistry"` + MonitorNamespacesByDefault bool `yaml:"monitorNamespacesByDefault"` + Service ServiceSettings `yaml:",inline"` + *ServiceRegistrySettings `yaml:"serviceRegistry"` // DEPRECATED: include this under serviceRegistry instead of here. // TODO: remove this on v0.6.0 diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 7e7ea00..878cabe 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -82,7 +82,7 @@ func ParseAndValidateSettings(settings *types.Settings) (*types.Settings, error) return nil, fmt.Errorf("no settings provided") } - finalSettings := &types.Settings{EnableNamespaceByDefault: settings.EnableNamespaceByDefault} + finalSettings := &types.Settings{MonitorNamespacesByDefault: settings.MonitorNamespacesByDefault} if settings.CloudMetadata != nil { clCfg := settings.CloudMetadata finalCfg := &types.CloudMetadata{} diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 716e8a1..1dd635b 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -114,14 +114,14 @@ func TestParseAndValidateSettings(t *testing.T) { }, { id: "no-service-registry-settings", - arg: &types.Settings{EnableNamespaceByDefault: true}, + arg: &types.Settings{MonitorNamespacesByDefault: true}, expErr: fmt.Errorf("no service registry provided"), }, { id: "no-service-registry-fields", arg: &types.Settings{ - EnableNamespaceByDefault: true, - ServiceRegistrySettings: &types.ServiceRegistrySettings{}, + MonitorNamespacesByDefault: true, + ServiceRegistrySettings: &types.ServiceRegistrySettings{}, }, expErr: fmt.Errorf("no service registry provided"), }, @@ -142,7 +142,7 @@ func TestParseAndValidateSettings(t *testing.T) { { id: "etcd-uname-pass-auth", arg: &types.Settings{ - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, ServiceRegistrySettings: &types.ServiceRegistrySettings{ EtcdSettings: &types.EtcdSettings{ Authentication: types.EtcdAuthWithUsernamePassw, @@ -153,7 +153,7 @@ func TestParseAndValidateSettings(t *testing.T) { }, }, expRes: &types.Settings{ - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, ServiceRegistrySettings: &types.ServiceRegistrySettings{ EtcdSettings: &types.EtcdSettings{ Authentication: types.EtcdAuthWithUsernamePassw, @@ -220,7 +220,7 @@ func TestParseAndValidateSettings(t *testing.T) { { id: "both-but-only-etcd-is-there", arg: &types.Settings{ - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, @@ -234,7 +234,7 @@ func TestParseAndValidateSettings(t *testing.T) { }, }, expRes: &types.Settings{ - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, @@ -256,14 +256,14 @@ func TestParseAndValidateSettings(t *testing.T) { DefaultRegion: "ca", }, }, - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, ServiceRegistrySettings: &types.ServiceRegistrySettings{}, }, expRes: &types.Settings{ - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, @@ -284,7 +284,7 @@ func TestParseAndValidateSettings(t *testing.T) { DefaultRegion: "old", }, }, - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, @@ -296,7 +296,7 @@ func TestParseAndValidateSettings(t *testing.T) { }, }, expRes: &types.Settings{ - EnableNamespaceByDefault: true, + MonitorNamespacesByDefault: true, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, diff --git a/main.go b/main.go index e5bd387..cd0ef12 100644 --- a/main.go +++ b/main.go @@ -210,22 +210,22 @@ func main() { } if err = (&controllers.ServiceReconciler{ - Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("Service"), - Scheme: mgr.GetScheme(), - ServRegBroker: srBroker, - EnableNamespaceByDefault: settings.EnableNamespaceByDefault, + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("Service"), + Scheme: mgr.GetScheme(), + ServRegBroker: srBroker, + MonitorNamespacesByDefault: settings.MonitorNamespacesByDefault, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Service") returnCode = 8 runtime.Goexit() } if err = (&controllers.NamespaceReconciler{ - Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("Namespace"), - Scheme: mgr.GetScheme(), - ServRegBroker: srBroker, - EnableNamespaceByDefault: settings.EnableNamespaceByDefault, + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("Namespace"), + Scheme: mgr.GetScheme(), + ServRegBroker: srBroker, + MonitorNamespacesByDefault: settings.MonitorNamespacesByDefault, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Namespace") returnCode = 9 From a90783bf8f147a0729d9896a5cabe1086d5eee32 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Fri, 17 Sep 2021 10:55:58 +0200 Subject: [PATCH 02/10] Pass allowed annotations to controllers This commit passes allowed annotations to the controllers, so they have that reference instead of getting it from viper. Signed-off-by: Elis Lulja --- controllers/namespace_controller.go | 1 + controllers/service_controller.go | 1 + main.go | 13 ++----------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/controllers/namespace_controller.go b/controllers/namespace_controller.go index 2180422..38d7768 100644 --- a/controllers/namespace_controller.go +++ b/controllers/namespace_controller.go @@ -41,6 +41,7 @@ type NamespaceReconciler struct { Log logr.Logger Scheme *runtime.Scheme MonitorNamespacesByDefault bool + AllowedAnnotations []string nsLastConf map[string]bool lock sync.Mutex ServRegBroker *sr.Broker diff --git a/controllers/service_controller.go b/controllers/service_controller.go index 2d5cac4..3ec66f4 100644 --- a/controllers/service_controller.go +++ b/controllers/service_controller.go @@ -39,6 +39,7 @@ type ServiceReconciler struct { Scheme *runtime.Scheme ServRegBroker *sr.Broker MonitorNamespacesByDefault bool + AllowedAnnotations []string } // +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete diff --git a/main.go b/main.go index cd0ef12..1716148 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,6 @@ import ( sr "github.com/CloudNativeSDWAN/cnwan-operator/pkg/servregistry" "github.com/CloudNativeSDWAN/cnwan-operator/pkg/servregistry/etcd" sd "github.com/CloudNativeSDWAN/cnwan-operator/pkg/servregistry/gcloud/servicedirectory" - "github.com/spf13/viper" clientv3 "go.etcd.io/etcd/client/v3" "gopkg.in/yaml.v3" corev1 "k8s.io/api/core/v1" @@ -119,16 +118,6 @@ func main() { } setupLog.Info("settings parsed successfully") - // Load the allowed annotations and put into a map, for better - // check afterwards - annotations := settings.Service.Annotations - allowedAnnotations := map[string]bool{} - for _, ann := range annotations { - allowedAnnotations[ann] = true - } - viper.Set(types.AllowedAnnotationsMap, allowedAnnotations) - viper.Set(types.CurrentNamespace, nsName) - persistentMeta := []sr.MetadataPair{} if settings.CloudMetadata != nil { // No need to check for network and subnetwork nil as it was already @@ -215,6 +204,7 @@ func main() { Scheme: mgr.GetScheme(), ServRegBroker: srBroker, MonitorNamespacesByDefault: settings.MonitorNamespacesByDefault, + AllowedAnnotations: settings.Service.Annotations, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Service") returnCode = 8 @@ -226,6 +216,7 @@ func main() { Scheme: mgr.GetScheme(), ServRegBroker: srBroker, MonitorNamespacesByDefault: settings.MonitorNamespacesByDefault, + AllowedAnnotations: settings.Service.Annotations, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Namespace") returnCode = 9 From 95458da6647b54b50d790ecedb708a3d419a8086 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Fri, 17 Sep 2021 10:58:47 +0200 Subject: [PATCH 03/10] Move filterAnnotations to controllers package FilterAnnotations is moved from utils package to controllers, because basically that's the only place where it was actually used. Signed-off-by: Elis Lulja --- controllers/namespace_controller.go | 3 +- controllers/service_controller.go | 3 +- controllers/utils.go | 64 ++++++++++++++++++++++ controllers/utils_test.go | 75 ++++++++++++++++++++++++++ go.mod | 10 ---- go.sum | 82 ----------------------------- internal/utils/utils.go | 44 ---------------- internal/utils/utils_test.go | 72 ------------------------- 8 files changed, 141 insertions(+), 212 deletions(-) create mode 100644 controllers/utils.go create mode 100644 controllers/utils_test.go diff --git a/controllers/namespace_controller.go b/controllers/namespace_controller.go index 38d7768..ca5cb69 100644 --- a/controllers/namespace_controller.go +++ b/controllers/namespace_controller.go @@ -22,7 +22,6 @@ import ( "strings" "sync" - "github.com/CloudNativeSDWAN/cnwan-operator/internal/utils" sr "github.com/CloudNativeSDWAN/cnwan-operator/pkg/servregistry" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" @@ -137,7 +136,7 @@ func (r *NamespaceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { } else { // Get the data in our simpler format // Note: as of now, we are not copying any annotations from a namespace - serv.Annotations = utils.FilterAnnotations(serv.Annotations) + serv.Annotations = filterAnnotations(serv.Annotations, r.AllowedAnnotations) nsData, servData, endpList, err := r.ServRegBroker.Reg.ExtractData(&ns, &serv) if err != nil { l.WithValues("serv-name", servData.Name).Error(err, "error while extracting data from the namespace and service") diff --git a/controllers/service_controller.go b/controllers/service_controller.go index 3ec66f4..f0ba29f 100644 --- a/controllers/service_controller.go +++ b/controllers/service_controller.go @@ -21,7 +21,6 @@ import ( "fmt" "strings" - "github.com/CloudNativeSDWAN/cnwan-operator/internal/utils" sr "github.com/CloudNativeSDWAN/cnwan-operator/pkg/servregistry" "github.com/go-logr/logr" @@ -99,7 +98,7 @@ func (r *ServiceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { // Get the data in our simpler format // Note: as of now, we are not copying any annotations from a namespace - service.Annotations = utils.FilterAnnotations(service.Annotations) + service.Annotations = filterAnnotations(service.Annotations, r.AllowedAnnotations) nsData, servData, endpList, err := r.ServRegBroker.Reg.ExtractData(&ns, &service) if err != nil { l.Error(err, "error while getting data from the namespace and service") diff --git a/controllers/utils.go b/controllers/utils.go new file mode 100644 index 0000000..7e031fc --- /dev/null +++ b/controllers/utils.go @@ -0,0 +1,64 @@ +// Copyright © 2021 Cisco +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// All rights reserved. + +package controllers + +import ( + "fmt" + "strings" +) + +// filterAnnotations is used to remove annotations that should be ignored +// by the operator +func filterAnnotations(currentAnnotations map[string]string, filter []string) map[string]string { + filterMap := map[string]bool{} + for _, ann := range filter { + filterMap[ann] = true + } + + if _, exists := filterMap["*/*"]; exists { + return currentAnnotations + } + + filtered := map[string]string{} + for key, val := range currentAnnotations { + + // Check this key specifically + if _, exists := filterMap[key]; exists { + filtered[key] = val + continue + } + + prefixName := strings.Split(key, "/") + if len(prefixName) != 2 { + // This key is not in prefix/name format + continue + } + + prefixWildcard := fmt.Sprintf("%s/*", prefixName[0]) + if _, exists := filterMap[prefixWildcard]; exists { + filtered[key] = val + continue + } + + wildcardName := fmt.Sprintf("*/%s", prefixName[1]) + if _, exists := filterMap[wildcardName]; exists { + filtered[key] = val + } + } + + return filtered +} diff --git a/controllers/utils_test.go b/controllers/utils_test.go new file mode 100644 index 0000000..48a061e --- /dev/null +++ b/controllers/utils_test.go @@ -0,0 +1,75 @@ +// Copyright © 2021 Cisco +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// All rights reserved. + +package controllers + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFilterAnnotations(t *testing.T) { + annotations := map[string]string{ + "stand-alone": "alone", + "another-stand-alone": "another-alone", + "prefix.io/one": "one", + "prefix.io/two": "two", + "another.io/first": "another-first", + "another.io/second": "another-second", + "yet-another.io/first": "yet-first", + "yet-another.io/second": "yet-second", + } + + cases := []struct { + annotations map[string]string + filter []string + expRes map[string]string + }{ + { + annotations: map[string]string{}, + filter: []string{"whatever"}, + expRes: map[string]string{}, + }, + { + annotations: map[string]string{"whatever": "whatever"}, + filter: []string{}, + expRes: map[string]string{}, + }, + { + annotations: annotations, + filter: []string{"*/*"}, + expRes: annotations, + }, + { + annotations: annotations, + filter: []string{"stand-alone", "prefix.io/*", "*/first"}, + expRes: map[string]string{ + "stand-alone": "alone", + "prefix.io/one": "one", + "prefix.io/two": "two", + "another.io/first": "another-first", + "yet-another.io/first": "yet-first", + }, + }, + } + + a := assert.New(t) + for _, currCase := range cases { + res := filterAnnotations(currCase.annotations, currCase.filter) + a.Equal(currCase.expRes, res) + } +} diff --git a/go.mod b/go.mod index cdcc7e5..acee6a4 100644 --- a/go.mod +++ b/go.mod @@ -26,32 +26,23 @@ require ( github.com/googleapis/gax-go/v2 v2.0.5 // indirect github.com/googleapis/gnostic v0.3.1 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect github.com/imdario/mergo v0.3.9 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.11 // indirect - github.com/magiconair/properties v1.8.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/nxadm/tail v1.4.4 // indirect github.com/onsi/ginkgo v1.14.2 github.com/onsi/gomega v1.10.3 - github.com/pelletier/go-toml v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.11.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.26.0 // indirect github.com/prometheus/procfs v0.6.0 // indirect - github.com/spf13/afero v1.2.2 // indirect - github.com/spf13/cast v1.3.0 // indirect - github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.7.0 - github.com/subosito/gotenv v1.2.0 // indirect go.etcd.io/etcd/api/v3 v3.5.0 go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect go.etcd.io/etcd/client/v3 v3.5.0 @@ -77,7 +68,6 @@ require ( google.golang.org/grpc v1.39.1 google.golang.org/protobuf v1.27.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b diff --git a/go.sum b/go.sum index 21e5b3f..510bb40 100644 --- a/go.sum +++ b/go.sum @@ -33,7 +33,6 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= @@ -58,7 +57,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= @@ -72,10 +70,7 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -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= @@ -85,11 +80,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -101,9 +93,7 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -116,14 +106,12 @@ github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzA github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -306,41 +294,18 @@ github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTV github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk= github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -362,8 +327,6 @@ github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMW github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -380,8 +343,6 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= -github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -389,20 +350,11 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= @@ -417,7 +369,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -431,9 +382,7 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -442,10 +391,8 @@ 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= github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ= @@ -455,44 +402,30 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzzhMQ= github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= -github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -500,8 +433,6 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= -github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= -github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= @@ -512,11 +443,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= -github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= @@ -527,7 +455,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= @@ -560,7 +487,6 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -618,9 +544,7 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -690,11 +614,9 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -784,7 +706,6 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -797,7 +718,6 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -982,8 +902,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= -gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 878cabe..72299e3 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -18,10 +18,8 @@ package utils import ( "fmt" - "strings" "github.com/CloudNativeSDWAN/cnwan-operator/internal/types" - "github.com/spf13/viper" "go.uber.org/zap/zapcore" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -30,48 +28,6 @@ var ( log = zap.New(zap.UseDevMode(false)) ) -// FilterAnnotations is used to remove annotations that should be ignored -// by the operator -func FilterAnnotations(annotations map[string]string) map[string]string { - allowedAnnotations := map[string]bool{} - if viper.Get(types.AllowedAnnotationsMap) != nil { - allowedAnnotations = viper.Get(types.AllowedAnnotationsMap).(map[string]bool) - } - - if _, exists := allowedAnnotations["*/*"]; exists { - return annotations - } - - filtered := map[string]string{} - for key, val := range annotations { - - // Check this key specifically - if _, exists := allowedAnnotations[key]; exists { - filtered[key] = val - continue - } - - prefixName := strings.Split(key, "/") - if len(prefixName) != 2 { - // This key is not in prefix/name format - continue - } - - prefixWildcard := fmt.Sprintf("%s/*", prefixName[0]) - if _, exists := allowedAnnotations[prefixWildcard]; exists { - filtered[key] = val - continue - } - - wildcardName := fmt.Sprintf("*/%s", prefixName[1]) - if _, exists := allowedAnnotations[wildcardName]; exists { - filtered[key] = val - } - } - - return filtered -} - // ParseAndValidateSettings parses the settings and validates them. // // In case of any errors, the settings returned is nil and the error diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 1dd635b..9abf1d0 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -21,81 +21,9 @@ import ( "testing" "github.com/CloudNativeSDWAN/cnwan-operator/internal/types" - "github.com/spf13/viper" . "github.com/stretchr/testify/assert" ) -func TestFilterAnnotations(t *testing.T) { - annotations := map[string]string{ - "one.prefix.com/first-name": "one-first-value", - "one.prefix.com/second-name": "one-second-value", - "one-no-prefix-label": "one-no-prefix-value", - "two-no-prefix-label": "two-no-prefix-value", - "two.prefix.com/first-name": "two-first-value", - "two.prefix.com/second-name": "two-second-value", - } - - // Case 1: no annotations - res := FilterAnnotations(map[string]string{}) - Empty(t, res) - - viper.Set(types.AllowedAnnotationsMap, map[string]bool{"one.prefix.com/first-name": true}) - res = FilterAnnotations(map[string]string{}) - Empty(t, res) - - // Case 2: specific annotations - allowed := map[string]bool{ - "one.prefix.com/first-name": true, - "one-no-prefix-label": true, - "three-no-prefix-label": true, - } - expected := map[string]string{ - "one.prefix.com/first-name": "one-first-value", - "one-no-prefix-label": "one-no-prefix-value", - } - viper.Set(types.AllowedAnnotationsMap, allowed) - res = FilterAnnotations(annotations) - Equal(t, expected, res) - - // Case 3: with prefix wildcards - allowed = map[string]bool{ - "one.prefix.com/*": true, - "one-no-prefix-label": true, - "three-no-prefix-label": true, - } - expected = map[string]string{ - "one.prefix.com/first-name": "one-first-value", - "one.prefix.com/second-name": "one-second-value", - "one-no-prefix-label": "one-no-prefix-value", - } - viper.Set(types.AllowedAnnotationsMap, allowed) - res = FilterAnnotations(annotations) - Equal(t, expected, res) - - // Case 3: with prefix names - allowed = map[string]bool{ - "*/first-name": true, - "one-no-prefix-label": true, - "three-no-prefix-label": true, - } - expected = map[string]string{ - "one.prefix.com/first-name": "one-first-value", - "two.prefix.com/first-name": "two-first-value", - "one-no-prefix-label": "one-no-prefix-value", - } - viper.Set(types.AllowedAnnotationsMap, allowed) - res = FilterAnnotations(annotations) - Equal(t, expected, res) - - // Case 4: all - allowed = map[string]bool{ - "*/*": true, - } - viper.Set(types.AllowedAnnotationsMap, allowed) - res = FilterAnnotations(annotations) - Equal(t, annotations, res) -} - func TestParseAndValidateSettings(t *testing.T) { a := New(t) pref := "/whatever" From ddb51bf5911fb4230f49e7b1a7fb6b9a52d5ca11 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Fri, 17 Sep 2021 11:05:40 +0200 Subject: [PATCH 04/10] Remove constants used by viper Signed-off-by: Elis Lulja --- internal/types/settings.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/internal/types/settings.go b/internal/types/settings.go index 86e76ab..1c4921c 100644 --- a/internal/types/settings.go +++ b/internal/types/settings.go @@ -16,30 +16,6 @@ package types -const ( - // SDDefaultRegion is the key for service directory region setting - SDDefaultRegion = "gcloud.servicedirectory.region" - // SDProject is the key for service directory project setting - SDProject = "gcloud.servicedirectory.project" - // AllowedAnnotations is the key for the allowed annotations setting - AllowedAnnotations = "service.annotations" - // AllowedAnnotationsMap is the key for the allowed annotations map setting - AllowedAnnotationsMap = "service.annotationsmap" - // ServiceRegistrySettingsKey is the key for the service registry settings - ServiceRegistrySettingsKey = "serviceregistry" - // DeprecatedGcloudServiceDirectoryKey is the key for the old service - // directory. It is currently only used to check if it is there and warn - // the user that it is deprecated. - DeprecatedGcloudServiceDirectoryKey = "gcloud.servicedirectory" - // CurrentNamespace identifies the namespace name in which we are running - // in, in case we are running inside the cluster. - CurrentNamespace = "currentnamespace" - // EtcdCredentialsSecretName is the name of the secret holding username - // and password to connect to the etcd cluster. If it exists, the cnwan - // operator expects this name. - EtcdCredentialsSecretName = "cnwan-operator-etcd-credentials" -) - // Settings of the application type Settings struct { MonitorNamespacesByDefault bool `yaml:"monitorNamespacesByDefault"` From cfc402c6340013856722b1c379ed7f21d91df643 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Mon, 20 Sep 2021 11:00:13 +0200 Subject: [PATCH 05/10] Remove deprecated gcloud settings This removes the old gcloud settings and only uses the new one. Signed-off-by: Elis Lulja --- internal/types/settings.go | 19 +--------- internal/utils/utils.go | 17 --------- internal/utils/utils_test.go | 73 ------------------------------------ 3 files changed, 1 insertion(+), 108 deletions(-) diff --git a/internal/types/settings.go b/internal/types/settings.go index 1c4921c..3d855e2 100644 --- a/internal/types/settings.go +++ b/internal/types/settings.go @@ -21,17 +21,7 @@ type Settings struct { MonitorNamespacesByDefault bool `yaml:"monitorNamespacesByDefault"` Service ServiceSettings `yaml:",inline"` *ServiceRegistrySettings `yaml:"serviceRegistry"` - - // DEPRECATED: include this under serviceRegistry instead of here. - // TODO: remove this on v0.6.0 - Gcloud *GcloudSettings `yaml:"gcloud"` - CloudMetadata *CloudMetadata `yaml:"cloudMetadata"` -} - -// GcloudSettings holds gcloud settings -// TODO: remove this on v0.6.0 -type GcloudSettings struct { - ServiceDirectory *DeprecatedServiceDirectorySettings `yaml:"serviceDirectory"` + CloudMetadata *CloudMetadata `yaml:"cloudMetadata"` } // ServiceSettings includes settings about services @@ -46,13 +36,6 @@ type ServiceRegistrySettings struct { *EtcdSettings `yaml:"etcd"` } -// DeprecatedServiceDirectorySettings holds settings about gcloud service directory -// TODO: remove this on v0.6.0 -type DeprecatedServiceDirectorySettings struct { - DefaultRegion string `yaml:"region"` - ProjectName string `yaml:"project"` -} - // ServiceDirectorySettings holds settings about gcloud service directory type ServiceDirectorySettings struct { // DefaultRegion is the default region where objects will be registered to diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 72299e3..b438883 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -68,23 +68,6 @@ func ParseAndValidateSettings(settings *types.Settings) (*types.Settings, error) // Only one service registry can be chosen at this time - // TODO: remove this in v0.6.0 - if settings.Gcloud != nil { - if settings.Gcloud.ServiceDirectory != nil && settings.ServiceDirectorySettings == nil { - // Convert the deprecated service directory settings into the new structure, - // but only if the new one doesn't already exist. - log.V(int(zapcore.WarnLevel)).Info(`DEPRECATED: current service directory settings is under gcloud field. - This is deprecated and will be removed on v0.6.0. - Please place it under service registry as defined in the documentation.`) - - sd := settings.Gcloud.ServiceDirectory - settings.ServiceDirectorySettings = &types.ServiceDirectorySettings{ - DefaultRegion: sd.DefaultRegion, - ProjectID: sd.ProjectName, - } - } - } - if settings.EtcdSettings == nil && settings.ServiceDirectorySettings == nil { // Both are nil return nil, fmt.Errorf("no service registry provided") diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 9abf1d0..9e816a6 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -175,76 +175,9 @@ func TestParseAndValidateSettings(t *testing.T) { }, }, }, - { - id: "convert-deprecated-sd", - arg: &types.Settings{ - Gcloud: &types.GcloudSettings{ - ServiceDirectory: &types.DeprecatedServiceDirectorySettings{ - ProjectName: "test", - DefaultRegion: "ca", - }, - }, - MonitorNamespacesByDefault: true, - Service: types.ServiceSettings{ - Annotations: []string{"one", "two"}, - }, - ServiceRegistrySettings: &types.ServiceRegistrySettings{}, - }, - expRes: &types.Settings{ - MonitorNamespacesByDefault: true, - Service: types.ServiceSettings{ - Annotations: []string{"one", "two"}, - }, - ServiceRegistrySettings: &types.ServiceRegistrySettings{ - ServiceDirectorySettings: &types.ServiceDirectorySettings{ - ProjectID: "test", - DefaultRegion: "ca", - }, - }, - }, - }, - { - id: "do-not-convert-deprecated-sd", - arg: &types.Settings{ - Gcloud: &types.GcloudSettings{ - ServiceDirectory: &types.DeprecatedServiceDirectorySettings{ - ProjectName: "old", - DefaultRegion: "old", - }, - }, - MonitorNamespacesByDefault: true, - Service: types.ServiceSettings{ - Annotations: []string{"one", "two"}, - }, - ServiceRegistrySettings: &types.ServiceRegistrySettings{ - ServiceDirectorySettings: &types.ServiceDirectorySettings{ - ProjectID: "new", - DefaultRegion: "new", - }, - }, - }, - expRes: &types.Settings{ - MonitorNamespacesByDefault: true, - Service: types.ServiceSettings{ - Annotations: []string{"one", "two"}, - }, - ServiceRegistrySettings: &types.ServiceRegistrySettings{ - ServiceDirectorySettings: &types.ServiceDirectorySettings{ - ProjectID: "new", - DefaultRegion: "new", - }, - }, - }, - }, { id: "successful-with-cloud-cfg", arg: &types.Settings{ - Gcloud: &types.GcloudSettings{ - ServiceDirectory: &types.DeprecatedServiceDirectorySettings{ - ProjectName: "old", - DefaultRegion: "old", - }, - }, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, @@ -288,12 +221,6 @@ func TestParseAndValidateSettings(t *testing.T) { { id: "successful-with-empty-cloud-cfg", arg: &types.Settings{ - Gcloud: &types.GcloudSettings{ - ServiceDirectory: &types.DeprecatedServiceDirectorySettings{ - ProjectName: "old", - DefaultRegion: "old", - }, - }, Service: types.ServiceSettings{ Annotations: []string{"one", "two"}, }, From 67e4dab98a360f622419d6867a47a531860d8c66 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Mon, 20 Sep 2021 11:14:56 +0200 Subject: [PATCH 06/10] Create a guide on how to update to v0.6.0 Signed-off-by: Elis Lulja --- docs/update.md | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/docs/update.md b/docs/update.md index a5eddb7..a23d411 100644 --- a/docs/update.md +++ b/docs/update.md @@ -8,32 +8,45 @@ If your version is not included, just follow [Simple update](#simple-update) ## Simple update -Export the version you want to use: +Remove the operator: ```bash -export IMG=cnwan/cnwan-operator:v0.3.0 +./scripts/remove.sh ``` -If you intend to use your own build you will have to modify the value of `IMG` above accordingly. +and follow installation guide again. The operator will try to perform all its work again but will stop it when it realizes that most of it was already performed on previous installation. -Run: +## 0.5.1 and below + +Remove the operator: + +```bash +./scripts/remove.sh +``` + +`monitorNamespacesByDefault` on the settings needs to be set as `true` if your previous value of `namespace.listPolicy` was `blocklist`, otherwise you can just leave it as it is. + +Now, if your previous value of `namespace.listPolicy` was `allowlist` run: ```bash -kubectl set image deployment/cnwan-operator-controller-manager -n cnwan-operator-system manager=$IMG --record +for ns in $(kubectl get ns -l "operator.cnwan.io/allowed" -o jsonpath="{.items[*].metadata.name}") +do +kubectl label ns $ns operator.cnwan.io/monitor=true +kubectl label ns $ns operator.cnwan.io/allowed- +done ``` -and you should see +Or, if it was `blocklist`: ```bash -deployment.apps/cnwan-operator-controller-manager image updated +for ns in $(kubectl get ns -l "operator.cnwan.io/blocked" -o jsonpath="{.items[*].metadata.name}") +do +kubectl label ns $ns operator.cnwan.io/monitor=false +kubectl label ns $ns operator.cnwan.io/blocked- +done ``` - +Now you can ## 0.2.1 and below From afd1f3609dee95c5f4d6d50adf40ad1ec2466669 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Tue, 21 Sep 2021 10:52:29 +0200 Subject: [PATCH 07/10] Create caching in broker Signed-off-by: Elis Lulja --- go.mod | 1 + go.sum | 2 ++ pkg/servregistry/broker.go | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/go.mod b/go.mod index acee6a4..f7060f2 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( github.com/nxadm/tail v1.4.4 // indirect github.com/onsi/ginkgo v1.14.2 github.com/onsi/gomega v1.10.3 + github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.11.0 // indirect diff --git a/go.sum b/go.sum index 510bb40..82411fd 100644 --- a/go.sum +++ b/go.sum @@ -382,6 +382,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= diff --git a/pkg/servregistry/broker.go b/pkg/servregistry/broker.go index ecccf01..d06fa42 100644 --- a/pkg/servregistry/broker.go +++ b/pkg/servregistry/broker.go @@ -18,8 +18,10 @@ package servregistry import ( "sync" + "time" "github.com/go-logr/logr" + cache "github.com/patrickmn/go-cache" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -40,6 +42,7 @@ type Broker struct { Reg ServiceRegistry log logr.Logger + cache *cache.Cache opMetaPair MetadataPair persistentMeta []MetadataPair lock sync.Mutex @@ -78,5 +81,6 @@ func NewBroker(reg ServiceRegistry, opMetaPair MetadataPair, persMeta ...Metadat Reg: reg, opMetaPair: opMetaPair, persistentMeta: persMeta, + cache: cache.New(5*time.Minute, 10*time.Minute), }, nil } From 207679061f6d92769dc157d1bde1adbce21567a8 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Tue, 21 Sep 2021 14:03:59 +0200 Subject: [PATCH 08/10] implement caching on namespace operations Signed-off-by: Elis Lulja --- pkg/servregistry/broker_test.go | 7 +++ pkg/servregistry/namespace.go | 97 ++++++++++++++++++++---------- pkg/servregistry/namespace_test.go | 97 +++++++++++++++++++++++++++++- 3 files changed, 168 insertions(+), 33 deletions(-) diff --git a/pkg/servregistry/broker_test.go b/pkg/servregistry/broker_test.go index 4fb2d42..49f8d4d 100644 --- a/pkg/servregistry/broker_test.go +++ b/pkg/servregistry/broker_test.go @@ -40,6 +40,8 @@ type fakeServReg struct { createdEndp []string updatedEndp []string deletedEndp []string + + getNs string } func newFakeInt() ServiceRegistry { @@ -47,6 +49,7 @@ func newFakeInt() ServiceRegistry { nsList: map[string]*Namespace{}, servList: map[string]*Service{}, endpList: map[string]*Endpoint{}, + getNs: "", createdNs: []string{}, updatedNs: []string{}, deletedNs: []string{}, @@ -64,6 +67,7 @@ func newFakeStruct() *fakeServReg { nsList: map[string]*Namespace{}, servList: map[string]*Service{}, endpList: map[string]*Endpoint{}, + getNs: "", createdNs: []string{}, updatedNs: []string{}, deletedNs: []string{}, @@ -77,6 +81,9 @@ func newFakeStruct() *fakeServReg { } func (f *fakeServReg) GetNs(name string) (*Namespace, error) { + defer func() { + f.getNs = name + }() if name == "get-error" { return nil, errors.New("error") } diff --git a/pkg/servregistry/namespace.go b/pkg/servregistry/namespace.go index 5a9514e..f433172 100644 --- a/pkg/servregistry/namespace.go +++ b/pkg/servregistry/namespace.go @@ -16,6 +16,12 @@ package servregistry +import ( + "path" + + "github.com/patrickmn/go-cache" +) + // This file contains functions that perform operations on namespaces, // such as create/update/delete. // These functions belong to a ServiceRegistryBroker, defined in @@ -42,6 +48,7 @@ func (b *Broker) ManageNs(nsData *Namespace) (regNs *Namespace, err error) { if len(nsData.Name) == 0 { return nil, ErrNsNameNotProvided } + cacheKey := path.Join("namespaces", nsData.Name) // -- Init b.lock.Lock() @@ -54,25 +61,30 @@ func (b *Broker) ManageNs(nsData *Namespace) (regNs *Namespace, err error) { // -- Do stuff l.V(1).Info("going to load namespace from service registry") + if val, found := b.cache.Get(cacheKey); found { + regNs = val.(*Namespace) + l.Info("retrieved from cache") + } else { + regNs, err = b.Reg.GetNs(nsData.Name) + if err != nil { + if err != ErrNotFound { + l.Error(err, "error occurred while getting namespace from service registry") + return + } - regNs, err = b.Reg.GetNs(nsData.Name) - if err != nil { - if err != ErrNotFound { - l.Error(err, "error occurred while getting namespace from service registry") - return - } + // If you're here, it means that the namespace does not exist. + // Let's create it. + l.V(1).Info("namespace does not exist in service registry, going to create it") + regNs, err = b.Reg.CreateNs(nsData) + if err != nil { + l.Error(err, "error occurred while creating namespace in service registry") + return + } - // If you're here, it means that the namespace does not exist. - // Let's create it. - l.V(1).Info("namespace does not exist in service registry, going to create it") - regNs, err = b.Reg.CreateNs(nsData) - if err != nil { - l.Error(err, "error occurred while creating namespace in service registry") - return + l.V(0).Info("namespace created correctly") + regNs = nsData } - - l.V(0).Info("namespace created correctly") - regNs = nsData + b.cache.Add(cacheKey, regNs, cache.DefaultExpiration) } if by, exists := regNs.Metadata[b.opMetaPair.Key]; by != b.opMetaPair.Value || !exists { @@ -84,11 +96,15 @@ func (b *Broker) ManageNs(nsData *Namespace) (regNs *Namespace, err error) { if !b.deepEqualMetadata(nsData.Metadata, regNs.Metadata) { l.V(1).Info("namespace metadata need to be updated") + b.cache.Delete(cacheKey) + regNs, err = b.Reg.UpdateNs(nsData) if err != nil { l.Error(err, "error while trying to update namespace in service registry") return nil, err } + + b.cache.Add(cacheKey, regNs, cache.DefaultExpiration) } return @@ -113,6 +129,7 @@ func (b *Broker) RemoveNs(nsName string, forceNotEmpty bool) (err error) { if len(nsName) == 0 { return ErrNsNameNotProvided } + cacheKey := path.Join("namespaces", nsName) // -- Init b.lock.Lock() @@ -121,26 +138,42 @@ func (b *Broker) RemoveNs(nsName string, forceNotEmpty bool) (err error) { // -- Do stuff l.V(1).Info("going to remove namespace from service registry") + var regNs *Namespace + + if val, found := b.cache.Get(cacheKey); found { + l.Info("retrieved from cache") + regNs = val.(*Namespace) + } else { + // Load the namespace first + regNs, err = b.Reg.GetNs(nsName) + if err != nil { + if err != ErrNotFound { + l.Error(err, "error occurred while removing namespace from service registry") + return + } - // Load the namespace first - regNs, err := b.Reg.GetNs(nsName) - if err != nil { - if err != ErrNotFound { - l.Error(err, "error occurred while removing namespace from service registry") - return + // If you're here, it means that the namespace does not exist. + // This doesn't change anything for us. + l.V(0).Info("namespace does not exist in service registry, going to stop here") + return nil } - - // If you're here, it means that the namespace does not exist. - // This doesn't change anything for us. - l.V(0).Info("namespace does not exist in service registry, going to stop here") - return nil + b.cache.Add(cacheKey, regNs, cache.DefaultExpiration) } // Is it empty? + var listServ []*Service l.V(1).Info("checking if namespace is empty before deleting") - listServ, err := b.Reg.ListServ(nsName) - if err != nil { - return + if val, found := b.cache.Get(path.Join(cacheKey, "services")); found { + l.Info("retreived services list from cache") + listServ = val.([]*Service) + defer b.cache.Delete(path.Join(cacheKey, "services")) + } else { + // We're going to try and delete these services, so there is no point + // in putting them in the cache. + listServ, err = b.Reg.ListServ(nsName) + if err != nil { + return + } } if len(listServ) > 0 && !forceNotEmpty { @@ -181,11 +214,13 @@ func (b *Broker) RemoveNs(nsName string, forceNotEmpty bool) (err error) { return ErrNsNotOwnedByOp } + defer b.cache.Delete(cacheKey) err = b.Reg.DeleteNs(nsName) if err != nil { l.Error(err, "error while deleting namespace from service registry") + } else { + l.V(0).Info("namespace deleted from service registry successfully") } - l.V(0).Info("namespace deleted from service registry successfully") return } diff --git a/pkg/servregistry/namespace_test.go b/pkg/servregistry/namespace_test.go index 933d096..7f379e0 100644 --- a/pkg/servregistry/namespace_test.go +++ b/pkg/servregistry/namespace_test.go @@ -17,8 +17,10 @@ package servregistry import ( + "path" "testing" + "github.com/patrickmn/go-cache" a "github.com/stretchr/testify/assert" ) @@ -82,7 +84,10 @@ func TestManageNs(t *testing.T) { // Test namespaces not owned by the operator are not modified testNotOwned := func(tt *testing.T) { - defer resetFake() + defer func() { + resetFake() + b.cache.Flush() + }() assert := a.New(tt) one := &Namespace{Name: "one", Metadata: map[string]string{b.opMetaPair.Key: "someone-else", "key": "val"}} @@ -97,17 +102,35 @@ func TestManageNs(t *testing.T) { assert.Equal(one, regNs) assert.NoError(err) + // It is now in cache + if val, found := b.cache.Get(path.Join("namespaces", "one")); !found { + assert.Fail("namespace is not in cache") + } else { + v := val.(*Namespace) + assert.Equal(one, v) + } + regNs, err = b.ManageNs(twoChange) assert.Equal(two, regNs) assert.NoError(err) + if val, found := b.cache.Get(path.Join("namespaces", "two")); !found { + assert.Fail("namespace is not in cache") + } else { + v := val.(*Namespace) + assert.Equal(two, v) + } + assert.Empty(f.createdNs) assert.Empty(f.updatedNs) } // Test namespaces owned by the operator are modified testOwned := func(tt *testing.T) { - defer resetFake() + defer func() { + resetFake() + b.cache.Flush() + }() assert := a.New(tt) // should return nil because an error in updating @@ -119,6 +142,11 @@ func TestManageNs(t *testing.T) { assert.Nil(regNs) assert.Error(err) + // Should not be in cache + if _, found := b.cache.Get(path.Join("namespaces", "update-error")); found { + assert.Fail("namespace is in cache but should not be") + } + // no error so it should return the new value shouldOk := &Namespace{Name: "update", Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}} changeOk := &Namespace{Name: "update", Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val-1"}} @@ -129,6 +157,21 @@ func TestManageNs(t *testing.T) { assert.NoError(err) assert.Empty(f.createdNs) + + // Should be in cache with new value + if val, found := b.cache.Get(path.Join("namespaces", "update")); !found { + assert.Fail("namespace is not in cache") + } else { + v := val.(*Namespace) + assert.Equal(changeOk, v) + } + + // Assert it was pulled from cache, not from service registry + f.getNs = "" + regNs, err = b.ManageNs(changeOk) + assert.Equal(changeOk, regNs) + assert.NoError(err) + assert.Empty(f.getNs) } // Test namespaces are created if they do not exist @@ -143,6 +186,11 @@ func TestManageNs(t *testing.T) { assert.Nil(regNs) assert.Error(err) + // Should not be in cache + if _, found := b.cache.Get(path.Join("namespaces", "update")); found { + assert.Fail("namespace is in cache but should not be") + } + // no error so it should return the created create = &Namespace{Name: "create", Metadata: map[string]string{"key": "val"}} regNs, err = b.ManageNs(create) @@ -151,6 +199,21 @@ func TestManageNs(t *testing.T) { assert.NoError(err) assert.Empty(f.updatedNs) + + // it is now in cache + if val, found := b.cache.Get(path.Join("namespaces", "create")); !found { + assert.Fail("namespace is not in cache") + } else { + v := val.(*Namespace) + assert.Equal(create, v) + } + + // Assert it was retrieved from cache, not from service registry + f.updatedNs = []string{} + regNs, err = b.ManageNs(create) + assert.Equal(create, regNs) + assert.NoError(err) + assert.Empty(f.updatedNs) } testValidation(t) @@ -220,6 +283,11 @@ func TestRemoveNs(t *testing.T) { err = b.RemoveNs(two.Name, false) assert.Equal(ErrNsNotOwnedByOp, err) assert.Empty(f.deletedNs) + + // this was not deleted, so it is still in cache + if _, found := b.cache.Get(path.Join("namespaces", two.Name)); !found { + assert.Fail("namespace was not found in cache but should still be there") + } } // Test empty owned namespaces are deleted @@ -301,9 +369,34 @@ func TestRemoveNs(t *testing.T) { assert.Error(err) } + testFlushCache := func(tt *testing.T) { + defer resetFake() + assert := a.New(tt) + oneOwned := &Service{ + Name: "one", + Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}, + NsName: nsName, + } + nsDel := &Namespace{Name: nsName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}} + b.cache.Add(path.Join("namespaces", nsName), nsDel, cache.DefaultExpiration) + b.cache.Add(path.Join("namespaces", nsName, "services"), []*Service{oneOwned}, cache.DefaultExpiration) + + f.nsList[nsDel.Name] = nsDel + f.servList[oneOwned.Name] = oneOwned + + _ = b.RemoveNs(nsDel.Name, true) + if _, found := b.cache.Get(path.Join("namespaces", nsName, "services")); found { + assert.Fail("services list was found on cache but should not be there") + } + if _, found := b.cache.Get(path.Join("namespaces", nsName)); found { + assert.Fail("namespace was found on cache but should not be there") + } + } + testValidation(t) testUnErr(t) testNotOwned(t) testEmptyOwned(t) testNotEmptyOwned(t) + testFlushCache(t) } From 3b61c117131c0b1ece43ab715e039c07023b65d5 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Tue, 21 Sep 2021 14:38:25 +0200 Subject: [PATCH 09/10] Implement caching on services operations Signed-off-by: Elis Lulja --- pkg/servregistry/broker_test.go | 5 +- pkg/servregistry/service.go | 94 ++++++++++++++++++++++---------- pkg/servregistry/service_test.go | 56 +++++++++++++++++++ 3 files changed, 124 insertions(+), 31 deletions(-) diff --git a/pkg/servregistry/broker_test.go b/pkg/servregistry/broker_test.go index 49f8d4d..f7fb3fd 100644 --- a/pkg/servregistry/broker_test.go +++ b/pkg/servregistry/broker_test.go @@ -41,7 +41,8 @@ type fakeServReg struct { updatedEndp []string deletedEndp []string - getNs string + getNs string + getServ string } func newFakeInt() ServiceRegistry { @@ -50,6 +51,7 @@ func newFakeInt() ServiceRegistry { servList: map[string]*Service{}, endpList: map[string]*Endpoint{}, getNs: "", + getServ: "", createdNs: []string{}, updatedNs: []string{}, deletedNs: []string{}, @@ -68,6 +70,7 @@ func newFakeStruct() *fakeServReg { servList: map[string]*Service{}, endpList: map[string]*Endpoint{}, getNs: "", + getServ: "", createdNs: []string{}, updatedNs: []string{}, deletedNs: []string{}, diff --git a/pkg/servregistry/service.go b/pkg/servregistry/service.go index ba94a5f..3624287 100644 --- a/pkg/servregistry/service.go +++ b/pkg/servregistry/service.go @@ -16,6 +16,12 @@ package servregistry +import ( + "path" + + "github.com/patrickmn/go-cache" +) + // This file contains functions that perform operations on services, // such as create/update/delete. // These functions belong to a ServiceRegistryBroker, defined in @@ -51,6 +57,7 @@ func (b *Broker) ManageServ(servData *Service) (regServ *Service, err error) { if len(servData.NsName) == 0 { return nil, ErrNsNameNotProvided } + cacheKey := path.Join("namespaces", servData.NsName, "services", servData.Name) // -- Init b.lock.Lock() @@ -68,24 +75,30 @@ func (b *Broker) ManageServ(servData *Service) (regServ *Service, err error) { // -- Do stuff l.V(1).Info("going to load service from service registry") - regServ, err = b.Reg.GetServ(servData.NsName, servData.Name) - if err != nil { - if err != ErrNotFound { - l.Error(err, "error occurred while getting service from service registry") - return - } - - // If you're here, it means that the service does not exist. - // Let's create it. - l.V(1).Info("service does not exist in service registry, going to create it") - regServ, err = b.Reg.CreateServ(servData) + if val, found := b.cache.Get(cacheKey); found { + l.Info("retrieved from cache") + regServ = val.(*Service) + } else { + regServ, err = b.Reg.GetServ(servData.NsName, servData.Name) if err != nil { - l.Error(err, "error occurred while creating service in service registry") - return - } + if err != ErrNotFound { + l.Error(err, "error occurred while getting service from service registry") + return + } - l.V(0).Info("service created correctly") - regServ = servData + // If you're here, it means that the service does not exist. + // Let's create it. + l.V(1).Info("service does not exist in service registry, going to create it") + regServ, err = b.Reg.CreateServ(servData) + if err != nil { + l.Error(err, "error occurred while creating service in service registry") + return + } + + l.V(0).Info("service created correctly") + regServ = servData + } + b.cache.Add(cacheKey, regServ, cache.DefaultExpiration) } if by, exists := regServ.Metadata[b.opMetaPair.Key]; by != b.opMetaPair.Value || !exists { @@ -96,12 +109,15 @@ func (b *Broker) ManageServ(servData *Service) (regServ *Service, err error) { } if !b.deepEqualMetadata(servData.Metadata, regServ.Metadata) { + b.cache.Delete(cacheKey) + l.V(1).Info("service metadata need to be updated") regServ, err = b.Reg.UpdateServ(servData) if err != nil { l.Error(err, "error while trying to update service in service registry") return nil, err } + b.cache.Add(cacheKey, regServ, cache.DefaultExpiration) } return @@ -128,6 +144,7 @@ func (b *Broker) RemoveServ(nsName, servName string, forceNotEmpty bool) (err er if len(servName) == 0 { return ErrServNameNotProvided } + cacheKey := path.Join("namespaces", nsName, "services", servName) // -- Init b.lock.Lock() @@ -136,26 +153,42 @@ func (b *Broker) RemoveServ(nsName, servName string, forceNotEmpty bool) (err er // -- Do stuff l.V(1).Info("going to remove service from service registry") + var regServ *Service + + if val, found := b.cache.Get(cacheKey); found { + l.Info("retrieved from cache") + regServ = val.(*Service) + } else { + // Load the service first + regServ, err = b.Reg.GetServ(nsName, servName) + if err != nil { + if err != ErrNotFound { + l.Error(err, "error occurred while removing service from service registry") + return + } - // Load the service first - regServ, err := b.Reg.GetServ(nsName, servName) - if err != nil { - if err != ErrNotFound { - l.Error(err, "error occurred while removing service from service registry") - return + // If you're here, it means that the servce does not exist. + // This doesn't change anything for us. + l.V(0).Info("servce does not exist in service registry, going to stop here") + return nil } - - // If you're here, it means that the servce does not exist. - // This doesn't change anything for us. - l.V(0).Info("servce does not exist in service registry, going to stop here") - return nil + // Add it on cache, in case this should not be deleted (e.g. it is + // owned by someone else) + b.cache.Add(cacheKey, regServ, cache.DefaultExpiration) } // Is it empty? + var listEndp []*Endpoint l.V(1).Info("checking if service is empty before deleting") - listEndp, err := b.Reg.ListEndp(nsName, servName) - if err != nil { - return + if val, found := b.cache.Get(path.Join(cacheKey, "endpoints")); found { + l.Info("retrieved endpoints list from cache") + listEndp = val.([]*Endpoint) + defer b.cache.Delete(path.Join(cacheKey, "endpoints")) + } else { + listEndp, err = b.Reg.ListEndp(nsName, servName) + if err != nil { + return + } } if len(listEndp) > 0 && !forceNotEmpty { @@ -195,6 +228,7 @@ func (b *Broker) RemoveServ(nsName, servName string, forceNotEmpty bool) (err er return ErrServNotOwnedByOp } + defer b.cache.Delete(cacheKey) err = b.Reg.DeleteServ(nsName, servName) if err != nil { l.Error(err, "error while deleting service from service registry") diff --git a/pkg/servregistry/service_test.go b/pkg/servregistry/service_test.go index 66cb31c..d3eef22 100644 --- a/pkg/servregistry/service_test.go +++ b/pkg/servregistry/service_test.go @@ -17,8 +17,10 @@ package servregistry import ( + "path" "testing" + "github.com/patrickmn/go-cache" a "github.com/stretchr/testify/assert" ) @@ -104,12 +106,33 @@ func TestManageServ(t *testing.T) { assert.Equal(one, regServ) assert.NoError(err) + // Exists on cache? + if val, found := b.cache.Get(path.Join("namespaces", oneChange.NsName, "services", oneChange.Name)); !found { + assert.Fail("service was not found on cache") + } else { + v := val.(*Service) + assert.Equal(regServ, v) + } + regServ, err = b.ManageServ(twoChange) assert.Equal(two, regServ) assert.NoError(err) assert.Empty(f.createdServ) assert.Empty(f.updatedServ) + + // Exists on cache but as it was before? + if val, found := b.cache.Get(path.Join("namespaces", two.NsName, "services", two.Name)); !found { + assert.Fail("service was not found on cache") + } else { + v := val.(*Service) + assert.Equal(two, v) + } + + // Pulled from cache, not from service registry + f.getServ = "" + b.ManageServ(twoChange) + assert.Empty(f.getServ) } // Test services owned by the operator are modified @@ -235,6 +258,10 @@ func TestRemoveServ(t *testing.T) { err = b.RemoveServ(two.NsName, two.Name, false) assert.Equal(ErrServNotOwnedByOp, err) assert.Empty(f.deletedServ) + + if _, found := b.cache.Get(path.Join("namespaces", one.NsName, "services", one.Name)); !found { + assert.Fail("service was not found on cache, but should be there") + } } // Test empty owned services are deleted @@ -328,9 +355,38 @@ func TestRemoveServ(t *testing.T) { assert.Error(err) } + testFlushCache := func(tt *testing.T) { + defer resetFake() + assert := a.New(tt) + + oneOwned := &Endpoint{ + Name: "one", + ServName: servName, + NsName: nsName, + Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}, + } + servDel := &Service{Name: servName, NsName: nsName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}} + f.servList[servDel.Name] = servDel + f.endpList["one"] = oneOwned + + cacheKey := path.Join("namespaces", servDel.NsName, "services", servDel.Name) + b.cache.Add(cacheKey, servDel, cache.DefaultExpiration) + b.cache.Add(path.Join(cacheKey, "endpoints"), []*Endpoint{oneOwned}, cache.DefaultExpiration) + b.RemoveServ(servDel.NsName, servDel.Name, true) + + if _, found := b.cache.Get(cacheKey); found { + assert.Fail("service was found on cache, but shouldn't be there") + } + + if _, found := b.cache.Get(path.Join(cacheKey, "endpoints")); found { + assert.Fail("endpoints list was found on cache, but shouldn't be there") + } + } + testValidation(t) testUnErr(t) testNotOwned(t) testEmptyOwned(t) testNotEmptyOwned(t) + testFlushCache(t) } From bffde139ed098f212132ffba27903206e0aa6da4 Mon Sep 17 00:00:00 2001 From: Elis Lulja Date: Tue, 21 Sep 2021 15:10:50 +0200 Subject: [PATCH 10/10] Implement caching on endpoints operations Signed-off-by: Elis Lulja --- pkg/servregistry/broker_test.go | 5 +++-- pkg/servregistry/endpoint.go | 27 ++++++++++++++++++++++++--- pkg/servregistry/endpoint_test.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/pkg/servregistry/broker_test.go b/pkg/servregistry/broker_test.go index f7fb3fd..d49bf36 100644 --- a/pkg/servregistry/broker_test.go +++ b/pkg/servregistry/broker_test.go @@ -41,8 +41,9 @@ type fakeServReg struct { updatedEndp []string deletedEndp []string - getNs string - getServ string + getNs string + getServ string + listEndp string } func newFakeInt() ServiceRegistry { diff --git a/pkg/servregistry/endpoint.go b/pkg/servregistry/endpoint.go index 633b8a7..7b961cd 100644 --- a/pkg/servregistry/endpoint.go +++ b/pkg/servregistry/endpoint.go @@ -16,6 +16,12 @@ package servregistry +import ( + "path" + + "github.com/patrickmn/go-cache" +) + // This file contains functions that perform operations on endpoints, // such as create/update/delete. // These functions belong to a ServiceRegistryBroker, defined in @@ -74,12 +80,24 @@ func (b *Broker) ManageServEndps(nsName, servName string, endpsData []*Endpoint) endpErrs = map[string]error{} // Check what changed + cacheKey := path.Join("namespaces", nsName, "services", servName, "endpoints") var listRegEndps []*Endpoint - listRegEndps, err = b.Reg.ListEndp(nsName, servName) - if err != nil { - return + if val, found := b.cache.Get(cacheKey); found { + l.Info("retrieved endpoints list from cache") + listRegEndps = val.([]*Endpoint) + } else { + listRegEndps, err = b.Reg.ListEndp(nsName, servName) + if err != nil { + return + } + b.cache.Add(cacheKey, listRegEndps, cache.DefaultExpiration) } + newCacheList := []*Endpoint{} + defer func() { + b.cache.Delete(cacheKey) + b.cache.Add(cacheKey, newCacheList, cache.DefaultExpiration) + }() for _, regEndp := range listRegEndps { // endpData: the endpoint as it is in Kubernetes // regEndp: the endpoint as it is registered in the service registry @@ -92,6 +110,7 @@ func (b *Broker) ManageServEndps(nsName, servName string, endpsData []*Endpoint) l.V(0).Info("endpoint is not managed by the cnwan operator and is going to be ignored") endpErrs[regEndp.Name] = ErrEndpNotOwnedByOp delete(endpsMap, regEndp.Name) + newCacheList = append(newCacheList, regEndp) continue } @@ -124,6 +143,7 @@ func (b *Broker) ManageServEndps(nsName, servName string, endpsData []*Endpoint) } else { l.V(0).Info("endpoint updated in service registry") + newCacheList = append(newCacheList, endpData) } } @@ -143,6 +163,7 @@ func (b *Broker) ManageServEndps(nsName, servName string, endpsData []*Endpoint) } l.V(0).Info("endpoint created in service registry") + newCacheList = append(newCacheList, endpData) } return diff --git a/pkg/servregistry/endpoint_test.go b/pkg/servregistry/endpoint_test.go index 9033907..2050313 100644 --- a/pkg/servregistry/endpoint_test.go +++ b/pkg/servregistry/endpoint_test.go @@ -17,8 +17,10 @@ package servregistry import ( + "path" "testing" + "github.com/patrickmn/go-cache" a "github.com/stretchr/testify/assert" ) @@ -31,6 +33,7 @@ func TestManageServEndps(t *testing.T) { resetFake := func() { f = newFakeStruct() b.Reg = f + b.cache.Flush() } resetFake() @@ -208,9 +211,37 @@ func TestManageServEndps(t *testing.T) { assert.Equal(f.deletedEndp[0], del.Name) } + // Test cache + testCache := func(tt *testing.T) { + defer resetFake() + assert := a.New(tt) + cacheKey := path.Join("namespaces", nsName, "services", servName, "endpoints") + + toDelete := &Endpoint{Name: "to-delete", NsName: nsName, ServName: servName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "to": "delete"}} + toUpdate := &Endpoint{Name: "to-update", NsName: nsName, ServName: servName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "to": "update-before"}} + notOwned := &Endpoint{Name: "not-owned", NsName: nsName, ServName: servName, Metadata: map[string]string{"not": "owned"}} + f.endpList[toDelete.Name] = toDelete + f.endpList[toUpdate.Name] = toUpdate + f.endpList[notOwned.Name] = notOwned + + b.cache.Add(cacheKey, []*Endpoint{toDelete, toUpdate, notOwned}, cache.DefaultExpiration) + + toCreate := &Endpoint{Name: "to-create", NsName: nsName, ServName: servName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}} + toUpdateAfter := &Endpoint{Name: "to-update", NsName: nsName, ServName: servName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "to": "update-after"}} + errored := &Endpoint{Name: "create-error", NsName: nsName, ServName: servName, Metadata: map[string]string{b.opMetaPair.Key: b.opMetaPair.Value, "key": "val"}} + + b.ManageServEndps(nsName, servName, []*Endpoint{toCreate, toUpdateAfter, errored}) + data, found := b.cache.Get(cacheKey) + if !found { + assert.Fail("endpoints list is not in cache but should be!") + } + assert.ElementsMatch([]*Endpoint{notOwned, toUpdateAfter, toCreate}, data) + } + testValidation(t) testNotOwned(t) testOwnedDelete(t) testOwnedUpd(t) testOwnedCreate(t) + testCache(t) }