[GitHub] nicolaferraro closed pull request #55: Store integration code in a configmap

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] nicolaferraro closed pull request #55: Store integration code in a configmap

GitBox
nicolaferraro closed pull request #55: Store integration code in a configmap
URL: https://github.com/apache/camel-k/pull/55
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/deploy/operator.yaml b/deploy/operator.yaml
index 426387a..a2c4abc 100644
--- a/deploy/operator.yaml
+++ b/deploy/operator.yaml
@@ -2,8 +2,6 @@ apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: camel-k-operator
-  labels:
-    app: "camel-k"
 spec:
   replicas: 1
   selector:
@@ -17,9 +15,6 @@ spec:
       containers:
         - name: camel-k-operator
           image: docker.io/apache/camel-k:0.0.1-SNAPSHOT
-          ports:
-          - containerPort: 60000
-            name: metrics
           command:
           - camel-k-operator
           imagePullPolicy: Always
@@ -28,5 +23,3 @@ spec:
               valueFrom:
                 fieldRef:
                   fieldPath: metadata.namespace
-            - name: OPERATOR_NAME
-              value: "camel-k-operator"
diff --git a/deploy/resources.go b/deploy/resources.go
index 02b58ba..96995ce 100644
--- a/deploy/resources.go
+++ b/deploy/resources.go
@@ -359,8 +359,6 @@ apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: camel-k-operator
-  labels:
-    app: "camel-k"
 spec:
   replicas: 1
   selector:
@@ -374,9 +372,6 @@ spec:
       containers:
         - name: camel-k-operator
           image: docker.io/apache/camel-k:0.0.1-SNAPSHOT
-          ports:
-          - containerPort: 60000
-            name: metrics
           command:
           - camel-k-operator
           imagePullPolicy: Always
@@ -385,8 +380,6 @@ spec:
               valueFrom:
                 fieldRef:
                   fieldPath: metadata.namespace
-            - name: OPERATOR_NAME
-              value: "camel-k-operator"
 
 `
  Resources["user-cluster-role.yaml"] =
diff --git a/pkg/build/local/local_builder.go b/pkg/build/local/local_builder.go
index df96879..cd5b7b0 100644
--- a/pkg/build/local/local_builder.go
+++ b/pkg/build/local/local_builder.go
@@ -280,10 +280,8 @@ func generateProjectDefinition(source build.BuildSource) (maven.ProjectDefinitio
  Dependencies: make([]maven.Dependency, 0),
  },
  },
- Resources: map[string]string{
- source.Code.Name: source.Code.Content,
- },
- Env: make(map[string]string),
+ Resources: make(map[string]string),
+ Env:       make(map[string]string),
  }
 
  //
@@ -312,17 +310,5 @@ func generateProjectDefinition(source build.BuildSource) (maven.ProjectDefinitio
  }
  }
 
- //
- // set-up env
- //
-
- project.Env["JAVA_MAIN_CLASS"] = "org.apache.camel.k.jvm.Application"
- project.Env["CAMEL_K_ROUTES_URI"] = "classpath:" + source.Code.Name
-
- // Don't set the language if not set
- if source.Code.Language != "" {
- project.Env["CAMEL_K_ROUTES_LANGUAGE"] = source.Code.Language
- }
-
  return project, nil
 }
diff --git a/pkg/stub/action/integration/deploy.go b/pkg/stub/action/integration/deploy.go
index 43e50b8..3403928 100644
--- a/pkg/stub/action/integration/deploy.go
+++ b/pkg/stub/action/integration/deploy.go
@@ -18,10 +18,12 @@ limitations under the License.
 package action
 
 import (
+ "strings"
+
  "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
  "github.com/operator-framework/operator-sdk/pkg/sdk"
  "github.com/pkg/errors"
- "k8s.io/api/apps/v1"
+ appsv1 "k8s.io/api/apps/v1"
  corev1 "k8s.io/api/core/v1"
  k8serrors "k8s.io/apimachinery/pkg/api/errors"
  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,32 +45,88 @@ func (a *DeployAction) CanHandle(integration *v1alpha1.Integration) bool {
 }
 
 func (a *DeployAction) Handle(integration *v1alpha1.Integration) error {
+ if err := createOrUpdateConfigMap(integration); err != nil {
+ return err
+ }
+ if err := createOrUpdateDeployment(integration); err != nil {
+ return err
+ }
 
- deployment := a.getDeploymentFor(integration)
- err := sdk.Create(deployment)
- if err != nil && k8serrors.IsAlreadyExists(err) {
- err = sdk.Update(deployment)
+ return nil
+}
+
+// **********************************
+//
+// ConfigMap
+//
+// **********************************
+
+func getConfigMapFor(integration *v1alpha1.Integration) *corev1.ConfigMap {
+ controller := true
+ blockOwnerDeletion := true
+
+ return &corev1.ConfigMap{
+ TypeMeta: metav1.TypeMeta{
+ Kind:       "ConfigMap",
+ APIVersion: "v1",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name:      integration.Name,
+ Namespace: integration.Namespace,
+ Labels:    integration.Labels,
+ Annotations: map[string]string{
+ "camel.apache.org/source.language": integration.Spec.Source.Language,
+ "camel.apache.org/source.name":     integration.Spec.Source.Name,
+ },
+ OwnerReferences: []metav1.OwnerReference{
+ {
+ APIVersion:         integration.APIVersion,
+ Kind:               integration.Kind,
+ Name:               integration.Name,
+ UID:                integration.UID,
+ Controller:         &controller,
+ BlockOwnerDeletion: &blockOwnerDeletion,
+ },
+ },
+ },
+ Data: map[string]string{
+ "integration": integration.Spec.Source.Content,
+ },
  }
+}
+
+func createOrUpdateConfigMap(integration *v1alpha1.Integration) error {
+ cm := getConfigMapFor(integration)
 
+ err := sdk.Create(cm)
+ if err != nil && k8serrors.IsAlreadyExists(err) {
+ err = sdk.Update(cm)
+ }
  if err != nil {
- return errors.Wrap(err, "could not create or replace deployment for integration "+integration.Name)
+ return errors.Wrap(err, "could not create or replace configmap for integration "+integration.Name)
  }
 
- target := integration.DeepCopy()
- target.Status.Phase = v1alpha1.IntegrationPhaseRunning
- return sdk.Update(target)
+ return err
 }
 
-func (*DeployAction) getDeploymentFor(integration *v1alpha1.Integration) *v1.Deployment {
+// **********************************
+//
+// Deployment
+//
+// **********************************
+
+func getDeploymentFor(integration *v1alpha1.Integration) *appsv1.Deployment {
  controller := true
  blockOwnerDeletion := true
+ integrationName := strings.TrimPrefix(integration.Spec.Source.Name, "/")
+
  labels := map[string]string{
  "camel.apache.org/integration": integration.Name,
  }
- deployment := v1.Deployment{
+ deployment := appsv1.Deployment{
  TypeMeta: metav1.TypeMeta{
  Kind:       "Deployment",
- APIVersion: v1.SchemeGroupVersion.String(),
+ APIVersion: appsv1.SchemeGroupVersion.String(),
  },
  ObjectMeta: metav1.ObjectMeta{
  Name:        integration.Name,
@@ -86,7 +144,7 @@ func (*DeployAction) getDeploymentFor(integration *v1alpha1.Integration) *v1.Dep
  },
  },
  },
- Spec: v1.DeploymentSpec{
+ Spec: appsv1.DeploymentSpec{
  Replicas: integration.Spec.Replicas,
  Selector: &metav1.LabelSelector{
  MatchLabels: labels,
@@ -100,6 +158,44 @@ func (*DeployAction) getDeploymentFor(integration *v1alpha1.Integration) *v1.Dep
  {
  Name:  integration.Name,
  Image: integration.Status.Image,
+ VolumeMounts: []corev1.VolumeMount{
+ {
+ Name:      "integration",
+ MountPath: "/etc/camel",
+ },
+ },
+ Env: []corev1.EnvVar{
+ {
+ Name:  "JAVA_MAIN_CLASS",
+ Value: "org.apache.camel.k.jvm.Application",
+ },
+ {
+ Name:  "CAMEL_K_ROUTES_URI",
+ Value: "file:/etc/camel/" + integrationName,
+ },
+ {
+ Name:  "CAMEL_K_ROUTES_LANGUAGE",
+ Value: integration.Spec.Source.Language,
+ },
+ },
+ },
+ },
+ Volumes: []corev1.Volume{
+ {
+ Name: "integration",
+ VolumeSource: corev1.VolumeSource{
+ ConfigMap: &corev1.ConfigMapVolumeSource{
+ LocalObjectReference: corev1.LocalObjectReference{
+ Name: integration.Name,
+ },
+ Items: []corev1.KeyToPath{
+ {
+ Key:  "integration",
+ Path: integrationName,
+ },
+ },
+ },
+ },
  },
  },
  },
@@ -109,3 +205,20 @@ func (*DeployAction) getDeploymentFor(integration *v1alpha1.Integration) *v1.Dep
 
  return &deployment
 }
+
+func createOrUpdateDeployment(integration *v1alpha1.Integration) error {
+ deployment := getDeploymentFor(integration)
+
+ err := sdk.Create(deployment)
+ if err != nil && k8serrors.IsAlreadyExists(err) {
+ err = sdk.Update(deployment)
+ }
+ if err != nil {
+ return errors.Wrap(err, "could not create or replace deployment for integration "+integration.Name)
+ }
+
+ target := integration.DeepCopy()
+ target.Status.Phase = v1alpha1.IntegrationPhaseRunning
+
+ return sdk.Update(target)
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services