diff --git a/pkg/apis/camel/v1/knative/types_support.go b/pkg/apis/camel/v1/knative/types_support.go index d4ebf4b393..8ae5b87f2d 100644 --- a/pkg/apis/camel/v1/knative/types_support.go +++ b/pkg/apis/camel/v1/knative/types_support.go @@ -45,7 +45,6 @@ func BuildCamelServiceDefinition(name string, endpointKind CamelEndpointKind, se // SetSinkBinding marks one of the service as SinkBinding. func (env *CamelEnvironment) SetSinkBinding(name string, endpointKind CamelEndpointKind, serviceType CamelServiceType, apiVersion, kind string) { for i, svc := range env.Services { - svc := svc if svc.Name == name && svc.Metadata[CamelMetaEndpointKind] == string(endpointKind) && svc.ServiceType == serviceType && @@ -107,7 +106,6 @@ func (env *CamelEnvironment) ContainsService(name string, endpointKind CamelEndp // FindService -- . func (env *CamelEnvironment) FindService(name string, endpointKind CamelEndpointKind, serviceType CamelServiceType, apiVersion, kind string) *CamelServiceDefinition { for _, svc := range env.Services { - svc := svc if svc.Name == name && svc.Metadata[CamelMetaEndpointKind] == string(endpointKind) && svc.ServiceType == serviceType && diff --git a/pkg/builder/steps.go b/pkg/builder/steps.go index 245a389c2e..a518205260 100644 --- a/pkg/builder/steps.go +++ b/pkg/builder/steps.go @@ -81,7 +81,7 @@ func registerSteps(steps interface{}) { v := reflect.ValueOf(steps) t := reflect.TypeOf(steps) - for i := 0; i < v.NumField(); i++ { + for i := range v.NumField() { field := t.Field(i) if step, ok := v.Field(i).Interface().(Step); ok { id := t.PkgPath() + "/" + field.Name diff --git a/pkg/cmd/delete.go b/pkg/cmd/delete.go index acf480b363..326fab4b34 100644 --- a/pkg/cmd/delete.go +++ b/pkg/cmd/delete.go @@ -107,8 +107,8 @@ func (command *deleteCmdOptions) run(cmd *cobra.Command, args []string) error { if err != nil { return err } - for _, integration := range integrationList.Items { - integration := integration // pin + for i := range integrationList.Items { + integration := integrationList.Items[i] err := deleteIntegration(command.Context, cmd, c, &integration) if err != nil { return err diff --git a/pkg/cmd/kamelet_add_repo.go b/pkg/cmd/kamelet_add_repo.go index ceeb4baa86..f217b01a8e 100644 --- a/pkg/cmd/kamelet_add_repo.go +++ b/pkg/cmd/kamelet_add_repo.go @@ -125,8 +125,8 @@ func (o *kameletUpdateRepoCommandOptions) findIntegrationPlatform(cmd *cobra.Com if err != nil { return nil, err } - for _, p := range platforms.Items { - p := p // pin + for i := range platforms.Items { + p := platforms.Items[i] if platformutil.IsActive(&p) { return &p, nil } diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go index 736b13598f..531738be88 100644 --- a/pkg/cmd/uninstall.go +++ b/pkg/cmd/uninstall.go @@ -230,7 +230,7 @@ func (o *uninstallCmdOptions) uninstallClusterWideResources(ctx context.Context, if k8serrors.IsForbidden(err) { // Let's print a warning message and continue fmt.Fprintln(cmd.ErrOrStderr(), "Current user is not authorized to remove the operator ServiceAccount from the cluster role bindings") - } else if err != nil { + } else { return err } } diff --git a/pkg/cmd/util.go b/pkg/cmd/util.go index 9afc86c1ef..a30e2c0b86 100644 --- a/pkg/cmd/util.go +++ b/pkg/cmd/util.go @@ -219,7 +219,7 @@ func clone(dst interface{}, src interface{}) error { func fieldByMapstructureTagName(target reflect.Value, tagName string) (reflect.StructField, bool) { pl := p.NewClient() - for i := 0; i < target.Type().NumField(); i++ { + for i := range target.Type().NumField() { f := target.Type().Field(i) tag, ok := f.Tag.Lookup(MapstructureTagName) diff --git a/pkg/cmd/util_config.go b/pkg/cmd/util_config.go index ce4a5d52fa..fd40eaf994 100644 --- a/pkg/cmd/util_config.go +++ b/pkg/cmd/util_config.go @@ -98,7 +98,7 @@ func (cfg *Config) Update(cmd *cobra.Command, nodeID string, data interface{}, c pl := p.NewClient() val := reflect.ValueOf(data).Elem() - for i := 0; i < val.NumField(); i++ { + for i := range val.NumField() { field := val.Type().Field(i) if !field.Anonymous { if ktag, ok := field.Tag.Lookup(KamelTagName); ok { diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go index af2d164ae2..1ec95bac61 100644 --- a/pkg/controller/integration/build_kit.go +++ b/pkg/controller/integration/build_kit.go @@ -92,9 +92,8 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr integration.Name, "namespace", integration.Namespace) var integrationKit *v1.IntegrationKit kits: - for _, kit := range env.IntegrationKits { - kit := kit - + for j := range env.IntegrationKits { + kit := env.IntegrationKits[j] for i := range existingKits { k := &existingKits[i] diff --git a/pkg/install/operator.go b/pkg/install/operator.go index f6075bdae2..6f0ebd8ac6 100644 --- a/pkg/install/operator.go +++ b/pkg/install/operator.go @@ -131,7 +131,7 @@ func OperatorOrCollect(ctx context.Context, cmd *cobra.Command, c client.Client, if err != nil { fmt.Fprintln(cmd.ErrOrStderr(), "Warning: could not parse the configured resources requests!") } - for i := 0; i < len(d.Spec.Template.Spec.Containers); i++ { + for i := range len(d.Spec.Template.Spec.Containers) { d.Spec.Template.Spec.Containers[i].Resources = resourceReq } } @@ -145,7 +145,7 @@ func OperatorOrCollect(ctx context.Context, cmd *cobra.Command, c client.Client, if err != nil { fmt.Fprintln(cmd.ErrOrStderr(), "Warning: could not parse environment variables!") } - for i := 0; i < len(d.Spec.Template.Spec.Containers); i++ { + for i := range len(d.Spec.Template.Spec.Containers) { for _, envVar := range envVars { envvar.SetVar(&d.Spec.Template.Spec.Containers[i].Env, envVar) } diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go index 470e2aec3c..3f9b8ba559 100644 --- a/pkg/platform/platform.go +++ b/pkg/platform/platform.go @@ -154,8 +154,8 @@ func findLocal(ctx context.Context, c k8sclient.Reader, namespace string) (*v1.I } var fallback *v1.IntegrationPlatform - for _, platform := range lst.Items { - platform := platform // pin + for i := range lst.Items { + platform := lst.Items[i] if IsActive(&platform) { log.Debugf("Found active integration platform %s in namespace %s", platform.Name, namespace) return &platform, nil diff --git a/pkg/trait/util.go b/pkg/trait/util.go index 94581dad47..f81dfa5ed4 100644 --- a/pkg/trait/util.go +++ b/pkg/trait/util.go @@ -79,8 +79,6 @@ func collectConfigurationValues(configurationType string, configurable ...v1.Con result := sets.NewSet() for _, c := range configurable { - c := c - if c == nil || reflect.ValueOf(c).IsNil() { continue } @@ -106,8 +104,6 @@ func collectConfigurations(configurationType string, configurable ...v1.Configur var result []map[string]string for _, c := range configurable { - c := c - if c == nil || reflect.ValueOf(c).IsNil() { continue } @@ -133,8 +129,6 @@ func collectConfigurationPairs(configurationType string, configurable ...v1.Conf result := make([]variable, 0) for _, c := range configurable { - c := c - if c == nil || reflect.ValueOf(c).IsNil() { continue } diff --git a/pkg/util/camel/camel_dependencies.go b/pkg/util/camel/camel_dependencies.go index b979335b83..e1501fd186 100644 --- a/pkg/util/camel/camel_dependencies.go +++ b/pkg/util/camel/camel_dependencies.go @@ -345,7 +345,7 @@ func postProcessDependencies(project *maven.Project, catalog *RuntimeCatalog) { // SanitizeIntegrationDependencies --. func SanitizeIntegrationDependencies(dependencies []maven.Dependency) error { - for i := 0; i < len(dependencies); i++ { + for i := range len(dependencies) { dep := dependencies[i] // It may be externalized into runtime provider specific steps diff --git a/pkg/util/camel/camel_runtime_catalog.go b/pkg/util/camel/camel_runtime_catalog.go index 2681e4918e..b98103fcc9 100644 --- a/pkg/util/camel/camel_runtime_catalog.go +++ b/pkg/util/camel/camel_runtime_catalog.go @@ -37,8 +37,6 @@ func NewRuntimeCatalog(cat v1.CamelCatalog) *RuntimeCatalog { for id, artifact := range catalog.Artifacts { for _, scheme := range artifact.Schemes { - scheme := scheme - // In case of duplicate only, choose the "org.apache.camel.quarkus" artifact (if present). // Workaround for https://github.com/apache/camel-k/v2-runtime/issues/592 if _, duplicate := catalog.artifactByScheme[scheme.ID]; duplicate { @@ -51,7 +49,6 @@ func NewRuntimeCatalog(cat v1.CamelCatalog) *RuntimeCatalog { catalog.schemesByID[scheme.ID] = scheme } for _, dataFormat := range artifact.DataFormats { - dataFormat := dataFormat catalog.artifactByDataFormat[dataFormat] = id } for _, language := range artifact.Languages { diff --git a/pkg/util/envvar/envvar.go b/pkg/util/envvar/envvar.go index f22cee8070..0d017d391a 100644 --- a/pkg/util/envvar/envvar.go +++ b/pkg/util/envvar/envvar.go @@ -21,7 +21,7 @@ import corev1 "k8s.io/api/core/v1" // Get --. func Get(vars []corev1.EnvVar, name string) *corev1.EnvVar { - for i := 0; i < len(vars); i++ { + for i := range len(vars) { if vars[i].Name == name { return &vars[i] } diff --git a/pkg/util/kubernetes/resolver.go b/pkg/util/kubernetes/resolver.go index e86d24db17..8c61849c13 100644 --- a/pkg/util/kubernetes/resolver.go +++ b/pkg/util/kubernetes/resolver.go @@ -30,7 +30,7 @@ import ( // ResolveSources --. func ResolveSources(elements []v1.SourceSpec, mapLookup func(string) (*corev1.ConfigMap, error)) ([]v1.SourceSpec, error) { - for i := 0; i < len(elements); i++ { + for i := range len(elements) { r := &elements[i] if err := Resolve(&r.DataSpec, mapLookup); err != nil { diff --git a/pkg/util/patch/patch.go b/pkg/util/patch/patch.go index b7ad290a53..cab3ec7fe9 100644 --- a/pkg/util/patch/patch.go +++ b/pkg/util/patch/patch.go @@ -92,7 +92,7 @@ func removeNilValues(v reflect.Value, parent reflect.Value) { } switch v.Kind() { case reflect.Array, reflect.Slice: - for i := 0; i < v.Len(); i++ { + for i := range v.Len() { removeNilValues(v.Index(i), v) } case reflect.Map: diff --git a/pkg/util/util.go b/pkg/util/util.go index 2d72de0d1b..4842fbceca 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -117,7 +117,7 @@ func StringSliceJoin(slices ...[]string) []string { } func StringSliceContains(slice []string, items []string) bool { - for i := 0; i < len(items); i++ { + for i := range len(items) { if !StringSliceExists(slice, items[i]) { return false } @@ -127,7 +127,7 @@ func StringSliceContains(slice []string, items []string) bool { } func StringSliceExists(slice []string, item string) bool { - for i := 0; i < len(slice); i++ { + for i := range len(slice) { if slice[i] == item { return true } @@ -137,7 +137,7 @@ func StringSliceExists(slice []string, item string) bool { } func StringContainsPrefix(slice []string, prefix string) bool { - for i := 0; i < len(slice); i++ { + for i := range len(slice) { if strings.HasPrefix(slice[i], prefix) { return true } @@ -147,8 +147,8 @@ func StringContainsPrefix(slice []string, prefix string) bool { } func StringSliceContainsAnyOf(slice []string, items ...string) bool { - for i := 0; i < len(slice); i++ { - for j := 0; j < len(items); j++ { + for i := range len(slice) { + for j := range len(items) { if strings.Contains(slice[i], items[j]) { return true }