From 2916c7c20ebd2045b659c45d856addae807d255e Mon Sep 17 00:00:00 2001 From: Marco Bebway Date: Fri, 24 Nov 2023 14:03:53 +0100 Subject: [PATCH 1/2] Use common labels (#264) --- Dockerfile | 1 + config/default/kustomization.yaml | 14 +- .../ui-extensions/eventing/kustomization.yaml | 1 + .../subscriptions/subscriptions.yaml | 1 + .../eventing/controller.go | 1 - .../eventing/eventmesh.go | 3 +- .../eventing/eventmesh_test.go | 13 +- internal/label/label.go | 16 +++ pkg/eventing/deployment.go | 49 ++++--- pkg/eventing/deployment_test.go | 129 +++++++++++++++++- pkg/eventing/manager.go | 6 +- pkg/eventing/utils.go | 4 +- pkg/eventing/utils_test.go | 47 ++++++- pkg/object/equality_test.go | 74 ++++++++++ 14 files changed, 320 insertions(+), 39 deletions(-) create mode 100644 internal/label/label.go diff --git a/Dockerfile b/Dockerfile index dd11fe283..61c8d74b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ RUN go mod download COPY cmd/main.go cmd/main.go COPY api/ api/ COPY internal/controller/ internal/controller/ +COPY internal/label/ internal/label/ COPY pkg/ pkg/ COPY testing/ testing/ COPY options/ options/ diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 67c5a2544..01a91ee94 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -9,10 +9,16 @@ namespace: kyma-system #namePrefix: eventing- # Labels to add to all resources and selectors. -#labels: -#- includeSelectors: true -# pairs: -# someName: someValue +labels: + - includeSelectors: false + pairs: + app.kubernetes.io/component: eventing-manager + app.kubernetes.io/created-by: eventing-manager + app.kubernetes.io/instance: eventing-manager + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/name: eventing-manager + app.kubernetes.io/part-of: Kyma + control-plane: eventing-manager resources: - ../crd diff --git a/config/ui-extensions/eventing/kustomization.yaml b/config/ui-extensions/eventing/kustomization.yaml index a5f043f89..9175e1a19 100644 --- a/config/ui-extensions/eventing/kustomization.yaml +++ b/config/ui-extensions/eventing/kustomization.yaml @@ -9,6 +9,7 @@ configMapGenerator: options: disableNameSuffixHash: true labels: + app.kubernetes.io/created-by: eventing-manager app.kubernetes.io/name: eventings.operator.kyma-project.io busola.io/extension: resource busola.io/extension-version: "0.5" diff --git a/config/ui-extensions/subscriptions/subscriptions.yaml b/config/ui-extensions/subscriptions/subscriptions.yaml index f0bb09d58..2ac13b629 100644 --- a/config/ui-extensions/subscriptions/subscriptions.yaml +++ b/config/ui-extensions/subscriptions/subscriptions.yaml @@ -4,6 +4,7 @@ metadata: name: subscriptions namespace: kube-public labels: + app.kubernetes.io/created-by: eventing-manager app.kubernetes.io/name: subscriptions busola.io/extension: resource busola.io/extension-version: '0.5' diff --git a/internal/controller/operator.kyma-project.io/eventing/controller.go b/internal/controller/operator.kyma-project.io/eventing/controller.go index eb5b676d3..96fc645e1 100644 --- a/internal/controller/operator.kyma-project.io/eventing/controller.go +++ b/internal/controller/operator.kyma-project.io/eventing/controller.go @@ -61,7 +61,6 @@ const ( NatsServerNotAvailableMsg = "NATS server is not available" natsClientPort = 4222 - AppLabelValue = eventing.PublisherName PublisherSecretEMSHostKey = "ems-publish-host" TokenEndpointFormat = "%s?grant_type=%s&response_type=token" diff --git a/internal/controller/operator.kyma-project.io/eventing/eventmesh.go b/internal/controller/operator.kyma-project.io/eventing/eventmesh.go index 8c6bbbd16..a6770875c 100644 --- a/internal/controller/operator.kyma-project.io/eventing/eventmesh.go +++ b/internal/controller/operator.kyma-project.io/eventing/eventmesh.go @@ -15,6 +15,7 @@ import ( "k8s.io/apimachinery/pkg/types" "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" + "github.com/kyma-project/eventing-manager/internal/label" "github.com/kyma-project/eventing-manager/pkg/env" "github.com/kyma-project/eventing-manager/pkg/eventing" subscriptionmanager "github.com/kyma-project/eventing-manager/pkg/subscriptionmanager/manager" @@ -297,7 +298,7 @@ func getSecretForPublisher(eventMeshSecret *corev1.Secret) (*corev1.Secret, erro secret := newSecret(eventing.PublisherName, eventMeshSecret.Namespace) secret.Labels = map[string]string{ - eventing.AppLabelKey: AppLabelValue, + label.KeyName: label.ValueEventingPublisherProxy, } if _, ok := eventMeshSecret.Data["messaging"]; !ok { diff --git a/internal/controller/operator.kyma-project.io/eventing/eventmesh_test.go b/internal/controller/operator.kyma-project.io/eventing/eventmesh_test.go index 9aa3f9161..28ed9cdf4 100644 --- a/internal/controller/operator.kyma-project.io/eventing/eventmesh_test.go +++ b/internal/controller/operator.kyma-project.io/eventing/eventmesh_test.go @@ -5,12 +5,6 @@ import ( "errors" "testing" - "github.com/kyma-project/eventing-manager/pkg/eventing" - - "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" - "github.com/kyma-project/eventing-manager/pkg/k8s" - k8smocks "github.com/kyma-project/eventing-manager/pkg/k8s/mocks" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -19,8 +13,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" + "github.com/kyma-project/eventing-manager/internal/label" "github.com/kyma-project/eventing-manager/pkg/env" + "github.com/kyma-project/eventing-manager/pkg/eventing" managermocks "github.com/kyma-project/eventing-manager/pkg/eventing/mocks" + "github.com/kyma-project/eventing-manager/pkg/k8s" + k8smocks "github.com/kyma-project/eventing-manager/pkg/k8s/mocks" "github.com/kyma-project/eventing-manager/pkg/logger" submanagermocks "github.com/kyma-project/eventing-manager/pkg/subscriptionmanager/manager/mocks" subscriptionmanagermocks "github.com/kyma-project/eventing-manager/pkg/subscriptionmanager/mocks" @@ -628,7 +627,7 @@ func Test_GetSecretForPublisher(t *testing.T) { Name: eventing.PublisherName, Namespace: "test-namespace", Labels: map[string]string{ - eventing.AppLabelKey: eventing.PublisherName, + label.KeyName: label.ValueEventingPublisherProxy, }, }, StringData: map[string]string{ diff --git a/internal/label/label.go b/internal/label/label.go new file mode 100644 index 000000000..f7a759e19 --- /dev/null +++ b/internal/label/label.go @@ -0,0 +1,16 @@ +package label + +const ( + KeyComponent = "app.kubernetes.io/component" + KeyCreatedBy = "app.kubernetes.io/created-by" + KeyInstance = "app.kubernetes.io/instance" + KeyManagedBy = "app.kubernetes.io/managed-by" + KeyName = "app.kubernetes.io/name" + KeyPartOf = "app.kubernetes.io/part-of" + KeyBackend = "eventing.kyma-project.io/backend" + KeyDashboard = "kyma-project.io/dashboard" + + ValueEventingPublisherProxy = "eventing-publisher-proxy" + ValueEventingManager = "eventing-manager" + ValueEventing = "eventing" +) diff --git a/pkg/eventing/deployment.go b/pkg/eventing/deployment.go index d3a183162..02cb425e2 100644 --- a/pkg/eventing/deployment.go +++ b/pkg/eventing/deployment.go @@ -12,6 +12,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" + "github.com/kyma-project/eventing-manager/internal/label" "github.com/kyma-project/eventing-manager/pkg/env" "github.com/kyma-project/eventing-manager/pkg/utils" ) @@ -21,18 +22,12 @@ const ( livenessTimeoutSecs = int32(1) livenessPeriodSecs = int32(2) eventMeshNamespacePrefix = "/" - InstanceLabelKey = "app.kubernetes.io/instance" - InstanceLabelValue = "eventing" - DashboardLabelKey = "kyma-project.io/dashboard" - DashboardLabelValue = "eventing" - BackendLabelKey = "eventing.kyma-project.io/backend" publisherPortName = "http" publisherPortNum = int32(8080) publisherMetricsPortName = "http-metrics" publisherMetricsPortNum = int32(9090) PublisherName = "eventing-publisher-proxy" - AppLabelKey = "app.kubernetes.io/name" PublisherSecretClientIDKey = "client-id" PublisherSecretClientSecretKey = "client-secret" PublisherSecretTokenEndpointKey = "token-endpoint" @@ -56,6 +51,7 @@ func newNATSPublisherDeployment( eventing, publisherConfig, WithLabels(GetPublisherDeploymentName(*eventing), v1alpha1.NatsBackendType), + WithSelector(GetPublisherDeploymentName(*eventing)), WithContainers(publisherConfig, eventing), WithNATSEnvVars(natsConfig, publisherConfig, eventing), WithLogEnvVars(publisherConfig, eventing), @@ -72,6 +68,7 @@ func newEventMeshPublisherDeployment( eventing, publisherConfig, WithLabels(GetPublisherDeploymentName(*eventing), v1alpha1.EventMeshBackendType), + WithSelector(GetPublisherDeploymentName(*eventing)), WithContainers(publisherConfig, eventing), WithBEBEnvVars(GetPublisherDeploymentName(*eventing), publisherConfig, eventing), WithLogEnvVars(publisherConfig, eventing), @@ -126,19 +123,39 @@ func getPodSecurityContext() *v1.PodSecurityContext { } } -func WithLabels(publisherName string, backendType v1alpha1.BackendType) DeployOpt { - labels := map[string]string{ - AppLabelKey: publisherName, - InstanceLabelKey: InstanceLabelValue, - DashboardLabelKey: DashboardLabelValue, +func getLabels(publisherName string, backendType v1alpha1.BackendType) map[string]string { + return map[string]string{ + label.KeyComponent: label.ValueEventingManager, + label.KeyCreatedBy: label.ValueEventingManager, + label.KeyInstance: label.ValueEventing, + label.KeyManagedBy: label.ValueEventingManager, + label.KeyName: publisherName, + label.KeyPartOf: label.ValueEventingManager, + label.KeyBackend: fmt.Sprint(getECBackendType(backendType)), + label.KeyDashboard: label.ValueEventing, } +} + +func WithLabels(publisherName string, backendType v1alpha1.BackendType) DeployOpt { return func(d *appsv1.Deployment) { - d.Spec.Selector = metav1.SetAsLabelSelector(labels) + labels := getLabels(publisherName, backendType) + d.ObjectMeta.Labels = labels d.Spec.Template.ObjectMeta.Labels = labels + } +} - // label the event-publisher proxy with the backendType label - labels[BackendLabelKey] = fmt.Sprint(getECBackendType(backendType)) - d.ObjectMeta.Labels = labels +func getSelector(publisherName string) *metav1.LabelSelector { + labels := map[string]string{ + label.KeyInstance: label.ValueEventing, + label.KeyName: publisherName, + label.KeyDashboard: label.ValueEventing, + } + return metav1.SetAsLabelSelector(labels) +} + +func WithSelector(publisherName string) DeployOpt { + return func(d *appsv1.Deployment) { + d.Spec.Selector = getSelector(publisherName) } } @@ -157,7 +174,7 @@ func WithAffinity(publisherName string) DeployOpt { Weight: 100, PodAffinityTerm: v1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ - MatchLabels: map[string]string{AppLabelKey: publisherName}, + MatchLabels: map[string]string{label.KeyName: publisherName}, }, TopologyKey: "kubernetes.io/hostname", }, diff --git a/pkg/eventing/deployment_test.go b/pkg/eventing/deployment_test.go index 1d0ff82af..f3bd413d5 100644 --- a/pkg/eventing/deployment_test.go +++ b/pkg/eventing/deployment_test.go @@ -2,16 +2,17 @@ package eventing import ( "fmt" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" "testing" - appsv1 "k8s.io/api/apps/v1" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" + "github.com/kyma-project/eventing-manager/internal/label" "github.com/kyma-project/eventing-manager/pkg/env" "github.com/kyma-project/eventing-manager/test" testutils "github.com/kyma-project/eventing-manager/test/utils" @@ -77,9 +78,9 @@ func TestNewDeployment(t *testing.T) { t.Errorf("Invalid backend!") } - // the tight backenType should be set - assert.Equal(t, deployment.ObjectMeta.Labels[BackendLabelKey], string(getECBackendType(tc.givenBackendType))) - assert.Equal(t, deployment.ObjectMeta.Labels[AppLabelKey], publisherName) + // the right backendType should be set + assert.Equal(t, deployment.ObjectMeta.Labels[label.KeyBackend], string(getECBackendType(tc.givenBackendType))) + assert.Equal(t, deployment.ObjectMeta.Labels[label.KeyName], publisherName) // check the container properties were set properly container := findPublisherContainer(publisherName, *deployment) @@ -327,3 +328,121 @@ func findPublisherContainer(publisherName string, deployment appsv1.Deployment) } return container } + +func Test_getLabels(t *testing.T) { + // given + const ( + publisherName = "test-publisher" + backendTypeUnsupported = "Unsupported" + backendTypeEventMesh = "EventMesh" + backendTypeNATS = "NATS" + ) + type args struct { + publisherName string + backendType v1alpha1.BackendType + } + tests := []struct { + name string + args args + want map[string]string + }{ + { + name: "should return the correct labels for backend NATS", + args: args{ + publisherName: publisherName, + backendType: backendTypeNATS, + }, + want: map[string]string{ + label.KeyComponent: label.ValueEventingManager, + label.KeyCreatedBy: label.ValueEventingManager, + label.KeyInstance: label.ValueEventing, + label.KeyManagedBy: label.ValueEventingManager, + label.KeyName: publisherName, + label.KeyPartOf: label.ValueEventingManager, + label.KeyBackend: "NATS", + label.KeyDashboard: label.ValueEventing, + }, + }, + { + name: "should return the correct labels for backend EventMesh", + args: args{ + publisherName: publisherName, + backendType: backendTypeEventMesh, + }, + want: map[string]string{ + label.KeyComponent: label.ValueEventingManager, + label.KeyCreatedBy: label.ValueEventingManager, + label.KeyInstance: label.ValueEventing, + label.KeyManagedBy: label.ValueEventingManager, + label.KeyName: publisherName, + label.KeyPartOf: label.ValueEventingManager, + label.KeyBackend: "BEB", + label.KeyDashboard: label.ValueEventing, + }, + }, + { + name: "should return the correct labels for unsupported backend", + args: args{ + publisherName: publisherName, + backendType: backendTypeUnsupported, + }, + want: map[string]string{ + label.KeyComponent: label.ValueEventingManager, + label.KeyCreatedBy: label.ValueEventingManager, + label.KeyInstance: label.ValueEventing, + label.KeyManagedBy: label.ValueEventingManager, + label.KeyName: publisherName, + label.KeyPartOf: label.ValueEventingManager, + label.KeyBackend: "NATS", + label.KeyDashboard: label.ValueEventing, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // when + got := getLabels(tt.args.publisherName, tt.args.backendType) + + // then + require.Equal(t, tt.want, got) + }) + } +} + +func Test_getSelector(t *testing.T) { + // given + const ( + publisherName = "test-publisher" + ) + type args struct { + publisherName string + } + tests := []struct { + name string + args args + want *metav1.LabelSelector + }{ + { + name: "should return the correct selector", + args: args{ + publisherName: publisherName, + }, + want: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + label.KeyInstance: label.ValueEventing, + label.KeyName: publisherName, + label.KeyDashboard: label.ValueEventing, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // when + got := getSelector(tt.args.publisherName) + + // then + require.Equal(t, tt.want, got) + }) + } +} diff --git a/pkg/eventing/manager.go b/pkg/eventing/manager.go index 7ed46c425..0a344adb1 100644 --- a/pkg/eventing/manager.go +++ b/pkg/eventing/manager.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - ecv1alpha1 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/record" @@ -16,6 +15,7 @@ import ( "github.com/kyma-project/eventing-manager/pkg/k8s" "github.com/kyma-project/eventing-manager/pkg/logger" "github.com/kyma-project/eventing-manager/pkg/object" + ecv1alpha1 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha1" ) const ( @@ -210,7 +210,7 @@ func (em EventingManager) DeployPublisherProxyResources( publisherDeployment.Spec.Template.Labels), // HPA to auto-scale publisher proxy. newHorizontalPodAutoscaler(publisherDeployment.Name, publisherDeployment.Namespace, int32(eventing.Spec.Publisher.Min), - int32(eventing.Spec.Publisher.Max), cpuUtilization, memoryUtilization), + int32(eventing.Spec.Publisher.Max), cpuUtilization, memoryUtilization, publisherDeployment.Labels), } // create the resources on k8s. @@ -254,7 +254,7 @@ func (em EventingManager) DeletePublisherProxyResources(ctx context.Context, eve // Service to expose health endpoint of EPP. newPublisherProxyHealthService(GetPublisherHealthServiceName(*eventing), eventing.Namespace, map[string]string{}, map[string]string{}), // HPA to auto-scale publisher proxy. - newHorizontalPodAutoscaler(publisherDeployment.Name, eventing.Namespace, 0, 0, 0, 0), + newHorizontalPodAutoscaler(publisherDeployment.Name, eventing.Namespace, 0, 0, 0, 0, map[string]string{}), } // delete the resources on k8s. diff --git a/pkg/eventing/utils.go b/pkg/eventing/utils.go index d8421bfbd..2a63cd079 100644 --- a/pkg/eventing/utils.go +++ b/pkg/eventing/utils.go @@ -42,7 +42,8 @@ func GetPublisherClusterRoleBindingName(eventing v1alpha1.Eventing) string { return fmt.Sprintf("%s-%s", eventing.GetName(), publisherProxySuffix) } -func newHorizontalPodAutoscaler(name, namespace string, min int32, max int32, cpuUtilization, memoryUtilization int32) *autoscalingv2.HorizontalPodAutoscaler { +func newHorizontalPodAutoscaler(name, namespace string, min, max, cpuUtilization, memoryUtilization int32, + labels map[string]string) *autoscalingv2.HorizontalPodAutoscaler { return &autoscalingv2.HorizontalPodAutoscaler{ TypeMeta: metav1.TypeMeta{ Kind: "HorizontalPodAutoscaler", @@ -51,6 +52,7 @@ func newHorizontalPodAutoscaler(name, namespace string, min int32, max int32, cp ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, + Labels: labels, }, Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ diff --git a/pkg/eventing/utils_test.go b/pkg/eventing/utils_test.go index 635d6fdae..6aad05593 100644 --- a/pkg/eventing/utils_test.go +++ b/pkg/eventing/utils_test.go @@ -3,9 +3,11 @@ package eventing import ( "testing" - "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/kyma-project/eventing-manager/api/operator.kyma-project.io/v1alpha1" + ecv1alpha1 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha1" ) func Test_EPPResourcesNames(t *testing.T) { @@ -23,3 +25,46 @@ func Test_EPPResourcesNames(t *testing.T) { require.Equal(t, "test1-publisher-proxy", GetPublisherClusterRoleName(eventingCR)) require.Equal(t, "test1-publisher-proxy", GetPublisherClusterRoleBindingName(eventingCR)) } + +func Test_getECBackendType(t *testing.T) { + // given + type args struct { + backendType v1alpha1.BackendType + } + tests := []struct { + name string + args args + want ecv1alpha1.BackendType + }{ + { + name: "should return the correct backend type for NATS", + args: args{ + backendType: "NATS", + }, + want: "NATS", + }, + { + name: "should return the correct backend type for EventMesh", + args: args{ + backendType: "EventMesh", + }, + want: "BEB", + }, + { + name: "should return the default backend type for unsupported input", + args: args{ + backendType: "Unsupported", + }, + want: "NATS", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // when + got := getECBackendType(tt.args.backendType) + + // then + require.Equal(t, tt.want, got) + }) + } +} diff --git a/pkg/object/equality_test.go b/pkg/object/equality_test.go index 056aafe80..ed2acda6b 100644 --- a/pkg/object/equality_test.go +++ b/pkg/object/equality_test.go @@ -605,6 +605,80 @@ func TestPublisherProxyDeploymentEqual(t *testing.T) { }, expectedResult: true, }, + "should be equal if spec Labels are equal with same order": { + getPublisher1: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + "key2": "value2", + } + return p + }, + getPublisher2: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + "key2": "value2", + } + return p + }, + expectedResult: true, + }, + "should be equal if spec Labels are equal with different order": { + getPublisher1: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + "key2": "value2", + } + return p + }, + getPublisher2: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key2": "value2", + "key1": "value1", + } + return p + }, + expectedResult: true, + }, + "should not be equal if spec Labels were added": { + getPublisher1: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + } + return p + }, + getPublisher2: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + "key2": "value2", + } + return p + }, + expectedResult: false, + }, + "should not be equal if spec Labels were removed": { + getPublisher1: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + "key2": "value2", + } + return p + }, + getPublisher2: func() *appsv1.Deployment { + p := defaultNATSPublisher.DeepCopy() + p.Spec.Template.Labels = map[string]string{ + "key1": "value1", + } + return p + }, + expectedResult: false, + }, "should be unequal if spec Labels changes": { getPublisher1: func() *appsv1.Deployment { p := defaultNATSPublisher.DeepCopy() From 8d64f2200ef3c4e6cce30439e7088892a4e3220d Mon Sep 17 00:00:00 2001 From: Mansur Uralov Date: Fri, 24 Nov 2023 14:47:53 +0100 Subject: [PATCH 2/2] Make Eventing CR read if NATS CR in warning state (#269) --- go.mod | 8 ++++---- go.sum | 24 ++++++++++++------------ pkg/eventing/manager.go | 2 +- pkg/eventing/manager_test.go | 11 +++++++++++ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 1babdb805..ce343f69d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/kyma-incubator/api-gateway v0.0.0-20220819093753-296e6704d413 github.com/kyma-project/kyma/common/logging v0.0.0-20231113125307-562a57ab5198 github.com/kyma-project/kyma/components/eventing-controller v0.0.0-20231113125307-562a57ab5198 - github.com/kyma-project/nats-manager v1.0.2 + github.com/kyma-project/nats-manager v1.0.3-0.20231124103356-1904d89ab2b2 github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/nats-io/nats-server/v2 v2.10.5 github.com/nats-io/nats.go v1.31.0 @@ -96,13 +96,13 @@ require ( go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.15.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/mod v0.12.0 // indirect + golang.org/x/mod v0.13.0 // indirect golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/term v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.4.0 // indirect - golang.org/x/tools v0.13.0 // indirect + golang.org/x/tools v0.14.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect @@ -118,7 +118,7 @@ require ( k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect ) replace github.com/kyma-incubator/api-gateway => github.com/kyma-project/api-gateway v0.0.0-20220819093753-296e6704d413 diff --git a/go.sum b/go.sum index 028d751a3..93455f8f2 100644 --- a/go.sum +++ b/go.sum @@ -226,8 +226,8 @@ github.com/kyma-project/kyma/common/logging v0.0.0-20231113125307-562a57ab5198 h github.com/kyma-project/kyma/common/logging v0.0.0-20231113125307-562a57ab5198/go.mod h1:JGb5RBi8Uz+RZ/jf54+qA+RqY6uPQBJ8pO1w3KSwm1Q= github.com/kyma-project/kyma/components/eventing-controller v0.0.0-20231113125307-562a57ab5198 h1:/o4jabncHPmpvgFzGQ6TBzjbHmf111FDkOzgmdH3L4I= github.com/kyma-project/kyma/components/eventing-controller v0.0.0-20231113125307-562a57ab5198/go.mod h1:myk9NTLyoeWE5uo5y9oECUJqBkwcWPWW/8jq5g6EPy8= -github.com/kyma-project/nats-manager v1.0.2 h1:uJiVrLFFqnOsnz1IGNn76fm5cQoK+4L8GxP829mX2C8= -github.com/kyma-project/nats-manager v1.0.2/go.mod h1:gC0W/C2NgpmVnG/5v5f76ijNw5aloQLEkSuVOElB9gk= +github.com/kyma-project/nats-manager v1.0.3-0.20231124103356-1904d89ab2b2 h1:P8SMLPxQMCnPlwGMpqid5ofHPO2dvybu94F8K32GNmw= +github.com/kyma-project/nats-manager v1.0.3-0.20231124103356-1904d89ab2b2/go.mod h1:asVMhM0flO8aRcllmgABSuoPL+X9kdJ7tp8JPSPzpkk= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -273,8 +273,8 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.1 h1:LNGfMbR2OVGBfXjvRZIZ2YCTQdGKtPLvuI1rMCCj3OU= +github.com/onsi/ginkgo/v2 v2.13.1/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= @@ -406,8 +406,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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= @@ -468,8 +468,8 @@ 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/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/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-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -591,8 +591,8 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -756,5 +756,5 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMm sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.3.0 h1:UZbZAZfX0wV2zr7YZorDz6GXROfDFj6LvqCRm4VUVKk= sigs.k8s.io/structured-merge-diff/v4 v4.3.0/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/pkg/eventing/manager.go b/pkg/eventing/manager.go index 0a344adb1..da5f79d89 100644 --- a/pkg/eventing/manager.go +++ b/pkg/eventing/manager.go @@ -171,7 +171,7 @@ func (em EventingManager) IsNATSAvailable(ctx context.Context, namespace string) return false, err } for _, nats := range natsList.Items { - if nats.Status.State == v1alpha1.StateReady { + if nats.Status.State == v1alpha1.StateReady || nats.Status.State == v1alpha1.StateWarning { return true, nil } } diff --git a/pkg/eventing/manager_test.go b/pkg/eventing/manager_test.go index 363b7176e..2423bbacc 100644 --- a/pkg/eventing/manager_test.go +++ b/pkg/eventing/manager_test.go @@ -260,6 +260,17 @@ func Test_IsNATSAvailable(t *testing.T) { wantAvailable: true, wantErr: nil, }, + { + name: "NATS is available if in Warning state", + givenNATSResources: []natsv1alpha1.NATS{ + *natstestutils.NewNATSCR( + natstestutils.WithNATSStateWarning(), + ), + }, + givenNamespace: "test-namespace", + wantAvailable: true, + wantErr: nil, + }, { name: "NATS is not available", givenNATSResources: []natsv1alpha1.NATS{