Skip to content

Commit

Permalink
chore(lint): Fix golang 1.22 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gansheer committed Jul 30, 2024
1 parent b476d4d commit fe8d296
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 35 deletions.
2 changes: 0 additions & 2 deletions pkg/apis/camel/v1/knative/types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kamelet_add_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/integration/build_kit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions pkg/install/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions pkg/trait/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/camel/camel_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions pkg/util/camel/camel_runtime_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/envvar/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/kubernetes/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit fe8d296

Please sign in to comment.