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

support eflo in centralized IPAM #787

Merged
merged 8 commits into from
Feb 24, 2025
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
6 changes: 4 additions & 2 deletions .github/workflows/build-policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ concurrency:

jobs:
build-policy:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

with:
image: tonistiigi/binfmt:qemu-v7.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ concurrency:

jobs:
build-terway:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:qemu-v7.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ concurrency:

jobs:
go-test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23.2
go-version: 1.24.0
- name: Test
run: |
go=$(which go)
Expand All @@ -30,12 +30,12 @@ jobs:
verbose: true

go-mod:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23.2
go-version: 1.24.0
- name: Check module vendoring
run: |
go mod tidy
Expand All @@ -44,21 +44,21 @@ jobs:

go-lint:
name: lint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23.2
go-version: 1.24.0
cache: false
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
version: v1.64.5
args: --config=.golangci.yml

super-linter:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Lint Code Base
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
actions: read
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:

jobs:
release:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Build Changelog
Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ linters:
linters-settings:
errcheck:
check-blank: false
govet:
check-shadowing: false
maligned:
suggest-new: true
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)

## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.14.0
CONTROLLER_TOOLS_VERSION ?= v0.17.2
ENVTEST_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.61.0
GOLANGCI_LINT_VERSION ?= v1.64.5

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
Expand Down
56 changes: 53 additions & 3 deletions cmd/terway-cli/cni_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import (
"errors"
"fmt"
"strconv"
"strings"
"syscall"

"github.com/docker/docker/pkg/parsers/kernel"
"github.com/vishvananda/netlink"
utilfeature "k8s.io/apiserver/pkg/util/feature"

Expand Down Expand Up @@ -60,6 +62,54 @@
return require, nil
}

func checkKernelVersion(k, major, minor int) bool {
return kernel.CheckKernelVersion(k, major, minor)
func checkKernelVersion(iMajor, iMinor, iPatch int) bool {
var un syscall.Utsname
_ = syscall.Uname(&un)
var sb strings.Builder
for _, b := range un.Release[:] {
if b == 0 {
break

Check warning on line 71 in cmd/terway-cli/cni_linux.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-cli/cni_linux.go#L65-L71

Added lines #L65 - L71 were not covered by tests
}
sb.WriteByte(byte(b))

Check warning on line 73 in cmd/terway-cli/cni_linux.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-cli/cni_linux.go#L73

Added line #L73 was not covered by tests
}
major, minor, patch, ok := parseRelease(sb.String())
return ok && (major > iMajor ||
major == iMajor && minor > iMinor ||
major == iMajor && minor == iMinor && iPatch >= patch)

Check warning on line 78 in cmd/terway-cli/cni_linux.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-cli/cni_linux.go#L75-L78

Added lines #L75 - L78 were not covered by tests
}

// parseRelease parses a dot-separated version number. It follows the semver
// syntax, but allows the minor and patch versions to be elided.
//
// This is a copy of the Go runtime's parseRelease from
// https://golang.org/cl/209597.
func parseRelease(rel string) (major, minor, patch int, ok bool) {
// Strip anything after a dash or plus.
for i := 0; i < len(rel); i++ {
if rel[i] == '-' || rel[i] == '+' {
rel = rel[:i]
break
}
}

next := func() (int, bool) {
for i := 0; i < len(rel); i++ {
if rel[i] == '.' {
ver, err := strconv.Atoi(rel[:i])
rel = rel[i+1:]
return ver, err == nil
}
}
ver, err := strconv.Atoi(rel)
rel = ""
return ver, err == nil
}
if major, ok = next(); !ok || rel == "" {
return
}

Check warning on line 109 in cmd/terway-cli/cni_linux.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-cli/cni_linux.go#L108-L109

Added lines #L108 - L109 were not covered by tests
if minor, ok = next(); !ok || rel == "" {
return
}

Check warning on line 112 in cmd/terway-cli/cni_linux.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-cli/cni_linux.go#L111-L112

Added lines #L111 - L112 were not covered by tests
patch, ok = next()
return
}
41 changes: 41 additions & 0 deletions cmd/terway-cli/cni_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_parseRelease(t *testing.T) {
type args struct {
rel string
}
tests := []struct {
name string
args args
wantMajor int
wantMinor int
wantPatch int
wantOk bool
}{
{
name: "test1",
args: args{
rel: "6.8.0-51-generic",
},
wantMajor: 6,
wantMinor: 8,
wantPatch: 0,
wantOk: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotMajor, gotMinor, gotPatch, gotOk := parseRelease(tt.args.rel)
assert.Equalf(t, tt.wantMajor, gotMajor, "parseRelease(%v)", tt.args.rel)
assert.Equalf(t, tt.wantMinor, gotMinor, "parseRelease(%v)", tt.args.rel)
assert.Equalf(t, tt.wantPatch, gotPatch, "parseRelease(%v)", tt.args.rel)
assert.Equalf(t, tt.wantOk, gotOk, "parseRelease(%v)", tt.args.rel)
})
}
}
12 changes: 12 additions & 0 deletions cmd/terway-controlplane/terway-controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"math/rand"
"net"
"os"
"strings"
"time"

"github.com/samber/lo"
Expand All @@ -41,7 +42,9 @@
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature "k8s.io/apiserver/pkg/util/feature"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2/textlogger"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
Expand Down Expand Up @@ -92,9 +95,12 @@
var (
configFilePath string
credentialFilePath string
featureGates map[string]bool

Check warning on line 98 in cmd/terway-controlplane/terway-controlplane.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-controlplane/terway-controlplane.go#L98

Added line #L98 was not covered by tests
)
flag.StringVar(&configFilePath, "config", "/etc/config/ctrl-config.yaml", "config file for controlplane")
flag.StringVar(&credentialFilePath, "credential", "/etc/credential/ctrl-secret.yaml", "secret file for controlplane")
flag.Var(cliflag.NewMapStringBool(&featureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))

Check warning on line 103 in cmd/terway-controlplane/terway-controlplane.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-controlplane/terway-controlplane.go#L102-L103

Added lines #L102 - L103 were not covered by tests

logCfg := textlogger.NewConfig()
logCfg.AddFlags(flag.CommandLine)
Expand All @@ -104,6 +110,12 @@
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
log.Info(version.Version)

err := utilfeature.DefaultMutableFeatureGate.SetFromMap(featureGates)
if err != nil {
log.Error(err, "unable to set feature gates")
os.Exit(1)
}

Check warning on line 117 in cmd/terway-controlplane/terway-controlplane.go

View check run for this annotation

Codecov / codecov/patch

cmd/terway-controlplane/terway-controlplane.go#L113-L117

Added lines #L113 - L117 were not covered by tests

ctx := ctrl.SetupSignalHandler()

cfg, err := controlplane.ParseAndValidate(configFilePath, credentialFilePath)
Expand Down
Loading
Loading