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

Add Reconciler #184

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.21
ARG GO_VERSION=1.22

FROM nats:latest as NATS

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=5m
version: latest
8 changes: 4 additions & 4 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
strategy:
fail-fast: false
matrix:
k8s-version: ["1.25", "1.26", "1.27"]
k8s-version: ["1.27", "1.28", "1.29"]

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

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

- uses: tylerauerbeck/envtest-action@main
- uses: rizzza/envtest-action@patch-1
env:
KUBERNETES_VERSION: ${{ matrix.k8s-version }}
with:
Expand Down
7 changes: 2 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ linters-settings:
linters:
enable:
# default linters
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

# additional linters
- bodyclose
- gocritic
- gocyclo
- goerr113
- err113
- gofmt
- goimports
- gomnd
- mnd
- govet
- misspell
- noctx
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.21
ARG GO_VERSION=1.22

FROM mcr.microsoft.com/vscode/devcontainers/go:1-${GO_VERSION}-bullseye

Expand Down
1 change: 1 addition & 0 deletions chart/load-balancer-operator/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data:
LOADBALANCEROPERATOR_METADATA_SOURCE: "{{ .Values.operator.metadata.source }}"
LOADBALANCEROPERATOR_METADATA_STATUS_NAMESPACE_ID: "{{ .Values.operator.metadata.statusNamespaceID }}"
LOADBALANCEROPERATOR_OIDC_CLIENT_ISSUER: "{{ .Values.operator.api.oidc.client.issuer }}"
LOADBALANCEROPERATOR_RECONCILER_INTERVAL: "{{ .Values.operator.reconciler.interval }}"
{{- if .Values.operator.tracing.enabled }}
LOADBALANCEROPERATOR_TRACING_ENABLED: "{{ .Values.operator.tracing.enabled }}"
LOADBALANCEROPERATOR_TRACING_PROVIDER: "{{ .Values.operator.tracing.provider }}"
Expand Down
2 changes: 2 additions & 0 deletions chart/load-balancer-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ operator:
eventTopics: []

locations: []
reconciler:
interval: 15m

metadata:
# endpoint metadata endpoint to use
Expand Down
1 change: 1 addition & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
// ErrChartPath is returned when a Helm chart path is missing
errChartPath = errors.New("chart path is required and cannot be empty")
errRequiredTopics = errors.New("at least one topic is required")
errInvalidInterval = errors.New("reconciler interval must be greater than 0")
errInvalidKubeClient = errors.New("failed to create kubernetes client")
errInvalidHelmChart = errors.New("failed to load helm chart")
)
33 changes: 28 additions & 5 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ var (
)

const (
DefaultLBMetricsPort = 29782
DefaultLBMetricsPort = 29782
defaultReconcilerInterval = 15 * time.Minute
)

func init() {
Expand Down Expand Up @@ -101,6 +102,9 @@ func init() {
processCmd.Flags().String("metadata-source", "load-balancer-operator", "metadata-api endpoint")
viperx.MustBindFlag(viper.GetViper(), "metadata.source", processCmd.Flags().Lookup("metadata-source"))

processCmd.PersistentFlags().Duration("reconciler-interval", defaultReconcilerInterval, "interval to reconcile the state of the operator with the lb-api")
viperx.MustBindFlag(viper.GetViper(), "reconciler-interval", processCmd.PersistentFlags().Lookup("reconciler-interval"))

rootCmd.AddCommand(processCmd)
}

Expand All @@ -124,6 +128,7 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
}

cx, cancel := context.WithCancel(ctx)
defer cancel()

eSrv, err := echox.NewServer(
logger.Desugar(),
Expand Down Expand Up @@ -190,6 +195,17 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
logger.Fatalw("failed to initialize tracer", "error", err)
}

go func() {
defer cancel()

err := server.ReconcileTimer(ctx, config.AppConfig.ReconcilerInterval)
if err != nil {
logger.Error("error reconciling load balancers", zap.Error(err))
}

logger.Warn("reconciler stopped")
}()

if err := server.Run(cx); err != nil {
logger.Fatalw("failed starting server", "error", err)
cancel()
Expand All @@ -198,10 +214,13 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)

recvSig := <-sigCh
signal.Stop(sigCh)
cancel()
logger.Infof("exiting. Performing necessary cleanup", recvSig)
select {
case <-server.Context.Done():
logger.Info("context done signal received")
case recvSig := <-sigCh:
signal.Stop(sigCh)
logger.Infof("exiting. Performing necessary cleanup", recvSig)
}

if err := server.Shutdown(); err != nil {
logger.Errorw("failed to shutdown server", zap.Error(err))
Expand Down Expand Up @@ -235,6 +254,10 @@ func validateFlags() error {
return errRequiredTopics
}

if config.AppConfig.ReconcilerInterval <= 0 {
return errInvalidInterval
}

return nil
}

Expand Down
Loading