Skip to content
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
67 changes: 67 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Lint

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.64
args: --timeout=5m

go-fmt:
name: go fmt
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Check formatting
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "The following files are not formatted:"
gofmt -l .
exit 1
fi

go-vet:
name: go vet
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Run go vet
run: go vet ./...
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
run:
timeout: 5m
modules-download-mode: readonly

linters:
enable:
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- errcheck
- gofmt
- goimports

linters-settings:
goimports:
local-prefixes: github.com/kaasops/vector-operator

issues:
exclude-rules:
# Exclude some linters from running on tests files
- path: _test\.go
linters:
- errcheck
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.16.1
ENVTEST_VERSION ?= release-0.19
GOLANGCI_LINT_VERSION ?= v1.59.1
GOLANGCI_LINT_VERSION ?= v1.64.8

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/clustervectorpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package v1alpha1

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kaasops/vector-operator/internal/utils/k8s"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kaasops/vector-operator/internal/utils/k8s"
)

func (vp *ClusterVectorPipeline) GetSpec() VectorPipelineSpec {
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/vectorpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package v1alpha1

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kaasops/vector-operator/internal/utils/k8s"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kaasops/vector-operator/internal/utils/k8s"
)

type VectorPipelineRole string
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.

18 changes: 10 additions & 8 deletions cmd/event_collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import (
"errors"
"flag"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/kaasops/vector-operator/internal/buildinfo"
"github.com/kaasops/vector-operator/internal/evcollector"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
"k8s.io/client-go/kubernetes"
"log/slog"
"net"
"net/http"
"os"
"os/signal"
ctrl "sigs.k8s.io/controller-runtime"
"strings"
"syscall"

"github.com/fsnotify/fsnotify"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/kaasops/vector-operator/internal/buildinfo"
"github.com/kaasops/vector-operator/internal/evcollector"
)

func main() {
Expand Down Expand Up @@ -112,7 +114,7 @@ func main() {

http.Handle("/metrics", promhttp.Handler())
go func() {
if err = http.ListenAndServe(net.JoinHostPort("", *port), nil); err != nil && !errors.Is(http.ErrServerClosed, err) {
if err = http.ListenAndServe(net.JoinHostPort("", *port), nil); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Error("failed to start http server", "error", err)
os.Exit(1)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/evgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"flag"
"fmt"
"k8s.io/apimachinery/pkg/util/rand"
ctrl "sigs.k8s.io/controller-runtime"
"sync"
"time"

"k8s.io/apimachinery/pkg/util/rand"
ctrl "sigs.k8s.io/controller-runtime"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -34,8 +35,8 @@ func main() {
wg := sync.WaitGroup{}

for i := 0; i < *workers; i++ {
wg.Add(1)
go func() {
wg.Add(1)
defer wg.Done()

clientset, err := kubernetes.NewForConfig(config)
Expand Down
3 changes: 2 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"crypto/tls"
"flag"
"fmt"
"github.com/kaasops/vector-operator/internal/buildinfo"
"os"
"time"

"github.com/kaasops/vector-operator/internal/buildinfo"

monitorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
8 changes: 5 additions & 3 deletions internal/config/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package config

import (
"fmt"
vectorv1alpha1 "github.com/kaasops/vector-operator/api/v1alpha1"
"github.com/kaasops/vector-operator/internal/pipeline"
"github.com/kaasops/vector-operator/internal/utils/k8s"

"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/labels"
goyaml "sigs.k8s.io/yaml"

vectorv1alpha1 "github.com/kaasops/vector-operator/api/v1alpha1"
"github.com/kaasops/vector-operator/internal/pipeline"
"github.com/kaasops/vector-operator/internal/utils/k8s"
)

const (
Expand Down
10 changes: 6 additions & 4 deletions internal/config/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package config
import (
"errors"
"fmt"
"github.com/kaasops/vector-operator/internal/common"
"github.com/kaasops/vector-operator/internal/pipeline"
"github.com/stoewer/go-strcase"
corev1 "k8s.io/api/core/v1"
"net"
"strconv"
"strings"

"github.com/stoewer/go-strcase"
corev1 "k8s.io/api/core/v1"

"github.com/kaasops/vector-operator/internal/common"
"github.com/kaasops/vector-operator/internal/pipeline"
)

func BuildAggregatorConfig(params VectorConfigParams, pipelines ...pipeline.Pipeline) (*VectorConfig, error) {
Expand Down
10 changes: 6 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"encoding/json"
"errors"
"fmt"
vectorv1alpha1 "github.com/kaasops/vector-operator/api/v1alpha1"
"github.com/kaasops/vector-operator/internal/evcollector"
"net"
"strconv"

"github.com/mitchellh/mapstructure"
"gopkg.in/yaml.v2"
"net"
goyaml "sigs.k8s.io/yaml"
"strconv"

vectorv1alpha1 "github.com/kaasops/vector-operator/api/v1alpha1"
"github.com/kaasops/vector-operator/internal/evcollector"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion internal/config/configcheck/configcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

api_errors "k8s.io/apimachinery/pkg/api/errors"

"github.com/kaasops/vector-operator/internal/utils/k8s"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand All @@ -36,6 +35,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kaasops/vector-operator/internal/utils/k8s"

vectorv1alpha1 "github.com/kaasops/vector-operator/api/v1alpha1"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/config/configcheck/configcheck_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package configcheck
import (
"context"

"github.com/kaasops/vector-operator/internal/utils/compression"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kaasops/vector-operator/internal/utils/compression"
)

func (cc *ConfigCheck) createVectorConfigCheckConfig(ctx context.Context) (*corev1.Secret, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"encoding/json"
"fmt"

"github.com/kaasops/vector-operator/internal/utils/hash"

corev1 "k8s.io/api/core/v1"
Expand Down
16 changes: 9 additions & 7 deletions internal/controller/clustervectoraggregator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ package controller
import (
"context"
"errors"
"github.com/kaasops/vector-operator/internal/config"
"github.com/kaasops/vector-operator/internal/config/configcheck"
"github.com/kaasops/vector-operator/internal/pipeline"
"github.com/kaasops/vector-operator/internal/utils/hash"
"github.com/kaasops/vector-operator/internal/utils/k8s"
"github.com/kaasops/vector-operator/internal/vector/aggregator"
"time"

monitorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -38,7 +34,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"
"time"

"github.com/kaasops/vector-operator/internal/config"
"github.com/kaasops/vector-operator/internal/config/configcheck"
"github.com/kaasops/vector-operator/internal/pipeline"
"github.com/kaasops/vector-operator/internal/utils/hash"
"github.com/kaasops/vector-operator/internal/utils/k8s"
"github.com/kaasops/vector-operator/internal/vector/aggregator"

v1alpha1 "github.com/kaasops/vector-operator/api/v1alpha1"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"context"

"sigs.k8s.io/controller-runtime/pkg/event"

. "github.com/onsi/ginkgo/v2"
Expand Down
21 changes: 10 additions & 11 deletions internal/controller/pipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ import (
"reflect"
"time"

"github.com/kaasops/vector-operator/internal/config/configcheck"
"github.com/kaasops/vector-operator/internal/vector/aggregator"
"github.com/kaasops/vector-operator/internal/vector/vectoragent"
"golang.org/x/sync/errgroup"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/kaasops/vector-operator/api/v1alpha1"
"github.com/kaasops/vector-operator/internal/config"
"github.com/kaasops/vector-operator/internal/pipeline"
"github.com/kaasops/vector-operator/internal/config/configcheck"
"github.com/kaasops/vector-operator/internal/vector/aggregator"
"github.com/kaasops/vector-operator/internal/vector/vectoragent"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/kaasops/vector-operator/api/v1alpha1"
"github.com/kaasops/vector-operator/internal/config"
"github.com/kaasops/vector-operator/internal/pipeline"
)

type PipelineReconciler struct {
Expand Down Expand Up @@ -335,14 +337,11 @@ func (r *PipelineReconciler) SetupWithManager(mgr ctrl.Manager) error {

var specAndAnnotationsPredicate = predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldObject := e.ObjectOld.(client.Object)
newObject := e.ObjectNew.(client.Object)

if oldObject.GetGeneration() != newObject.GetGeneration() {
if e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() {
return true
}

if !reflect.DeepEqual(oldObject.GetAnnotations(), newObject.GetAnnotations()) {
if !reflect.DeepEqual(e.ObjectOld.GetAnnotations(), e.ObjectNew.GetAnnotations()) {
return true
}

Expand Down
Loading