Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #2324: Use golangci-lint for header checks #2353: Remove space between // and nolint #2943

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ jobs:
- name: Run golangci-lint
run: make golangci-lint

headers:
name: License Headers
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Check License Headers
uses: kt3k/license_checker@d12a6d90c58e30fefed09f2c4d03ba57f4c673a8

licenses:
name: Dependency Licenses
runs-on: ubuntu-latest
Expand Down
27 changes: 23 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ linters-settings:
godot:
exclude:
- ^\s*\+
goheader:
template: |-
SPDX-License-Identifier: Apache-2.0

Copyright Contributors to the Submariner project.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
govet:
enable:
- fieldalignment
Expand Down Expand Up @@ -41,7 +58,6 @@ linters:
- bodyclose
- contextcheck
# - cyclop # This is equivalent to gocyclo
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -68,7 +84,7 @@ linters:
# - godox # Let's not forbid inline TODOs, FIXMEs et al
- gofmt
- gofumpt
# - goheader # We do license header linting another way
- goheader
- goimports
# - golint # Deprecated since v1.41.0
# - gomnd # It doesn't seem useful in general to enforce constants for all numeric values
Expand Down Expand Up @@ -104,7 +120,6 @@ linters:
# - scopelint # Deprecated since v1.39.0
# - sqlclosecheck # We don't use SQL
- staticcheck
- structcheck
- stylecheck
# - tagliatelle # Inconsistent with stylecheck and not as good
# - tenv # Not relevant for our Ginkgo UTs
Expand All @@ -115,7 +130,6 @@ linters:
- unconvert
- unparam
- unused
- varcheck
# - varnamelen # It doesn't seem necessary to enforce a minimum variable name length
- wastedassign
- whitespace
Expand Down Expand Up @@ -171,3 +185,8 @@ issues:
- gochecknoinits
- goerr113
- wrapcheck

# Ignore header linting for files copied from the Operator SDK
- path: pkg/metrics/service-monitor.go
linters:
- goheader
30 changes: 0 additions & 30 deletions .licenserc.json

This file was deleted.

2 changes: 1 addition & 1 deletion api/v1alpha1/broker_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,9 +16,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=submariner.io

// Package v1alpha1 contains API Schema definitions for the v1alpha1 API group
package v1alpha1

import (
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/servicediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/submariner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions controllers/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -37,7 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

func DaemonSet(owner metav1.Object, daemonSet *appsv1.DaemonSet, reqLogger logr.Logger,
func DaemonSet(ctx context.Context, owner metav1.Object, daemonSet *appsv1.DaemonSet, reqLogger logr.Logger,
client controllerClient.Client, scheme *runtime.Scheme,
) (*appsv1.DaemonSet, error) {
var err error
Expand All @@ -54,7 +54,7 @@ func DaemonSet(owner metav1.Object, daemonSet *appsv1.DaemonSet, reqLogger logr.
Labels: map[string]string{},
}}

result, err := controllerutil.CreateOrUpdate(context.TODO(), client, toUpdate, func() error {
result, err := controllerutil.CreateOrUpdate(ctx, client, toUpdate, func() error {
toUpdate.Spec = daemonSet.Spec
copyLabels(daemonSet, toUpdate)

Expand All @@ -66,11 +66,11 @@ func DaemonSet(owner metav1.Object, daemonSet *appsv1.DaemonSet, reqLogger logr.
reqLogger.Info("Re-creating a DaemonSet because it has immutable fields", "DaemonSet.Namespace",
daemonSet.Namespace, "DaemonSet.Name", daemonSet.Name)

if err := client.Delete(context.TODO(), toUpdate); err != nil {
if err := client.Delete(ctx, toUpdate); err != nil {
return err //nolint:wrapcheck // No need to wrap here
}

if err := client.Create(context.TODO(), daemonSet); err != nil {
if err := client.Create(ctx, daemonSet); err != nil {
return err //nolint:wrapcheck // No need to wrap here
}

Expand All @@ -90,13 +90,13 @@ func DaemonSet(owner metav1.Object, daemonSet *appsv1.DaemonSet, reqLogger logr.

// Update the status from the server
if err == nil {
err = client.Get(context.TODO(), types.NamespacedName{Namespace: daemonSet.Namespace, Name: daemonSet.Name}, daemonSet)
err = client.Get(ctx, types.NamespacedName{Namespace: daemonSet.Namespace, Name: daemonSet.Name}, daemonSet)
}

return daemonSet, errors.WithMessagef(err, "error creating or updating DaemonSet %s/%s", daemonSet.Namespace, daemonSet.Name)
}

func Deployment(owner metav1.Object, deployment *appsv1.Deployment, reqLogger logr.Logger,
func Deployment(ctx context.Context, owner metav1.Object, deployment *appsv1.Deployment, reqLogger logr.Logger,
client controllerClient.Client, scheme *runtime.Scheme,
) (*appsv1.Deployment, error) {
var err error
Expand Down Expand Up @@ -135,13 +135,13 @@ func Deployment(owner metav1.Object, deployment *appsv1.Deployment, reqLogger lo

// Update the status from the server
if err == nil {
err = client.Get(context.TODO(), types.NamespacedName{Namespace: deployment.Namespace, Name: deployment.Name}, deployment)
err = client.Get(ctx, types.NamespacedName{Namespace: deployment.Namespace, Name: deployment.Name}, deployment)
}

return deployment, errors.WithMessagef(err, "error creating or updating Deployment %s/%s", deployment.Namespace, deployment.Name)
}

func ConfigMap(owner metav1.Object, configMap *corev1.ConfigMap, reqLogger logr.Logger,
func ConfigMap(ctx context.Context, owner metav1.Object, configMap *corev1.ConfigMap, reqLogger logr.Logger,
client controllerClient.Client, scheme *runtime.Scheme,
) (*corev1.ConfigMap, error) {
var err error
Expand Down Expand Up @@ -180,13 +180,13 @@ func ConfigMap(owner metav1.Object, configMap *corev1.ConfigMap, reqLogger logr.

// Update the status from the server
if err == nil {
err = client.Get(context.TODO(), types.NamespacedName{Namespace: configMap.Namespace, Name: configMap.Name}, configMap)
err = client.Get(ctx, types.NamespacedName{Namespace: configMap.Namespace, Name: configMap.Name}, configMap)
}

return configMap, errors.WithMessagef(err, "error creating or updating ConfigMap %s/%s", configMap.Namespace, configMap.Name)
}

func Service(owner metav1.Object, service *corev1.Service, reqLogger logr.Logger,
func Service(ctx context.Context, owner metav1.Object, service *corev1.Service, reqLogger logr.Logger,
client controllerClient.Client, scheme *runtime.Scheme,
) (*corev1.Service, error) {
var err error
Expand All @@ -206,7 +206,7 @@ func Service(owner metav1.Object, service *corev1.Service, reqLogger logr.Logger
Annotations: map[string]string{},
}}

result, err := controllerutil.CreateOrUpdate(context.TODO(), client, toUpdate, func() error {
result, err := controllerutil.CreateOrUpdate(ctx, client, toUpdate, func() error {
if toUpdate.Spec.Type == corev1.ServiceTypeClusterIP || toUpdate.Spec.Type == corev1.ServiceTypeLoadBalancer {
// Make sure we don't lose the ClusterIP, see https://github.com/kubernetes/kubectl/issues/798
service.Spec.ClusterIP = toUpdate.Spec.ClusterIP
Expand Down Expand Up @@ -244,7 +244,7 @@ func Service(owner metav1.Object, service *corev1.Service, reqLogger logr.Logger

// Update the status from the server
if err == nil {
err = client.Get(context.TODO(), types.NamespacedName{Namespace: service.Namespace, Name: service.Name}, service)
err = client.Get(ctx, types.NamespacedName{Namespace: service.Namespace, Name: service.Name}, service)
}

return service, errors.WithMessagef(err, "error creating or updating Service %s/%s", service.Namespace, service.Name)
Expand Down
2 changes: 1 addition & 1 deletion controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
9 changes: 5 additions & 4 deletions controllers/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -19,6 +19,7 @@ limitations under the License.
package metrics

import (
"context"
"errors"
"fmt"

Expand All @@ -34,10 +35,10 @@ import (
controllerClient "sigs.k8s.io/controller-runtime/pkg/client"
)

func Setup(serviceName, namespace, applicationKey, applicationName string, owner metav1.Object, port int32,
func Setup(ctx context.Context, serviceName, namespace, applicationKey, applicationName string, owner metav1.Object, port int32,
client controllerClient.Client, config *rest.Config, scheme *runtime.Scheme, reqLogger logr.Logger,
) error {
metricsService, err := apply.Service(owner, newMetricsService(serviceName, namespace, applicationKey,
metricsService, err := apply.Service(ctx, owner, newMetricsService(serviceName, namespace, applicationKey,
applicationName, port), reqLogger, client, scheme)
if err != nil {
return err //nolint:wrapcheck // No need to wrap here
Expand All @@ -46,7 +47,7 @@ func Setup(serviceName, namespace, applicationKey, applicationName string, owner
if config != nil {
services := []*corev1.Service{metricsService}

_, err = metrics.CreateServiceMonitors(config, namespace, services)
_, err = metrics.CreateServiceMonitors(ctx, config, namespace, services)
if err != nil {
// If this operator is deployed to a cluster without the prometheus-operator running, it will return
// ErrServiceMonitorNotPresent, which can be used to safely skip ServiceMonitor creation.
Expand Down
2 changes: 1 addition & 1 deletion controllers/resource/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion controllers/servicediscovery/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Loading
Loading