You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2020/07/02 06:50:04 UTC
[camel-k] 02/02: chore: Declare an integration label constant
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit e32c61722cf9a4b0af18738cfe393ac3f9e2ff32
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Jul 1 17:59:29 2020 +0200
chore: Declare an integration label constant
---
addons/master/master.go | 2 +-
addons/threescale/3scale_test.go | 2 +-
e2e/support/test_support.go | 2 +-
pkg/apis/camel/v1/integration_types_support.go | 2 ++
pkg/controller/integration/integration_controller.go | 2 +-
pkg/controller/integration/monitor.go | 4 ++--
pkg/trait/affinity.go | 4 ++--
pkg/trait/affinity_test.go | 4 ++--
pkg/trait/cron.go | 2 +-
pkg/trait/deployment.go | 6 +++---
pkg/trait/deployment_test.go | 2 +-
pkg/trait/gc.go | 4 ++--
pkg/trait/ingress_test.go | 4 ++--
pkg/trait/knative_service.go | 2 +-
pkg/trait/openapi.go | 2 +-
pkg/trait/prometheus.go | 6 +++---
pkg/trait/prometheus_test.go | 8 ++++----
pkg/trait/route.go | 2 +-
pkg/trait/route_test.go | 4 ++--
pkg/trait/service.go | 4 ++--
pkg/trait/trait_types.go | 6 +++---
pkg/util/kubernetes/collection.go | 6 +++---
pkg/util/kubernetes/conditions.go | 2 +-
pkg/util/kubernetes/log/util.go | 2 +-
24 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/addons/master/master.go b/addons/master/master.go
index a88d90c..e9ca949 100644
--- a/addons/master/master.go
+++ b/addons/master/master.go
@@ -109,7 +109,7 @@ func (t *masterTrait) Configure(e *trait.Environment) (bool, error) {
}
if t.LabelKey == nil {
- val := "camel.apache.org/integration"
+ val := v1.IntegrationLabel
t.LabelKey = &val
}
diff --git a/addons/threescale/3scale_test.go b/addons/threescale/3scale_test.go
index ccdd126..149a4e8 100644
--- a/addons/threescale/3scale_test.go
+++ b/addons/threescale/3scale_test.go
@@ -95,7 +95,7 @@ func createEnvironment(t *testing.T) (*corev1.Service, *trait.Environment) {
svc := corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
- "camel.apache.org/integration": "test",
+ v1.IntegrationLabel: "test",
},
},
}
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 6454bd0..6f76aba 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -257,7 +257,7 @@ func IntegrationPod(ns string, name string) func() *corev1.Pod {
err := TestClient.List(TestContext, &lst,
k8sclient.InNamespace(ns),
k8sclient.MatchingLabels{
- "camel.apache.org/integration": name,
+ v1.IntegrationLabel: name,
})
if err != nil {
panic(err)
diff --git a/pkg/apis/camel/v1/integration_types_support.go b/pkg/apis/camel/v1/integration_types_support.go
index d16394c..dd848f0 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -25,6 +25,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
+const IntegrationLabel = "camel.apache.org/integration"
+
// NewIntegration --
func NewIntegration(namespace string, name string) Integration {
return Integration{
diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go
index 96f4e1e..8170a37 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -175,7 +175,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
var requests []reconcile.Request
labels := rs.GetLabels()
- integrationName, ok := labels["camel.apache.org/integration"]
+ integrationName, ok := labels[v1.IntegrationLabel]
if ok {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go
index d350614..2b55f59 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -74,14 +74,14 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra
// Enforce the scale sub-resource label selector
// It is used by the HPA that queries the scale sub-resource endpoint to list the pods owned by the integration
- integration.Status.Selector = "camel.apache.org/integration=" + integration.Name
+ integration.Status.Selector = v1.IntegrationLabel + "=" + integration.Name
// Check replicas
replicaSets := &appsv1.ReplicaSetList{}
err = action.client.List(ctx, replicaSets,
k8sclient.InNamespace(integration.Namespace),
k8sclient.MatchingLabels{
- "camel.apache.org/integration": integration.Name,
+ v1.IntegrationLabel: integration.Name,
})
if err != nil {
return nil, err
diff --git a/pkg/trait/affinity.go b/pkg/trait/affinity.go
index 3ab91b3..5c65a4a 100644
--- a/pkg/trait/affinity.go
+++ b/pkg/trait/affinity.go
@@ -162,7 +162,7 @@ func (t *affinityTrait) addPodAffinity(e *Environment, deployment *appsv1.Deploy
if t.PodAffinity {
labelSelectorRequirements = append(labelSelectorRequirements, metav1.LabelSelectorRequirement{
- Key: "camel.apache.org/integration",
+ Key: v1.IntegrationLabel,
Operator: metav1.LabelSelectorOpIn,
Values: []string{
e.Integration.Name,
@@ -218,7 +218,7 @@ func (t *affinityTrait) addPodAntiAffinity(e *Environment, deployment *appsv1.De
if t.PodAntiAffinity {
labelSelectorRequirements = append(labelSelectorRequirements, metav1.LabelSelectorRequirement{
- Key: "camel.apache.org/integration",
+ Key: v1.IntegrationLabel,
Operator: metav1.LabelSelectorOpIn,
Values: []string{
e.Integration.Name,
diff --git a/pkg/trait/affinity_test.go b/pkg/trait/affinity_test.go
index 506b2f3..18dcf7f 100644
--- a/pkg/trait/affinity_test.go
+++ b/pkg/trait/affinity_test.go
@@ -98,7 +98,7 @@ func TestApplyPodAntiAffinityLabelsDoesSucceed(t *testing.T) {
assert.ElementsMatch(t, [1]string{"value"}, userRequirement.Values)
assert.NotNil(t, podAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchExpressions[1])
integrationRequirement := podAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchExpressions[1]
- assert.Equal(t, "camel.apache.org/integration", integrationRequirement.Key)
+ assert.Equal(t, v1.IntegrationLabel, integrationRequirement.Key)
assert.Equal(t, metav1.LabelSelectorOpIn, integrationRequirement.Operator)
assert.ElementsMatch(t, [1]string{"integration-name"}, integrationRequirement.Values)
}
@@ -119,7 +119,7 @@ func TestApplyPodAffinityLabelsDoesSucceed(t *testing.T) {
assert.Equal(t, metav1.LabelSelectorOpDoesNotExist, userRequirement.Operator)
assert.NotNil(t, podAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchExpressions[1])
integrationRequirement := podAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector.MatchExpressions[1]
- assert.Equal(t, "camel.apache.org/integration", integrationRequirement.Key)
+ assert.Equal(t, v1.IntegrationLabel, integrationRequirement.Key)
assert.Equal(t, metav1.LabelSelectorOpIn, integrationRequirement.Operator)
assert.ElementsMatch(t, [1]string{"integration-name"}, integrationRequirement.Values)
}
diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 3f740b1..fd7f264 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -258,7 +258,7 @@ func (t *cronTrait) Apply(e *Environment) error {
func (t *cronTrait) getCronJobFor(e *Environment) *v1beta1.CronJob {
labels := map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
}
annotations := make(map[string]string)
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index a56ec06..f7a048b 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -155,7 +155,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
Name: e.Integration.Name,
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
Annotations: annotations,
},
@@ -163,13 +163,13 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
Replicas: e.Integration.Spec.Replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
Annotations: annotations,
},
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index 9798e72..2d5a838 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -152,7 +152,7 @@ func createNominalDeploymentTest() (*deploymentTrait, *Environment) {
Name: "integration-name",
Namespace: "namespace",
Labels: map[string]string{
- "camel.apache.org/integration": "integration-name",
+ v1.IntegrationLabel: "integration-name",
},
},
Spec: appsv1.DeploymentSpec{
diff --git a/pkg/trait/gc.go b/pkg/trait/gc.go
index 5823b13..bcd3e43 100644
--- a/pkg/trait/gc.go
+++ b/pkg/trait/gc.go
@@ -114,7 +114,7 @@ func (t *garbageCollectorTrait) Apply(e *Environment) error {
// Label the resource with the current integration generation
labels["camel.apache.org/generation"] = generation
// Make sure the integration label is set
- labels["camel.apache.org/integration"] = env.Integration.Name
+ labels[v1.IntegrationLabel] = env.Integration.Name
resource.SetLabels(labels)
})
return nil
@@ -125,7 +125,7 @@ func (t *garbageCollectorTrait) Apply(e *Environment) error {
}
func (t *garbageCollectorTrait) garbageCollectResources(e *Environment) {
- integration, _ := labels.NewRequirement("camel.apache.org/integration", selection.Equals, []string{e.Integration.Name})
+ integration, _ := labels.NewRequirement(v1.IntegrationLabel, selection.Equals, []string{e.Integration.Name})
generation, err := labels.NewRequirement("camel.apache.org/generation", selection.LessThan, []string{strconv.FormatInt(e.Integration.GetGeneration(), 10)})
if err != nil {
t.L.ForIntegration(e.Integration).Errorf(err, "cannot determine generation requirement")
diff --git a/pkg/trait/ingress_test.go b/pkg/trait/ingress_test.go
index 390efac..4536d02 100644
--- a/pkg/trait/ingress_test.go
+++ b/pkg/trait/ingress_test.go
@@ -181,14 +181,14 @@ func createNominalIngressTest() (*ingressTrait, *Environment) {
Name: "service-name",
Namespace: "namespace",
Labels: map[string]string{
- "camel.apache.org/integration": "integration-name",
+ v1.IntegrationLabel: "integration-name",
"camel.apache.org/service.type": v1.ServiceTypeUser,
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{},
Selector: map[string]string{
- "camel.apache.org/integration": "integration-name",
+ v1.IntegrationLabel: "integration-name",
},
},
},
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index bea1513..ed84f5d 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -262,7 +262,7 @@ func (t *knativeServiceTrait) ControllerStrategySelectorOrder() int {
func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
labels := map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
}
annotations := make(map[string]string)
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 43895d4..99d94bc 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -257,7 +257,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Res
Name: generatedContentName,
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
Annotations: map[string]string{
"camel.apache.org/source.language": string(v1.LanguageXML),
diff --git a/pkg/trait/prometheus.go b/pkg/trait/prometheus.go
index cffb4f4..ecee2a2 100644
--- a/pkg/trait/prometheus.go
+++ b/pkg/trait/prometheus.go
@@ -222,7 +222,7 @@ func (t *prometheusTrait) getServiceMonitorFor(e *Environment) (*monitoringv1.Se
if err != nil {
return nil, err
}
- labels["camel.apache.org/integration"] = e.Integration.Name
+ labels[v1.IntegrationLabel] = e.Integration.Name
smt := monitoringv1.ServiceMonitor{
TypeMeta: metav1.TypeMeta{
@@ -237,7 +237,7 @@ func (t *prometheusTrait) getServiceMonitorFor(e *Environment) (*monitoringv1.Se
Spec: monitoringv1.ServiceMonitorSpec{
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
},
Endpoints: []monitoringv1.Endpoint{
@@ -266,7 +266,7 @@ func (t *prometheusTrait) getJmxExporterConfigMapOrAdd(e *Environment) string {
Name: defaultName,
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
},
Data: map[string]string{
diff --git a/pkg/trait/prometheus_test.go b/pkg/trait/prometheus_test.go
index 6eb6db5..6fb6e92 100644
--- a/pkg/trait/prometheus_test.go
+++ b/pkg/trait/prometheus_test.go
@@ -128,14 +128,14 @@ func TestApplyPrometheusTraitWithServiceDoesSucceed(t *testing.T) {
Name: "service-name",
Namespace: "namespace",
Labels: map[string]string{
- "camel.apache.org/integration": "integration-name",
+ v1.IntegrationLabel: "integration-name",
"camel.apache.org/service.type": v1.ServiceTypeUser,
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{},
Selector: map[string]string{
- "camel.apache.org/integration": "integration-name",
+ v1.IntegrationLabel: "integration-name",
},
},
})
@@ -162,8 +162,8 @@ func TestPrometheusTraitGetServiceMonitor(t *testing.T) {
assert.Equal(t, "monitoring.coreos.com/v1", serviceMonitor.APIVersion)
assert.Equal(t, "integration-name", serviceMonitor.Name)
assert.Equal(t, "integration-namespace", serviceMonitor.Namespace)
- assert.Equal(t, "integration-name", serviceMonitor.Labels["camel.apache.org/integration"])
- assert.Equal(t, "integration-name", serviceMonitor.Spec.Selector.MatchLabels["camel.apache.org/integration"])
+ assert.Equal(t, "integration-name", serviceMonitor.Labels[v1.IntegrationLabel])
+ assert.Equal(t, "integration-name", serviceMonitor.Spec.Selector.MatchLabels[v1.IntegrationLabel])
assert.Len(t, serviceMonitor.Spec.Endpoints, 1)
assert.Equal(t, "prometheus", serviceMonitor.Spec.Endpoints[0].Port)
}
diff --git a/pkg/trait/route.go b/pkg/trait/route.go
index 7a866b5..9962823 100644
--- a/pkg/trait/route.go
+++ b/pkg/trait/route.go
@@ -127,7 +127,7 @@ func (t *routeTrait) Apply(e *Environment) error {
Name: t.service.Name,
Namespace: t.service.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
},
Spec: routev1.RouteSpec{
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index bba96d2..71fb0d6 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -77,14 +77,14 @@ func createTestRouteEnvironment(t *testing.T, name string) *Environment {
Name: name,
Namespace: "test-ns",
Labels: map[string]string{
- "camel.apache.org/integration": name,
+ v1.IntegrationLabel: name,
"camel.apache.org/service.type": v1.ServiceTypeUser,
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{},
Selector: map[string]string{
- "camel.apache.org/integration": name,
+ v1.IntegrationLabel: name,
},
},
},
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 8f31e3d..30e3cf8 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -135,13 +135,13 @@ func getServiceFor(e *Environment) *corev1.Service {
Name: e.Integration.Name,
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{},
Selector: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
},
}
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 6352c7a..eeeedd5 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -355,7 +355,7 @@ func (e *Environment) ComputeApplicationProperties() *corev1.ConfigMap {
Name: e.Integration.Name + "-application-properties",
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
"camel.apache.org/properties.type": "application",
},
},
@@ -393,7 +393,7 @@ func (e *Environment) ComputeConfigMaps() []runtime.Object {
Name: e.Integration.Name + "-user-properties",
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
"camel.apache.org/properties.type": "user",
},
},
@@ -418,7 +418,7 @@ func (e *Environment) ComputeConfigMaps() []runtime.Object {
Name: fmt.Sprintf("%s-source-%03d", e.Integration.Name, i),
Namespace: e.Integration.Namespace,
Labels: map[string]string{
- "camel.apache.org/integration": e.Integration.Name,
+ v1.IntegrationLabel: e.Integration.Name,
},
Annotations: map[string]string{
"camel.apache.org/source.language": string(s.InferLanguage()),
diff --git a/pkg/util/kubernetes/collection.go b/pkg/util/kubernetes/collection.go
index d4b6140..bbfb5d2 100644
--- a/pkg/util/kubernetes/collection.go
+++ b/pkg/util/kubernetes/collection.go
@@ -124,7 +124,7 @@ func (c *Collection) GetDeploymentForIntegration(integration *v1.Integration) *a
}
return c.GetDeployment(func(d *appsv1.Deployment) bool {
- return d.ObjectMeta.Labels["camel.apache.org/integration"] == integration.Name
+ return d.ObjectMeta.Labels[v1.IntegrationLabel] == integration.Name
})
}
@@ -208,7 +208,7 @@ func (c *Collection) GetUserServiceForIntegration(integration *v1.Integration) *
}
return c.GetService(func(s *corev1.Service) bool {
return s.ObjectMeta.Labels != nil &&
- s.ObjectMeta.Labels["camel.apache.org/integration"] == integration.Name &&
+ s.ObjectMeta.Labels[v1.IntegrationLabel] == integration.Name &&
s.ObjectMeta.Labels["camel.apache.org/service.type"] == v1.ServiceTypeUser
})
}
@@ -219,7 +219,7 @@ func (c *Collection) GetServiceForIntegration(integration *v1.Integration) *core
return nil
}
return c.GetService(func(s *corev1.Service) bool {
- return s.ObjectMeta.Labels != nil && s.ObjectMeta.Labels["camel.apache.org/integration"] == integration.Name
+ return s.ObjectMeta.Labels != nil && s.ObjectMeta.Labels[v1.IntegrationLabel] == integration.Name
})
}
diff --git a/pkg/util/kubernetes/conditions.go b/pkg/util/kubernetes/conditions.go
index bb8e3c4..88e5465 100644
--- a/pkg/util/kubernetes/conditions.go
+++ b/pkg/util/kubernetes/conditions.go
@@ -50,7 +50,7 @@ func MirrorReadyCondition(ctx context.Context, c client.Client, it *v1.Integrati
func mirrorReadyConditionFromReplicaSet(ctx context.Context, c client.Client, it *v1.Integration) {
list := appsv1.ReplicaSetList{}
opts := runtimeclient.MatchingLabels{
- "camel.apache.org/integration": it.Name,
+ v1.IntegrationLabel: it.Name,
}
if err := c.List(ctx, &list, opts, runtimeclient.InNamespace(it.Namespace)); err != nil {
setReadyConditionError(it, err)
diff --git a/pkg/util/kubernetes/log/util.go b/pkg/util/kubernetes/log/util.go
index bd72a94..5539d13 100644
--- a/pkg/util/kubernetes/log/util.go
+++ b/pkg/util/kubernetes/log/util.go
@@ -30,7 +30,7 @@ import (
// Print prints integrations logs to the stdout
func Print(ctx context.Context, client kubernetes.Interface, integration *v1.Integration, out io.Writer) error {
- scraper := NewSelectorScraper(client, integration.Namespace, integration.Name, "camel.apache.org/integration="+integration.Name)
+ scraper := NewSelectorScraper(client, integration.Namespace, integration.Name, v1.IntegrationLabel+"="+integration.Name)
reader := scraper.Start(ctx)
if _, err := io.Copy(out, ioutil.NopCloser(reader)); err != nil {