Skip to content

Commit

Permalink
Fix #1014: fix linter and missing documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Nov 23, 2019
1 parent 6847b6e commit 04a24dc
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 84 deletions.
12 changes: 5 additions & 7 deletions cmd/util/doc-gen/generators/traitdocgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
tagTrait = "+camel-k:trait"

adocCommonMarkerStart = "// Start of autogenerated code - DO NOT EDIT!"
adocCommonMarkerEnd = "// End of autogenerated code - DO NOT EDIT!"
adocCommonMarkerEnd = "// End of autogenerated code - DO NOT EDIT!"

adocDescriptionMarkerStart = adocCommonMarkerStart + " (description)"
adocDescriptionMarkerEnd = adocCommonMarkerEnd + " (description)"
Expand Down Expand Up @@ -75,7 +75,7 @@ func NewTraitDocGen(arguments *args.GeneratorArgs) generator.Generator {
}

func (g *traitDocGen) Filename() string {
return "zz_doc_gen.go"
return "zz_generated_doc.go"
}

func (g *traitDocGen) Filter(context *generator.Context, t *types.Type) bool {
Expand All @@ -102,7 +102,7 @@ func (g *traitDocGen) GenerateType(context *generator.Context, t *types.Type, ou
}
defer file.Close()

writeTitle(t, traitID, &content)
writeTitle(traitID, &content)
writeDescription(t, traitID, &content)
writeFields(t, traitID, &content)

Expand Down Expand Up @@ -177,7 +177,7 @@ func traitNameFromFile(file string) string {
return name
}

func writeTitle(t *types.Type, traitID string, content *[]string) {
func writeTitle(traitID string, content *[]string) {
res := append([]string(nil), *content...)
for _, s := range res {
if strings.HasPrefix(s, "= ") {
Expand All @@ -193,9 +193,7 @@ func writeDescription(t *types.Type, traitID string, content *[]string) {
pre, post := split(*content, adocDescriptionMarkerStart, adocDescriptionMarkerEnd)
res := append([]string(nil), pre...)
res = append(res, adocDescriptionMarkerStart)
for _, l := range filterOutTagsAndComments(t.CommentLines) {
res = append(res, l)
}
res = append(res, filterOutTagsAndComments(t.CommentLines)...)
profiles := strings.Join(determineProfiles(traitID), ", ")
res = append(res, "", fmt.Sprintf("This trait is available in the following profiles: **%s**.", profiles))
if isPlatformTrait(traitID) {
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 @@ -12,6 +12,7 @@
** xref:configuration/configmap-secret.adoc[ConfigMap/Secret]
* xref:traits/traits.adoc[Traits]
// Start of autogenerated code - DO NOT EDIT! (trait-nav)
** xref:traits/affinity.adoc[Affinity]
** xref:traits/builder.adoc[Builder]
** xref:traits/camel.adoc[Camel]
** xref:traits/classpath.adoc[Classpath]
Expand Down
54 changes: 54 additions & 0 deletions docs/modules/ROOT/pages/traits/affinity.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
= Affinity Trait

// Start of autogenerated code - DO NOT EDIT! (description)
Allows to constrain which nodes the integration pod(s) are eligible to be scheduled on, based on labels on the node,
or with inter-pod affinity and anti-affinity, based on labels on pods that are already running on the nodes.

It’s disabled by default.


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

// 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 affinity.[key]=[value] integration.groovy
```
The following configuration options are available:

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

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

| affinity.pod-affinity
| bool
| Always co-locates multiple replicas of the integration in the same node (default *false*).

| affinity.pod-anti-affinity
| bool
| Never co-locates multiple replicas of the integration in the same node (default *false*).

| affinity.node-affinity-labels
| string
| Defines a set of nodes the integration pod(s) are eligible to be scheduled on, based on labels on the node.

| affinity.pod-affinity-labels
| string
| Defines a set of pods (namely those matching the label selector, relative to the given namespace) that the
integration pod(s) should be co-located with.

| affinity.pod-anti-affinity-labels
| string
| Defines a set of pods (namely those matching the label selector, relative to the given namespace) that the
integration pod(s) should not be co-located with.

|===

// End of autogenerated code - DO NOT EDIT! (configuration)
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/traits/traits.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ A trait may have additional properties that can be configured by the end user.
See the trait description pages for more information on a specific trait:

// Start of autogenerated code - DO NOT EDIT! (trait-list)
* xref:traits/affinity.adoc[Affinity Trait]
* xref:traits/builder.adoc[Builder Trait]
* xref:traits/camel.adoc[Camel Trait]
* xref:traits/classpath.adoc[Classpath Trait]
Expand Down
22 changes: 17 additions & 5 deletions pkg/trait/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
)

// Allows to constrain which nodes the integration pod(s) are eligible to be scheduled on, based on labels on the node,
// or with inter-pod affinity and anti-affinity, based on labels on pods that are already running on the nodes.
//
//It’s disabled by default.
//
// +camel-k:trait=affinity
type affinityTrait struct {
BaseTrait `property:",squash"`

PodAffinity bool `property:"pod-affinity"`
PodAntiAffinity bool `property:"pod-anti-affinity"`
NodeAffinityLabels string `property:"node-affinity-labels"`
PodAffinityLabels string `property:"pod-affinity-labels"`
// Always co-locates multiple replicas of the integration in the same node (default *false*).
PodAffinity bool `property:"pod-affinity"`
// Never co-locates multiple replicas of the integration in the same node (default *false*).
PodAntiAffinity bool `property:"pod-anti-affinity"`
// Defines a set of nodes the integration pod(s) are eligible to be scheduled on, based on labels on the node.
NodeAffinityLabels string `property:"node-affinity-labels"`
// Defines a set of pods (namely those matching the label selector, relative to the given namespace) that the
// integration pod(s) should be co-located with.
PodAffinityLabels string `property:"pod-affinity-labels"`
// Defines a set of pods (namely those matching the label selector, relative to the given namespace) that the
// integration pod(s) should not be co-located with.
PodAntiAffinityLabels string `property:"pod-anti-affinity-labels"`
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/trait/camel.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
//
// +camel-k:trait=camel
type camelTrait struct {
BaseTrait `property:",squash"`
BaseTrait `property:",squash"`
// The camel version to use for the integration. It overrides the default version set in the Integration Platform.
Version string `property:"version"`
Version string `property:"version"`
// The camel-k-runtime version to use for the integration. It overrides the default version set in the Integration Platform.
RuntimeVersion string `property:"runtime-version"`
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/trait/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ const (
type containerTrait struct {
BaseTrait `property:",squash"`

Auto *bool `property:"auto"`
Auto *bool `property:"auto"`
// The minimum amount of CPU required.
RequestCPU string `property:"request-cpu"`
RequestCPU string `property:"request-cpu"`
// The minimum amount of memory required.
RequestMemory string `property:"request-memory"`
RequestMemory string `property:"request-memory"`
// The maximum amount of CPU required.
LimitCPU string `property:"limit-cpu"`
LimitCPU string `property:"limit-cpu"`
// The maximum amount of memory required.
LimitMemory string `property:"limit-memory"`
LimitMemory string `property:"limit-memory"`
// Can be used to enable/disable exposure via kubernetes Service.
Expose *bool `property:"expose"`
Expose *bool `property:"expose"`
// To configure a different port exposed by the container (default `8080`).
Port int `property:"port"`
Port int `property:"port"`
// To configure a different port name for the port exposed by the container (default `http`).
PortName string `property:"port-name"`
PortName string `property:"port-name"`
// To configure under which service port the container port is to be exposed (default `80`).
ServicePort int `property:"service-port"`
ServicePort int `property:"service-port"`
// To configure under which service port name the container port is to be exposed (default `http`).
ServicePortName string `property:"service-port-name"`
// The main container name. It's named `integration` by default.
Name string `property:"name"`
Name string `property:"name"`
}

func newContainerTrait() *containerTrait {
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package trait
type deployerTrait struct {
BaseTrait `property:",squash"`
// Allows to explicitly select the desired deployment kind between `deployment` or `knative-service` when creating the resources for running the integration.
Kind string `property:"kind"`
Kind string `property:"kind"`
}

func newDeployerTrait() *deployerTrait {
Expand Down
3 changes: 2 additions & 1 deletion pkg/trait/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const (

func newEnvironmentTrait() *environmentTrait {
return &environmentTrait{
BaseTrait: newBaseTrait("environment"),
BaseTrait: newBaseTrait("environment"),
// Enable injection of NAMESPACE and POD_NAME environment variables.
ContainerMeta: true,
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/trait/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import (
type ingressTrait struct {
BaseTrait `property:",squash"`
// **Required**. To configure the host exposed by the ingress.
Host string `property:"host"`
Host string `property:"host"`
// To automatically add an ingress whenever the integration uses a HTTP endpoint consumer.
Auto *bool `property:"auto"`
Auto *bool `property:"auto"`
}

func newIngressTrait() *ingressTrait {
Expand Down
4 changes: 2 additions & 2 deletions pkg/trait/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
type istioTrait struct {
BaseTrait `property:",squash"`
// Configures a (comma-separated) list of CIDR subnets that should not be intercepted by the Istio proxy (`10.0.0.0/8,172.16.0.0/12,192.168.0.0/16` by default).
Allow string `property:"allow"`
Allow string `property:"allow"`
// Forces the value for labels `sidecar.istio.io/inject`. By default the label is set to `true` on deployment and not set on Knative Service.
Inject *bool `property:"inject"`
Inject *bool `property:"inject"`
}

const (
Expand Down
20 changes: 10 additions & 10 deletions pkg/trait/jolokia.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ type jolokiaTrait struct {
// The PEM encoded CA certification file path, used to verify client certificates,
// applicable when `protocol` is `https` and `use-ssl-client-authentication` is `true`
// (default `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt` for OpenShift).
CaCert *string `property:"ca-cert"`
CaCert *string `property:"ca-cert"`
// The principal which must be given in a client certificate to allow access to the Jolokia endpoint,
// applicable when `protocol` is `https` and `use-ssl-client-authentication` is `true`
// (default `clientPrincipal=cn=system:master-proxy` for OpenShift).
ClientPrincipal *string `property:"client-principal"`
ClientPrincipal *string `property:"client-principal"`
// Listen for multicast requests (default `false`)
DiscoveryEnabled *bool `property:"discovery-enabled"`
DiscoveryEnabled *bool `property:"discovery-enabled"`
// Mandate the client certificate contains a client flag in the extended key usage section,
// applicable when `protocol` is `https` and `use-ssl-client-authentication` is `true`
// (default `true` for OpenShift).
ExtendedClientCheck *bool `property:"extended-client-check"`
ExtendedClientCheck *bool `property:"extended-client-check"`
// The Host address to which the Jolokia agent should bind to. If `"\*"` or `"0.0.0.0"` is given,
// the servers binds to every network interface (default `"*"`).
Host *string `property:"host"`
Host *string `property:"host"`
// The password used for authentication, applicable when the `user` option is set.
Password *string `property:"password"`
Password *string `property:"password"`
// The Jolokia endpoint port (default `8778`).
Port int `property:"port"`
Port int `property:"port"`
// The protocol to use, either `http` or `https` (default `https` for OpenShift)
Protocol *string `property:"protocol"`
Protocol *string `property:"protocol"`
// The user to be used for authentication
User *string `property:"user"`
User *string `property:"user"`
// Whether client certificates should be used for authentication (default `true` for OpenShift).
UseSslClientAuthentication *bool `property:"use-ssl-client-authentication"`
UseSslClientAuthentication *bool `property:"use-ssl-client-authentication"`

// A comma-separated list of additional Jolokia options as defined
// in https://jolokia.org/reference/html/agents.html#agent-jvm-config[JVM agent configuration options],
Expand Down
22 changes: 11 additions & 11 deletions pkg/trait/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,35 @@ import (
//
// +camel-k:trait=knative
type knativeTrait struct {
BaseTrait `property:",squash"`
BaseTrait `property:",squash"`
// Can be used to inject a Knative complete configuration in JSON format.
Configuration string `property:"configuration"`
Configuration string `property:"configuration"`
// Comma-separated list of channels used as source of integration routes.
// Can contain simple channel names or full Camel URIs.
ChannelSources string `property:"channel-sources"`
ChannelSources string `property:"channel-sources"`
// Comma-separated list of channels used as destination of integration routes.
// Can contain simple channel names or full Camel URIs.
ChannelSinks string `property:"channel-sinks"`
ChannelSinks string `property:"channel-sinks"`
// Comma-separated list of channels used as source of integration routes.
EndpointSources string `property:"endpoint-sources"`
EndpointSources string `property:"endpoint-sources"`
// Comma-separated list of endpoints used as destination of integration routes.
// Can contain simple endpoint names or full Camel URIs.
EndpointSinks string `property:"endpoint-sinks"`
EndpointSinks string `property:"endpoint-sinks"`
// Comma-separated list of event types that the integration will be subscribed to.
// Can contain simple event types or full Camel URIs (to use a specific broker different from "default").
EventSources string `property:"event-sources"`
EventSources string `property:"event-sources"`
// Comma-separated list of event types that the integration will produce.
// Can contain simple event types or full Camel URIs (to use a specific broker).
EventSinks string `property:"event-sinks"`
EventSinks string `property:"event-sinks"`
// Enables filtering on events based on the header "ce-knativehistory". Since this is an experimental header
// that can be removed in a future version of Knative, filtering is enabled only when the integration is
// listening from more than 1 channel.
FilterSourceChannels *bool `property:"filter-source-channels"`
FilterSourceChannels *bool `property:"filter-source-channels"`
// The Knative 0.8 compatibility mode will check the installed version of Knative and
// use resource versions compatible with Knative 0.8 if found on the cluster.
Knative08CompatMode *bool `property:"knative-08-compat-mode"`
Knative08CompatMode *bool `property:"knative-08-compat-mode"`
// Enable automatic discovery of all trait properties.
Auto *bool `property:"auto"`
Auto *bool `property:"auto"`
}

const (
Expand Down
14 changes: 7 additions & 7 deletions pkg/trait/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,31 @@ type knativeServiceTrait struct {
// Configures the Knative autoscaling class property (e.g. to set `hpa.autoscaling.knative.dev` or `kpa.autoscaling.knative.dev` autoscaling).
//
// Refer to the Knative documentation for more information.
Class string `property:"autoscaling-class"`
Class string `property:"autoscaling-class"`
// Configures the Knative autoscaling metric property (e.g. to set `concurrency` based or `cpu` based autoscaling).
//
// Refer to the Knative documentation for more information.
Metric string `property:"autoscaling-metric"`
Metric string `property:"autoscaling-metric"`
// Sets the allowed concurrency level or CPU percentage (depending on the autoscaling metric) for each Pod.
//
// Refer to the Knative documentation for more information.
Target *int `property:"autoscaling-target"`
Target *int `property:"autoscaling-target"`
// The minimum number of Pods that should be running at any time for the integration. It's **zero** by default, meaning that
// the integration is scaled down to zero when not used for a configured amount of time.
//
// Refer to the Knative documentation for more information.
MinScale *int `property:"min-scale"`
MinScale *int `property:"min-scale"`
// An upper bound for the number of Pods that can be running in parallel for the integration.
// Knative has its own cap value that depends on the installation.
//
// Refer to the Knative documentation for more information.
MaxScale *int `property:"max-scale"`
MaxScale *int `property:"max-scale"`
// Automatically deploy the integration as Knative service when all conditions hold:
//
// * Integration is using the Knative profile
// * All routes are either starting from a HTTP based consumer or a passive consumer (e.g. `direct` is a passive consumer)
Auto *bool `property:"auto"`
deployer deployerTrait
Auto *bool `property:"auto"`
deployer deployerTrait
}

func newKnativeServiceTrait() *knativeServiceTrait {
Expand Down
3 changes: 1 addition & 2 deletions pkg/trait/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ownerTrait struct {
// The annotations to be transferred (A comma-separated list of label keys)
TargetAnnotations string `property:"target-annotations"`
// The labels to be transferred (A comma-separated list of label keys)
TargetLabels string `property:"target-labels"`
TargetLabels string `property:"target-labels"`
}

func newOwnerTrait() *ownerTrait {
Expand Down Expand Up @@ -112,7 +112,6 @@ func (t *ownerTrait) IsPlatformTrait() bool {
return true
}


func (t *ownerTrait) propagateLabelAndAnnotations(res metav1.Object, targetLabels map[string]string, targetAnnotations map[string]string) {
// Transfer annotations
annotations := res.GetAnnotations()
Expand Down
Loading

0 comments on commit 04a24dc

Please sign in to comment.