Fix #1201: add label flag and fix e2e tests
diff --git a/e2e/addons_test.go b/e2e/addons_test.go
index 9b1a5a3..5620677 100644
--- a/e2e/addons_test.go
+++ b/e2e/addons_test.go
@@ -27,21 +27,42 @@
 
 	. "github.com/onsi/gomega"
 	v1 "k8s.io/api/core/v1"
+
+	_ "github.com/apache/camel-k/addons"
 )
 
 func TestAddons(t *testing.T) {
 	withNewTestNamespace(t, func(ns string) {
 		Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
 
-		t.Run("master addon", func(t *testing.T) {
+		t.Run("master works", func(t *testing.T) {
 			RegisterTestingT(t)
-			Expect(kamel("run", "-n", ns, "files/Master.java", "-t", `master.label-key=""`).Execute()).Should(BeNil())
+			Expect(kamel("run", "-n", ns, "files/Master.java").Execute()).Should(BeNil())
 			Eventually(integrationPodPhase(ns, "master"), 5*time.Minute).Should(Equal(v1.PodRunning))
 			Eventually(integrationLogs(ns, "master"), 1*time.Minute).Should(ContainSubstring("Magicstring!"))
 			Eventually(configMap(ns, "master-lock"), 30*time.Second).ShouldNot(BeNil())
+			Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+		})
+
+		t.Run("only one integration with master runs", func(t *testing.T) {
+			RegisterTestingT(t)
+			Expect(kamel("run", "-n", ns, "files/Master.java",
+				"--name", "first",
+				"--label", "leader-group=same",
+				"-t", "master.label-key=leader-group",
+				"-t", "master.label-value=same",
+				"-t", "owner.target-labels=leader-group").Execute()).Should(BeNil())
+			Eventually(integrationPodPhase(ns, "first"), 5*time.Minute).Should(Equal(v1.PodRunning))
+			Eventually(integrationLogs(ns, "first"), 1*time.Minute).Should(ContainSubstring("Magicstring!"))
+			Eventually(configMap(ns, "first-lock"), 30*time.Second).ShouldNot(BeNil())
 			// Start a second integration with the same lock (it should not start the route)
-			Expect(kamel("run", "-n", ns, "files/Master.java", "--name", "second",
-				"-t", "master.configmap=master-lock", "-t", `master.label-key=""`).Execute()).Should(BeNil())
+			Expect(kamel("run", "-n", ns, "files/Master.java",
+				"--name", "second",
+				"--label", "leader-group=same",
+				"-t", "master.label-key=leader-group",
+				"-t", "master.label-value=same",
+				"-t", "master.configmap=first-lock",
+				"-t", "owner.target-labels=leader-group").Execute()).Should(BeNil())
 			Eventually(integrationPodPhase(ns, "second"), 5*time.Minute).Should(Equal(v1.PodRunning))
 			Eventually(integrationLogs(ns, "second"), 1*time.Minute).Should(ContainSubstring("started in"))
 			Eventually(integrationLogs(ns, "second"), 30*time.Second).ShouldNot(ContainSubstring("Magicstring!"))
diff --git a/e2e/files/Master.java b/e2e/files/Master.java
index ff28451..84fdeeb 100644
--- a/e2e/files/Master.java
+++ b/e2e/files/Master.java
@@ -17,7 +17,7 @@
 
 import org.apache.camel.builder.RouteBuilder;
 
-public class Java extends RouteBuilder {
+public class Master extends RouteBuilder {
   @Override
   public void configure() throws Exception {
 	  from("master:lock:timer:tick")
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index dd35f72..5214ba7 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -87,6 +87,7 @@
 	cmd.Flags().StringArrayP("volume", "v", nil, "Mount a volume into the integration container. E.g \"-v pvcname:/container/path\"")
 	cmd.Flags().StringArrayP("env", "e", nil, "Set an environment variable in the integration container. E.g \"-e MY_VAR=my-value\"")
 	cmd.Flags().StringArrayP("property-file", "", nil, "Bind a property file to the integration. E.g. \"--property-file integration.properties\"")
+	cmd.Flags().StringArrayP("label", "", nil, "Add a label to the integration. E.g. \"--label my.company=hello\"")
 
 	cmd.Flags().Bool("save", false, "Save the run parameters into the default kamel configuration file (kamel-config.yaml)")
 
@@ -120,6 +121,7 @@
 	Volumes         []string `mapstructure:"volumes"`
 	EnvVars         []string `mapstructure:"envs"`
 	PropertyFiles   []string `mapstructure:"property-files"`
+	Labels          []string `mapstructure:"labels"`
 }
 
 func (o *runCmdOptions) decode(cmd *cobra.Command, args []string) error {
@@ -188,6 +190,13 @@
 		}
 	}
 
+	for _, label := range o.Labels {
+		parts := strings.Split(label, "=")
+		if len(parts) != 2 {
+			return fmt.Errorf(`invalid label specification %s. Expected "<labelkey>=<labelvalue>"`, label)
+		}
+	}
+
 	return nil
 }
 
@@ -378,6 +387,16 @@
 		},
 	}
 
+	for _, label := range o.Labels {
+		parts := strings.Split(label, "=")
+		if len(parts) == 2 {
+			if integration.Labels == nil {
+				integration.Labels = make(map[string]string)
+			}
+			integration.Labels[parts[0]] = parts[1]
+		}
+	}
+
 	for _, source := range sources {
 		data, err := o.loadData(source, o.Compression)
 		if err != nil {