Skip to content

Commit

Permalink
Fix apache#1574: implement changes in source loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Sep 14, 2020
1 parent 230a1e9 commit 56d06e0
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 192 deletions.
12 changes: 10 additions & 2 deletions deploy/resources.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions deploy/traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,23 @@ traits:
- name: options
type: '[]string'
description: A list of JVM options
- name: kamelets
platform: true
profiles:
- Kubernetes
- Knative
- OpenShift
description: The kamelets trait is a platform trait used to inject Kamelets into the integration runtime.
properties:
- name: enabled
type: bool
description: Can be used to enable or disable a trait. All traits share this common property.
- name: auto
type: bool
description: Automatically inject all referenced Kamelets and their default configuration (enabled by default)
- name: list
type: string
description: Comma separated list of Kamelet names to load into the current integration
- name: knative-service
platform: false
profiles:
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
** xref:traits:istio.adoc[Istio]
** xref:traits:jolokia.adoc[Jolokia]
** xref:traits:jvm.adoc[Jvm]
** xref:traits:kamelets.adoc[Kamelets]
** xref:traits:knative-service.adoc[Knative Service]
** xref:traits:knative.adoc[Knative]
** xref:traits:master.adoc[Master]
Expand Down
39 changes: 39 additions & 0 deletions docs/modules/traits/pages/kamelets.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
= Kamelets Trait

// Start of autogenerated code - DO NOT EDIT! (description)
The kamelets trait is a platform trait used to inject Kamelets into the integration runtime.


This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**.

WARNING: The kamelets trait is a *platform trait*: disabling it may compromise the platform functionality.

// End of autogenerated code - DO NOT EDIT! (description)
// Start of autogenerated code - DO NOT EDIT! (configuration)
== Configuration

Trait properties can be specified when running any integration with the CLI:
```
kamel run --trait kamelets.[key]=[value] --trait kamelets.[key2]=[value2] integration.groovy
```
The following configuration options are available:

[cols="2,1,5a"]
|===
|Property | Type | Description

| kamelets.enabled
| bool
| Can be used to enable or disable a trait. All traits share this common property.

| kamelets.auto
| bool
| Automatically inject all referenced Kamelets and their default configuration (enabled by default)

| kamelets.list
| string
| Comma separated list of Kamelet names to load into the current integration

|===

// End of autogenerated code - DO NOT EDIT! (configuration)
6 changes: 4 additions & 2 deletions pkg/apis/camel/v1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ type SourceSpec struct {
Interceptors []string `json:"interceptors,omitempty"`
// Type defines the kind of source described by this object
Type SourceType `json:"type,omitempty"`
// List of property names defined in the source (e.g. if type is "template")
PropertyNames []string `json:"property-names,omitempty"`
}

type SourceType string

const (
SourceTypeDefault SourceType = ""
SourceTypeKamelet SourceType = "kamelet"
SourceTypeDefault SourceType = ""
SourceTypeTemplate SourceType = "template"
)

// Language --
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/camel/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions pkg/apis/camel/v1alpha1/jsonschema_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ limitations under the License.

package v1alpha1

import "encoding/json"

// JSONSchemaProps is a JSON-Schema following Specification Draft 4 (http://json-schema.org/).
type JSONSchemaProps struct {
ID string `json:"id,omitempty" protobuf:"bytes,1,opt,name=id"`
Expand Down Expand Up @@ -59,7 +61,7 @@ type JSONSchemaProps struct {
// default is a default value for undefined object fields.
// Defaulting is a beta feature under the CustomResourceDefaulting feature gate.
// Defaulting requires spec.preserveUnknownFields to be false.
Default *JSON `json:"default,omitempty" protobuf:"bytes,8,opt,name=default"`
Default *json.RawMessage `json:"default,omitempty" protobuf:"bytes,8,opt,name=default"`
Maximum *float64 `json:"maximum,omitempty" protobuf:"bytes,9,opt,name=maximum"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty" protobuf:"bytes,10,opt,name=exclusiveMaximum"`
Minimum *float64 `json:"minimum,omitempty" protobuf:"bytes,11,opt,name=minimum"`
Expand All @@ -71,7 +73,7 @@ type JSONSchemaProps struct {
MinItems *int64 `json:"minItems,omitempty" protobuf:"bytes,17,opt,name=minItems"`
UniqueItems bool `json:"uniqueItems,omitempty" protobuf:"bytes,18,opt,name=uniqueItems"`
MultipleOf *float64 `json:"multipleOf,omitempty" protobuf:"bytes,19,opt,name=multipleOf"`
Enum []JSON `json:"enum,omitempty" protobuf:"bytes,20,rep,name=enum"`
Enum []*json.RawMessage `json:"enum,omitempty" protobuf:"bytes,20,rep,name=enum"`
MaxProperties *int64 `json:"maxProperties,omitempty" protobuf:"bytes,21,opt,name=maxProperties"`
MinProperties *int64 `json:"minProperties,omitempty" protobuf:"bytes,22,opt,name=minProperties"`
Required []string `json:"required,omitempty" protobuf:"bytes,23,rep,name=required"`
Expand All @@ -87,7 +89,7 @@ type JSONSchemaProps struct {
AdditionalItems *JSONSchemaPropsOrBool `json:"additionalItems,omitempty" protobuf:"bytes,33,opt,name=additionalItems"`
Definitions JSONSchemaDefinitions `json:"definitions,omitempty" protobuf:"bytes,34,opt,name=definitions"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" protobuf:"bytes,35,opt,name=externalDocs"`
Example *JSON `json:"example,omitempty" protobuf:"bytes,36,opt,name=example"`
Example *json.RawMessage `json:"example,omitempty" protobuf:"bytes,36,opt,name=example"`
Nullable bool `json:"nullable,omitempty" protobuf:"bytes,37,opt,name=nullable"`

// x-kubernetes-preserve-unknown-fields stops the API server
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/camel/v1alpha1/kamelet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ type AuthorizationSpec struct {
type KameletStatus struct {
Phase KameletPhase `json:"phase,omitempty"`
Conditions []KameletCondition `json:"conditions,omitempty"`
Properties []KameletProperty `json:"properties,omitempty"`
}

type KameletProperty struct {
Name string `json:"name,omitempty"`
Default string `json:"default,omitempty"`
}

// KameletCondition describes the state of a resource at a certain point.
Expand Down Expand Up @@ -95,11 +101,13 @@ const (
KameletPhaseReady KameletPhase = "Ready"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Kamelet is the Schema for the kamelets API
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// +genclient
// +kubebuilder:resource:path=kamelets,scope=Namespaced,shortName=kl,categories=kamel;camel
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=kamelets,scope=Namespaced
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="The Kamelet phase"
type Kamelet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
51 changes: 45 additions & 6 deletions pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions pkg/controller/kamelet/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package kamelet

import (
"encoding/json"
"fmt"
"sort"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/pkg/errors"
)

func updateStatus(kamelet *v1alpha1.Kamelet) (*v1alpha1.Kamelet, error) {
target := kamelet.DeepCopy()
target.Status.Phase = v1alpha1.KameletPhaseReady
if err := recomputeProperties(target); err != nil {
return nil, err
}
return target, nil
}

func recomputeProperties(kamelet *v1alpha1.Kamelet) error {
kamelet.Status.Properties = make([]v1alpha1.KameletProperty, 0, len(kamelet.Spec.Definition.Properties))
propSet := make(map[string]bool)
for k, v := range kamelet.Spec.Definition.Properties {
if propSet[k] {
continue
}
propSet[k] = true
defValue := ""
if v.Default != nil {
var val interface{}
if err := json.Unmarshal(*v.Default, &val); err != nil {
return errors.Wrapf(err, "cannot decode default value for property %q", k)
}
defValue = fmt.Sprintf("%v", val)
}
kamelet.Status.Properties = append(kamelet.Status.Properties, v1alpha1.KameletProperty{
Name: k,
Default: defValue,
})
}
sort.SliceStable(kamelet.Status.Properties, func(i, j int) bool {
pi := kamelet.Status.Properties[i].Name
pj := kamelet.Status.Properties[j].Name
return pi < pj
})
return nil
}
4 changes: 1 addition & 3 deletions pkg/controller/kamelet/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,5 @@ func (action *initializeAction) CanHandle(kamelet *v1alpha1.Kamelet) bool {
}

func (action *initializeAction) Handle(ctx context.Context, kamelet *v1alpha1.Kamelet) (*v1alpha1.Kamelet, error) {
target := kamelet.DeepCopy()
target.Status.Phase = v1alpha1.KameletPhaseReady
return target, nil
return updateStatus(kamelet)
}
3 changes: 1 addition & 2 deletions pkg/controller/kamelet/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ func (action *monitorAction) CanHandle(kamelet *v1alpha1.Kamelet) bool {
}

func (action *monitorAction) Handle(ctx context.Context, kamelet *v1alpha1.Kamelet) (*v1alpha1.Kamelet, error) {
// Doing nothing for now
return kamelet, nil
return updateStatus(kamelet)
}
9 changes: 2 additions & 7 deletions pkg/trait/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ import (
"fmt"
"sort"
"strconv"
"strings"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/envvar"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"

serving "knative.dev/serving/pkg/apis/serving/v1"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/envvar"
)

const (
Expand Down Expand Up @@ -195,8 +192,6 @@ func (t *containerTrait) configureContainer(e *Environment) error {
envvar.SetVal(&container.Env, "CAMEL_K_CONF", "/etc/camel/conf/application.properties")
envvar.SetVal(&container.Env, "CAMEL_K_CONF_D", "/etc/camel/conf.d")

// Configure sources
envvar.SetVal(&container.Env, "CAMEL_K_ROUTES", strings.Join(e.ComputeSourcesURI(), ","))
e.AddSourcesProperties()

t.configureResources(e, &container)
Expand Down
Loading

0 comments on commit 56d06e0

Please sign in to comment.