Skip to content

Commit

Permalink
Add local golint-ci lint config file (#146)
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling committed Dec 16, 2020
1 parent 5641805 commit eb549ce
Show file tree
Hide file tree
Showing 79 changed files with 903 additions and 107 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
args: -v
version: v1.29
args: --enable=gosec,maligned,misspell
only-new-issues: true

security:
name: Security
Expand Down
24 changes: 24 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
run:
timeout: 5m

# all available settings of specific linters
linters-settings:
goheader:
template-path: header.txt
goimports:
local-prefixes: github.com/open-telemetry/opentelemetry-operator
maligned:
suggest-new: true
misspell:
locale: US

linters:
enable:
- goheader
- goimports
- maligned
- misspell
- gosec
- exhaustive
- godot
- unparam
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
)

var (
// GroupVersion is group version used to register these objects
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "opentelemetry.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type (
)

const (
// ModeDaemonSet specifies that the collector should be deployed as a Kubernetes DaemonSet
// ModeDaemonSet specifies that the collector should be deployed as a Kubernetes DaemonSet.
ModeDaemonSet Mode = "daemonset"

// ModeDeployment specifies that the collector should be deployed as a Kubernetes Deployment
// ModeDeployment specifies that the collector should be deployed as a Kubernetes Deployment.
ModeDeployment Mode = "deployment"

// ModeSidecar specifies that the collector should be deployed as a sidecar to pods
// ModeSidecar specifies that the collector should be deployed as a sidecar to pods.
ModeSidecar Mode = "sidecar"
)
8 changes: 4 additions & 4 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector
// OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
type OpenTelemetryCollectorSpec struct {
// Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details.
// +required
Expand Down Expand Up @@ -78,7 +78,7 @@ type OpenTelemetryCollectorSpec struct {
Env []v1.EnvVar `json:"env,omitempty"`
}

// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector
// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector.
type OpenTelemetryCollectorStatus struct {
// Replicas is currently not being set and might be removed in the next version.
// +optional
Expand All @@ -102,7 +102,7 @@ type OpenTelemetryCollectorStatus struct {
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".status.version",description="OpenTelemetry Version"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// OpenTelemetryCollector is the Schema for the opentelemetrycollectors API
// OpenTelemetryCollector is the Schema for the opentelemetrycollectors API.
type OpenTelemetryCollector struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -113,7 +113,7 @@ type OpenTelemetryCollector struct {

// +kubebuilder:object:root=true

// OpenTelemetryCollectorList contains a list of OpenTelemetryCollector
// OpenTelemetryCollectorList contains a list of OpenTelemetryCollector.
type OpenTelemetryCollectorList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *OpenTelemetryCollector) SetupWebhookWithManager(mgr ctrl.Manager) error

var _ webhook.Defaulter = &OpenTelemetryCollector{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *OpenTelemetryCollector) Default() {
if len(r.Spec.Mode) == 0 {
r.Spec.Mode = ModeDeployment
Expand All @@ -54,19 +54,19 @@ func (r *OpenTelemetryCollector) Default() {

var _ webhook.Validator = &OpenTelemetryCollector{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *OpenTelemetryCollector) ValidateCreate() error {
opentelemetrycollectorlog.Info("validate create", "name", r.Name)
return nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *OpenTelemetryCollector) ValidateUpdate(old runtime.Object) error {
opentelemetrycollectorlog.Info("validate update", "name", r.Name)
return nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *OpenTelemetryCollector) ValidateDelete() error {
opentelemetrycollectorlog.Info("validate delete", "name", r.Name)
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
validation:
openAPIV3Schema:
description: OpenTelemetryCollector is the Schema for the opentelemetrycollectors
API
API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -54,7 +54,7 @@ spec:
metadata:
type: object
spec:
description: OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector
description: OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
properties:
args:
additionalProperties:
Expand Down Expand Up @@ -1703,7 +1703,7 @@ spec:
type: object
status:
description: OpenTelemetryCollectorStatus defines the observed state of
OpenTelemetryCollector
OpenTelemetryCollector.
properties:
messages:
description: Messages about actions performed by the operator on this
Expand Down
14 changes: 7 additions & 7 deletions controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/reconcile"
)

// OpenTelemetryCollectorReconciler reconciles a OpenTelemetryCollector object
// OpenTelemetryCollectorReconciler reconciles a OpenTelemetryCollector object.
type OpenTelemetryCollectorReconciler struct {
client.Client
log logr.Logger
Expand All @@ -41,14 +41,14 @@ type OpenTelemetryCollectorReconciler struct {
tasks []Task
}

// Task represents a reconciliation task to be executed by the reconciler
// Task represents a reconciliation task to be executed by the reconciler.
type Task struct {
Name string
Do func(context.Context, reconcile.Params) error
BailOnError bool
}

// Params is the set of options to build a new openTelemetryCollectorReconciler
// Params is the set of options to build a new openTelemetryCollectorReconciler.
type Params struct {
client.Client
Log logr.Logger
Expand All @@ -57,7 +57,7 @@ type Params struct {
Tasks []Task
}

// NewReconciler creates a new reconciler for OpenTelemetryCollector objects
// NewReconciler creates a new reconciler for OpenTelemetryCollector objects.
func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
if len(p.Tasks) == 0 {
p.Tasks = []Task{
Expand Down Expand Up @@ -106,7 +106,7 @@ func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
// +kubebuilder:rbac:groups=opentelemetry.io,resources=opentelemetrycollectors,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=opentelemetry.io,resources=opentelemetrycollectors/status,verbs=get;update;patch

// Reconcile the current state of an OpenTelemetry collector resource with the desired state
// Reconcile the current state of an OpenTelemetry collector resource with the desired state.
func (r *OpenTelemetryCollectorReconciler) Reconcile(_ context.Context, req ctrl.Request) (ctrl.Result, error) {
ctx := context.Background()
log := r.log.WithValues("opentelemetrycollector", req.NamespacedName)
Expand Down Expand Up @@ -138,7 +138,7 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(_ context.Context, req ctrl
return ctrl.Result{}, nil
}

// RunTasks runs all the tasks associated with this reconciler
// RunTasks runs all the tasks associated with this reconciler.
func (r *OpenTelemetryCollectorReconciler) RunTasks(ctx context.Context, params reconcile.Params) error {
for _, task := range r.tasks {
if err := task.Do(ctx, params); err != nil {
Expand All @@ -152,7 +152,7 @@ func (r *OpenTelemetryCollectorReconciler) RunTasks(ctx context.Context, params
return nil
}

// SetupWithManager tells the manager what our controller is interested in
// SetupWithManager tells the manager what our controller is interested in.
func (r *OpenTelemetryCollectorReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.OpenTelemetryCollector{}).
Expand Down
14 changes: 14 additions & 0 deletions controllers/opentelemetrycollector_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright The OpenTelemetry Authors
//
// 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.

package controllers_test

import (
Expand Down
13 changes: 13 additions & 0 deletions header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright The OpenTelemetry Authors

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.
10 changes: 5 additions & 5 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
defaultCollectorConfigMapEntry = "collector.yaml"
)

// Config holds the static configuration for this operator
// Config holds the static configuration for this operator.
type Config struct {
// Registers a callback, to be called once a configuration change happens
OnChange func() error
Expand All @@ -50,7 +50,7 @@ type Config struct {
version version.Version
}

// New constructs a new configuration based on the given options
// New constructs a new configuration based on the given options.
func New(opts ...Option) Config {
// initialize with the default values
o := options{
Expand Down Expand Up @@ -82,7 +82,7 @@ func New(opts ...Option) Config {
}
}

// FlagSet binds the flags to the user-modifiable values of the operator's configuration
// FlagSet binds the flags to the user-modifiable values of the operator's configuration.
func (c *Config) FlagSet() *pflag.FlagSet {
fs := pflag.NewFlagSet("opentelemetry-operator", pflag.ExitOnError)
pflag.StringVar(&c.collectorImage,
Expand Down Expand Up @@ -155,12 +155,12 @@ func (c *Config) CollectorConfigMapEntry() string {
return c.collectorConfigMapEntry
}

// Platform represents the type of the platform this operator is running
// Platform represents the type of the platform this operator is running.
func (c *Config) Platform() platform.Platform {
return c.platform
}

// Version holds the versions used by this operator
// Version holds the versions used by this operator.
func (c *Config) Version() version.Version {
return c.version
}
14 changes: 14 additions & 0 deletions internal/config/main_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright The OpenTelemetry Authors
//
// 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.

package config_test

import (
Expand Down
16 changes: 15 additions & 1 deletion internal/config/options.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright The OpenTelemetry Authors
//
// 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.

package config

import (
Expand All @@ -10,7 +24,7 @@ import (
"github.com/open-telemetry/opentelemetry-operator/pkg/platform"
)

// Option represents one specific configuration option
// Option represents one specific configuration option.
type Option func(c *options)

type options struct {
Expand Down
10 changes: 5 additions & 5 deletions internal/podinjector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ var (

var _ PodSidecarInjector = (*podSidecarInjector)(nil)

// PodSidecarInjector is a webhook handler that analyzes new pods and injects appropriate sidecars into it
// PodSidecarInjector is a webhook handler that analyzes new pods and injects appropriate sidecars into it.
type PodSidecarInjector interface {
admission.Handler
admission.DecoderInjector
}

// the implementation
// the implementation.
type podSidecarInjector struct {
config config.Config
logger logr.Logger
client client.Client
decoder *admission.Decoder
}

// NewPodSidecarInjector creates a new PodSidecarInjector
// NewPodSidecarInjector creates a new PodSidecarInjector.
func NewPodSidecarInjector(cfg config.Config, logger logr.Logger, cl client.Client) PodSidecarInjector {
return &podSidecarInjector{
config: cfg,
Expand Down Expand Up @@ -144,7 +144,7 @@ func (p *podSidecarInjector) mutate(ctx context.Context, ns corev1.Namespace, po

func (p *podSidecarInjector) getCollectorInstance(ctx context.Context, ns corev1.Namespace, ann string) (v1alpha1.OpenTelemetryCollector, error) {
if strings.EqualFold(ann, "true") {
return p.selectCollectorInstance(ctx, ns, ann)
return p.selectCollectorInstance(ctx, ns)
}

otelcol := v1alpha1.OpenTelemetryCollector{}
Expand All @@ -160,7 +160,7 @@ func (p *podSidecarInjector) getCollectorInstance(ctx context.Context, ns corev1
return otelcol, nil
}

func (p *podSidecarInjector) selectCollectorInstance(ctx context.Context, ns corev1.Namespace, ann string) (v1alpha1.OpenTelemetryCollector, error) {
func (p *podSidecarInjector) selectCollectorInstance(ctx context.Context, ns corev1.Namespace) (v1alpha1.OpenTelemetryCollector, error) {
otelcols := v1alpha1.OpenTelemetryCollectorList{}
if err := p.client.List(ctx, &otelcols, client.InNamespace(ns.Name)); err != nil {
return v1alpha1.OpenTelemetryCollector{}, err
Expand Down
Loading

0 comments on commit eb549ce

Please sign in to comment.