This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit cdd75b2e53a337af2cbfc454676464ab3716a98b Author: nicolaferraro <ni.ferr...@gmail.com> AuthorDate: Tue Dec 21 11:02:20 2021 +0100 Fix #1107: fix linter --- addons/keda/duck/v1alpha1/duck_types.go | 16 +++++++------- addons/keda/keda.go | 37 +++++++++++++++------------------ addons/keda/keda_test.go | 12 +++++------ docs/modules/traits/pages/keda.adoc | 4 ++-- pkg/client/serverside.go | 4 +++- pkg/cmd/kit_create.go | 2 +- pkg/cmd/run.go | 6 +++--- pkg/install/kamelets.go | 8 +------ pkg/resources/resources.go | 4 ++-- pkg/util/uri/uri.go | 2 +- pkg/util/util.go | 5 ++--- resources/traits.yaml | 4 ++-- 12 files changed, 48 insertions(+), 56 deletions(-) diff --git a/addons/keda/duck/v1alpha1/duck_types.go b/addons/keda/duck/v1alpha1/duck_types.go index 90a20bf..a278ead 100644 --- a/addons/keda/duck/v1alpha1/duck_types.go +++ b/addons/keda/duck/v1alpha1/duck_types.go @@ -27,7 +27,7 @@ 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"` @@ -35,7 +35,7 @@ type ScaledObject struct { 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 @@ -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 @@ -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. @@ -87,7 +87,7 @@ 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"` @@ -95,13 +95,13 @@ type TriggerAuthentication struct { 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"` @@ -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"` diff --git a/addons/keda/keda.go b/addons/keda/keda.go index c446ea3..0c972ab 100644 --- a/addons/keda/keda.go +++ b/addons/keda/keda.go @@ -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" @@ -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." ) @@ -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. // @@ -287,14 +286,12 @@ 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 @@ -302,7 +299,7 @@ func (t *kedaTrait) hackControllerReplicas(e *trait.Environment) error { 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, @@ -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) @@ -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 diff --git a/addons/keda/keda_test.go b/addons/keda/keda_test.go index ae49b4a..08a627e 100644 --- a/addons/keda/keda_test.go +++ b/addons/keda/keda_test.go @@ -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", }, @@ -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", }, diff --git a/docs/modules/traits/pages/keda.adoc b/docs/modules/traits/pages/keda.adoc index 1d5bbcb..340e150 100644 --- a/docs/modules/traits/pages/keda.adoc +++ b/docs/modules/traits/pages/keda.adoc @@ -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. diff --git a/pkg/client/serverside.go b/pkg/client/serverside.go index bca029d..50be4a7 100644 --- a/pkg/client/serverside.go +++ b/pkg/client/serverside.go @@ -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" ) @@ -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 @@ -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 diff --git a/pkg/cmd/kit_create.go b/pkg/cmd/kit_create.go index 4e3e7c2..4c16aba 100644 --- a/pkg/cmd/kit_create.go +++ b/pkg/cmd/kit_create.go @@ -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 diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 1819405..d2d260f 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -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...) @@ -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) @@ -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) diff --git a/pkg/install/kamelets.go b/pkg/install/kamelets.go index fc64e25..4ff4572 100644 --- a/pkg/install/kamelets.go +++ b/pkg/install/kamelets.go @@ -28,14 +28,12 @@ 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 ( @@ -43,10 +41,6 @@ const ( 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) diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go index 414e4d8..80a8c6d 100644 --- a/pkg/resources/resources.go +++ b/pkg/resources/resources.go @@ -555,9 +555,9 @@ var assets = func() http.FileSystem { "/traits.yaml": &vfsgen۰CompressedFileInfo{ name: "traits.yaml", modTime: time.Time{}, - uncompressedSize: 49560, + uncompressedSize: 49570, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfd\x73\x5b\xb9\x91\xe0\xef\xf3\x57\xa0\xb4\x57\x65\x49\x45\x52\x9e\xc9\x26\x3b\xa7\xbb\xd9\x94\xc6\x76\x12\xcd\xf8\x43\x67\x3b\xb3\x97\x9a\x9b\x0a\xc1\xf7\x9a\x24\xcc\x47\xe0\x05\xc0\x93\xcc\xdc\xde\xff\x7e\x85\xee\xc6\xc7\x7b\x24\x25\xca\xb6\x66\xa3\xad\xdd\x54\xed\x58\xd2\x03\xd0\x68\x34\xfa\xbb\x1b\xde\x4a\xe5\xdd\xf9\x57\x63\xa1\xe5\x1a\xce\x85\x9c\xcf\x95\x56\x7e\xf3\x95\x10\x6d\x23\xfd\xdc\xd8\xf5\xb9\x [...] + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfd\x73\x5b\xb9\x91\xe0\xef\xf3\x57\xa0\xb4\x57\x65\x49\x45\x52\x9e\xc9\x26\x3b\xa7\xbb\xd9\x94\xc6\x76\x12\xcd\xf8\x43\x67\x3b\xb3\x97\x9a\x9b\x0a\xc1\xf7\x9a\x24\xcc\x47\xe0\x05\xc0\x93\xcc\xdc\xde\xff\x7e\x85\xee\xc6\xc7\x7b\x24\x25\xca\xb6\x66\xa3\xad\xdd\x54\xed\x58\xd2\x03\xd0\x68\x34\xfa\xbb\x1b\xde\x4a\xe5\xdd\xf9\x57\x63\xa1\xe5\x1a\xce\x85\x9c\xcf\x95\x56\x7e\xf3\x95\x10\x6d\x23\xfd\xdc\xd8\xf5\xb9\x [...] }, } fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ diff --git a/pkg/util/uri/uri.go b/pkg/util/uri/uri.go index 210f169..79a9f86 100644 --- a/pkg/util/uri/uri.go +++ b/pkg/util/uri/uri.go @@ -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 { diff --git a/pkg/util/util.go b/pkg/util/util.go index 69fa4cb..05cdb80 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -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]) } } @@ -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{}: diff --git a/resources/traits.yaml b/resources/traits.yaml index 8eac6f4..f1a813f 100755 --- a/resources/traits.yaml +++ b/resources/traits.yaml @@ -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: