Skip to content

Commit

Permalink
Fix apache#1107: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Jan 10, 2022
1 parent 1edfde7 commit 6cc2aa6
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 56 deletions.
16 changes: 8 additions & 8 deletions addons/keda/duck/v1alpha1/duck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
// +genclient:noStatus
// +kubebuilder:object:root=true

// ScaledObject is a specification for a ScaledObject resource
// ScaledObject is a specification for a ScaledObject resource.
type ScaledObject struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ScaledObjectSpec `json:"spec"`
}

// ScaledObjectSpec is the spec for a ScaledObject resource
// ScaledObjectSpec is the spec for a ScaledObject resource.
type ScaledObjectSpec struct {
ScaleTargetRef *v1.ObjectReference `json:"scaleTargetRef"`
// +optional
Expand All @@ -52,7 +52,7 @@ type ScaledObjectSpec struct {
Triggers []ScaleTriggers `json:"triggers"`
}

// ScaleTriggers reference the scaler that will be used
// ScaleTriggers reference the scaler that will be used.
type ScaleTriggers struct {
Type string `json:"type"`
// +optional
Expand All @@ -65,7 +65,7 @@ type ScaleTriggers struct {
}

// ScaledObjectAuthRef points to the TriggerAuthentication or ClusterTriggerAuthentication object that
// is used to authenticate the scaler with the environment
// is used to authenticate the scaler with the environment.
type ScaledObjectAuthRef struct {
Name string `json:"name"`
// Kind of the resource being referred to. Defaults to TriggerAuthentication.
Expand All @@ -87,21 +87,21 @@ type ScaledObjectList struct {
// +genclient:noStatus
// +kubebuilder:object:root=true

// TriggerAuthentication defines how a trigger can authenticate
// TriggerAuthentication defines how a trigger can authenticate.
type TriggerAuthentication struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TriggerAuthenticationSpec `json:"spec"`
}

// TriggerAuthenticationSpec defines the various ways to authenticate
// TriggerAuthenticationSpec defines the various ways to authenticate.
type TriggerAuthenticationSpec struct {
// +optional
SecretTargetRef []AuthSecretTargetRef `json:"secretTargetRef,omitempty"`
}

// AuthSecretTargetRef is used to authenticate using a reference to a secret
// AuthSecretTargetRef is used to authenticate using a reference to a secret.
type AuthSecretTargetRef struct {
Parameter string `json:"parameter"`
Name string `json:"name"`
Expand All @@ -110,7 +110,7 @@ type AuthSecretTargetRef struct {

// +kubebuilder:object:root=true

// TriggerAuthenticationList contains a list of TriggerAuthentication
// TriggerAuthenticationList contains a list of TriggerAuthentication.
type TriggerAuthenticationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Expand Down
37 changes: 17 additions & 20 deletions addons/keda/keda.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

kedav1alpha1 "github.com/apache/camel-k/addons/keda/duck/v1alpha1"
camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
camelv1alpha1 "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/kamelet/repository"
"github.com/apache/camel-k/pkg/metadata"
Expand All @@ -46,18 +45,18 @@ import (
)

const (
// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata
// kameletURNMetadataPrefix allows binding Kamelet properties to KEDA metadata.
kameletURNMetadataPrefix = "urn:keda:metadata:"
// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options
// kameletURNAuthenticationPrefix allows binding Kamelet properties to KEDA authentication options.
kameletURNAuthenticationPrefix = "urn:keda:authentication:"
// kameletURNRequiredTag is used to mark properties required by KEDA
// kameletURNRequiredTag is used to mark properties required by KEDA.
kameletURNRequiredTag = "urn:keda:required"

// kameletAnnotationType indicates the scaler type associated to a Kamelet
// kameletAnnotationType indicates the scaler type associated to a Kamelet.
kameletAnnotationType = "camel.apache.org/keda.type"
// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties
// kameletAnnotationMetadataPrefix is used to define virtual metadata fields computed from Kamelet properties.
kameletAnnotationMetadataPrefix = "camel.apache.org/keda.metadata."
// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties
// kameletAnnotationAuthenticationPrefix is used to define virtual authentication fields computed from Kamelet properties.
kameletAnnotationAuthenticationPrefix = "camel.apache.org/keda.authentication."
)

Expand All @@ -66,9 +65,9 @@ const (
// via markers in the Kamelets.
//
// For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
// xref:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
// xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
// If you want to create Kamelets that contain KEDA metadata, refer to
// xref:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
// xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
//
// The KEDA trait is disabled by default.
//
Expand Down Expand Up @@ -287,22 +286,20 @@ func (t *kedaTrait) hackControllerReplicas(e *trait.Environment) error {
return err
}
}
} else {
if e.Integration.Spec.Replicas == nil {
one := int32(1)
e.Integration.Spec.Replicas = &one
// Update the Integration directly as the spec section is not merged by default
if err := e.Client.Update(e.Ctx, e.Integration); err != nil {
return err
}
} else if e.Integration.Spec.Replicas == nil {
one := int32(1)
e.Integration.Spec.Replicas = &one
// Update the Integration directly as the spec section is not merged by default
if err := e.Client.Update(e.Ctx, e.Integration); err != nil {
return err
}
}
return nil
}

func (t *kedaTrait) getTopControllerReference(e *trait.Environment) *v1.ObjectReference {
for _, o := range e.Integration.OwnerReferences {
if o.Kind == v1alpha1.KameletBindingKind && strings.HasPrefix(o.APIVersion, v1alpha1.SchemeGroupVersion.Group) {
if o.Kind == camelv1alpha1.KameletBindingKind && strings.HasPrefix(o.APIVersion, camelv1alpha1.SchemeGroupVersion.Group) {
return &v1.ObjectReference{
APIVersion: o.APIVersion,
Kind: o.Kind,
Expand Down Expand Up @@ -349,7 +346,7 @@ func (t *kedaTrait) populateTriggersFromKamelets(e *trait.Environment) error {
}

sortedKamelets := make([]string, 0, len(kameletURIs))
for kamelet, _ := range kameletURIs {
for kamelet := range kameletURIs {
sortedKamelets = append(sortedKamelets, kamelet)
}
sort.Strings(sortedKamelets)
Expand Down Expand Up @@ -495,7 +492,7 @@ func (t *kedaTrait) evaluateTemplateParameters(e *trait.Environment, kamelet *ca
return paramValues, authenticationParam, nil
}

func (t *kedaTrait) getKameletPropertyValue(e *trait.Environment, kamelet *v1alpha1.Kamelet, kameletURI, prop string) (string, error) {
func (t *kedaTrait) getKameletPropertyValue(e *trait.Environment, kamelet *camelv1alpha1.Kamelet, kameletURI, prop string) (string, error) {
// From top priority to lowest
if v := uri.GetQueryParameter(kameletURI, prop); v != "" {
return v, nil
Expand Down
12 changes: 6 additions & 6 deletions addons/keda/keda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ func TestKameletAutoDetection(t *testing.T) {
Spec: camelv1alpha1.KameletSpec{
Definition: &camelv1alpha1.JSONSchemaProps{
Properties: map[string]camelv1alpha1.JSONSchemaProp{
"a": camelv1alpha1.JSONSchemaProp{
"a": {
XDescriptors: []string{
"urn:keda:metadata:a",
},
},
"b": camelv1alpha1.JSONSchemaProp{
"b": {
XDescriptors: []string{
"urn:keda:metadata:bb",
},
},
"c": camelv1alpha1.JSONSchemaProp{
"c": {
XDescriptors: []string{
"urn:keda:authentication:cc",
},
Expand Down Expand Up @@ -248,17 +248,17 @@ func TestKameletBindingAutoDetection(t *testing.T) {
Spec: camelv1alpha1.KameletSpec{
Definition: &camelv1alpha1.JSONSchemaProps{
Properties: map[string]camelv1alpha1.JSONSchemaProp{
"a": camelv1alpha1.JSONSchemaProp{
"a": {
XDescriptors: []string{
"urn:keda:metadata:a",
},
},
"b": camelv1alpha1.JSONSchemaProp{
"b": {
XDescriptors: []string{
"urn:keda:metadata:bb",
},
},
"c": camelv1alpha1.JSONSchemaProp{
"c": {
XDescriptors: []string{
"urn:keda:authentication:cc",
},
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/traits/pages/keda.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ The trait can be either manually configured using the `triggers` option or autom
via markers in the Kamelets.

For information on how to use KEDA enabled Kamelets with the KEDA trait, refer to
xref:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the KEDA section in the Kamelets user guide].
If you want to create Kamelets that contain KEDA metadata, refer to
xref:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].
xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the KEDA section in the Kamelets development guide].

The KEDA trait is disabled by default.

Expand Down
4 changes: 3 additions & 1 deletion pkg/client/serverside.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pkg/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -49,6 +50,7 @@ func (c *defaultClient) ServerOrClientSideApplier() ServerOrClientSideApplier {
func (a *ServerOrClientSideApplier) Apply(ctx context.Context, object ctrl.Object) error {
once := false
var err error
// nolint: ifshort
needsRetry := false
a.tryServerSideApply.Do(func() {
once = true
Expand Down Expand Up @@ -80,7 +82,7 @@ func (a *ServerOrClientSideApplier) Apply(ctx context.Context, object ctrl.Objec
return nil
}

func (a *ServerOrClientSideApplier) serverSideApply(ctx context.Context, resource ctrl.Object) error {
func (a *ServerOrClientSideApplier) serverSideApply(ctx context.Context, resource runtime.Object) error {
target, err := patch.PositiveApplyPatch(resource)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/kit_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (command *kitCreateCommandOptions) run(_ *cobra.Command, args []string) err
return nil
}

func (*kitCreateCommandOptions) configureTraits(kit *v1.IntegrationKit, options []string, catalog *trait.Catalog) error {
func (*kitCreateCommandOptions) configureTraits(kit *v1.IntegrationKit, options []string, catalog trait.Finder) error {
traits, err := configureTraits(options, catalog)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (o *runCmdOptions) waitForIntegrationReady(cmd *cobra.Command, c client.Cli
return watch.HandleIntegrationStateChanges(o.Context, c, integration, handler)
}

func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sources []string, catalog *trait.Catalog) error {
func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sources []string, catalog trait.Finder) error {
// Let's watch all relevant files when in dev mode
var files []string
files = append(files, sources...)
Expand Down Expand Up @@ -480,7 +480,7 @@ func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sou
}

// nolint: gocyclo
func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.Client, sources []string, catalog *trait.Catalog) (*v1.Integration, error) {
func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.Client, sources []string, catalog trait.Finder) (*v1.Integration, error) {
namespace := o.Namespace
name := o.GetIntegrationName(sources)

Expand Down Expand Up @@ -738,7 +738,7 @@ func (o *runCmdOptions) GetIntegrationName(sources []string) string {
return name
}

func (o *runCmdOptions) configureTraits(integration *v1.Integration, options []string, catalog *trait.Catalog) error {
func (o *runCmdOptions) configureTraits(integration *v1.Integration, options []string, catalog trait.Finder) error {
// configure ServiceBinding trait
for _, sb := range o.Connects {
bindings := fmt.Sprintf("service-binding.services=%s", sb)
Expand Down
8 changes: 1 addition & 7 deletions pkg/install/kamelets.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,19 @@ import (

"golang.org/x/sync/errgroup"

"k8s.io/apimachinery/pkg/runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/defaults"
"github.com/apache/camel-k/pkg/util/kubernetes"
"k8s.io/apimachinery/pkg/runtime"
)

const (
kameletDirEnv = "KAMELET_CATALOG_DIR"
defaultKameletDir = "/kamelets/"
)

var (
log = logf.Log
)

// KameletCatalog installs the bundled Kamelets into the specified namespace.
func KameletCatalog(ctx context.Context, c client.Client, namespace string) error {
kameletDir := os.Getenv(kameletDirEnv)
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/resources.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/util/uri/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func GetQueryParameter(uri string, param string) string {
return res
}

// GetPathSegment returns the path segment of the URI corresponding to the given position (0 based), if present
// GetPathSegment returns the path segment of the URI corresponding to the given position (0 based), if present.
func GetPathSegment(uri string, pos int) string {
match := pathExtractorRegexp.FindStringSubmatch(uri)
if len(match) > 1 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ func ConfigTreePropertySplit(property string) []string {
if len(cur) > 0 {
tmp = append(tmp, cur)
}
for i := len(tmp) - 1; i >= 0; i = i - 1 {
for i := len(tmp) - 1; i >= 0; i-- {
res = append(res, tmp[i])
}
}
Expand All @@ -895,9 +895,8 @@ func NavigateConfigTree(current interface{}, nodes []string) (interface{}, error
if isSlice(1) {
slice := make([]interface{}, 0)
return &slice
} else {
return make(map[string]interface{})
}
return make(map[string]interface{})
}
switch c := current.(type) {
case map[string]interface{}:
Expand Down
4 changes: 2 additions & 2 deletions resources/traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,9 @@ traits:
description: The KEDA trait can be used for automatic integration with KEDA autoscalers.
The trait can be either manually configured using the `triggers` option or automatically
configured via markers in the Kamelets. For information on how to use KEDA enabled
Kamelets with the KEDA trait, refer to xref:kamelets/kamelets-user.adoc#kamelet-keda-user[the
Kamelets with the KEDA trait, refer to xref:ROOT:kamelets/kamelets-user.adoc#kamelet-keda-user[the
KEDA section in the Kamelets user guide]. If you want to create Kamelets that
contain KEDA metadata, refer to xref:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the
contain KEDA metadata, refer to xref:ROOT:kamelets/kamelets-dev.adoc#kamelet-keda-dev[the
KEDA section in the Kamelets development guide]. The KEDA trait is disabled by
default.
properties:
Expand Down

0 comments on commit 6cc2aa6

Please sign in to comment.