Skip to content

Commit

Permalink
Merge pull request #22 from telekom/fix/gh-actions
Browse files Browse the repository at this point in the history
Add PR Workflow
  • Loading branch information
chdxD1 committed Jun 19, 2023
2 parents 1667568 + 330c49c commit 04c11d4
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/container-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version: "^1.18"

- name: Install packages
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev libbpf-dev linux-headers-generic-hwe-20.04
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev gcc-multilib linux-headers-$(uname -r)

- name: Build
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/draft_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
go-version: "^1.18"

- name: Install packages
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev libbpf-dev linux-headers-generic-hwe-20.04
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev gcc-multilib linux-headers-$(uname -r)

- name: Build
run: |
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
go-version: "^1.18"

- name: Install packages
run: sudo apt-get update && apt-get install -y llvm clang libbpf-dev libbpf-dev linux-headers-generic-hwe-20.04
run: sudo apt-get update && apt-get install -y llvm clang libbpf-dev gcc-multilib linux-headers-$(uname -r)

- name: Build
run: |
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/pullrequests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: pullrequests

on:
pull_request:
types: [opened, edited, synchronize, reopened]

permissions: {}

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
- name: Install packages
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev gcc-multilib linux-headers-$(uname -r)
- name: run code generators
run: make generate
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.6.0
with:
version: v1.48.0

test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
- name: Install packages
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev gcc-multilib linux-headers-$(uname -r)
- name: Run Tests
run: make test

validate-generated:
name: validate generated files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
- name: Install packages
run: sudo apt-get update && sudo apt-get install -y llvm clang libbpf-dev gcc-multilib linux-headers-$(uname -r)
- name: run code generators
run: make generate
- name: run manifest generators
run: make manifests
- name: ensure no files changed
run: git diff --exit-code || (echo "Generated files are out of sync. Please run 'make generate manifests' and commit the updated files."; exit 1)
3 changes: 2 additions & 1 deletion api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ var _ = BeforeSuite(func() {
},
}

cfg, err := testEnv.Start()
var err error
cfg, err = testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: layer2networkconfigurations.network.schiff.telekom.de
spec:
group: network.schiff.telekom.de
Expand Down Expand Up @@ -108,6 +106,7 @@ spec:
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
vni:
description: VXLAN VNI Id for the layer 2 network
type: integer
Expand All @@ -128,9 +127,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: vrfrouteconfigurations.network.schiff.telekom.de
spec:
group: network.schiff.telekom.de
Expand Down Expand Up @@ -133,9 +131,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 0 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
2 changes: 0 additions & 2 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
creationTimestamp: null
name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
Expand Down
3 changes: 2 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var _ = BeforeSuite(func() {
ErrorIfCRDPathMissing: true,
}

cfg, err := testEnv.Start()
var err error
cfg, err = testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

Expand Down
5 changes: 4 additions & 1 deletion controllers/vrfrouteconfiguration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ func (r *VRFRouteConfigurationReconciler) ReconcileDebounced(ctx context.Context
// Make sure that all created netlink VRFs are up after FRR reload
time.Sleep(2 * time.Second)
for _, info := range created {
r.NLManager.UpL3(info)
if err := r.NLManager.UpL3(info); err != nil {
r.Logger.Error(err, "error setting L3 to state UP")
return err
}
}
return nil
}
Expand Down
27 changes: 9 additions & 18 deletions pkg/anycast/anycast.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,9 @@ func (a *AnycastTracker) checkTrackedInterfaces() {
}
}

func createNeighborEntry(mac net.HardwareAddr, intf, master int) *netlink.Neigh {
return &netlink.Neigh{
State: netlink.NUD_NOARP,
Family: unix.AF_BRIDGE,
HardwareAddr: mac,
LinkIndex: intf,
MasterIndex: master,
}
}

func isUnicastMac(mac net.HardwareAddr) bool {
return mac[0]&0x01 == 0
}

func containsIPNetwork(list []*net.IPNet, dst *net.IPNet) bool {
for _, v := range list {
if bytes.Equal(v.IP, dst.IP) && bytes.Equal(v.Mask, dst.Mask) {
if net.IP.Equal(v.IP, dst.IP) && bytes.Equal(v.Mask, dst.Mask) {
return true
}
}
Expand All @@ -58,7 +44,7 @@ func containsIPNetwork(list []*net.IPNet, dst *net.IPNet) bool {

func containsIPAddress(list []netlink.Neigh, dst *net.IPNet) bool {
for _, v := range list {
if bytes.Equal(v.IP, dst.IP) {
if net.IP.Equal(v.IP, dst.IP) {
return true
}
}
Expand Down Expand Up @@ -114,7 +100,9 @@ func syncInterfaceByFamily(intf *netlink.Bridge, family int, routingTable uint32
alreadyV4Existing := []*net.IPNet{}
for _, route := range routes {
if !containsIPAddress(bridgeNeighbors, route.Dst) {
netlink.RouteDel(&route)
if err := netlink.RouteDel(&route); err != nil {
fmt.Printf("Error deleting route %v: %v\n", route, err)
}
} else {
alreadyV4Existing = append(alreadyV4Existing, route.Dst)
}
Expand All @@ -123,7 +111,10 @@ func syncInterfaceByFamily(intf *netlink.Bridge, family int, routingTable uint32
for _, neighbor := range bridgeNeighbors {
net := netlink.NewIPNet(neighbor.IP)
if !containsIPNetwork(alreadyV4Existing, net) {
netlink.RouteAdd(buildRoute(family, intf, net, routingTable))
route := buildRoute(family, intf, net, routingTable)
if err := netlink.RouteAdd(route); err != nil {
fmt.Printf("Error adding route %v: %v\n", route, err)
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -33,7 +32,7 @@ func LoadConfig() (*Config, error) {
vniFile = val
}

read, err := ioutil.ReadFile(vniFile)
read, err := os.ReadFile(vniFile)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/frr/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package frr

import (
"bytes"
"io/ioutil"
"os"

"github.com/telekom/das-schiff-network-operator/pkg/nl"
Expand Down Expand Up @@ -32,7 +31,7 @@ func (m *FRRManager) Configure(in FRRConfiguration) (bool, error) {
return false, err
}

currentConfig, err := ioutil.ReadFile(m.ConfigPath)
currentConfig, err := os.ReadFile(m.ConfigPath)
if err != nil {
return false, err
}
Expand All @@ -42,8 +41,8 @@ func (m *FRRManager) Configure(in FRRConfiguration) (bool, error) {
return false, err
}

if bytes.Compare(currentConfig, targetConfig) != 0 {
err = ioutil.WriteFile(m.ConfigPath, targetConfig, FRR_PERMISSIONS)
if bytes.Equal(currentConfig, targetConfig) {
err = os.WriteFile(m.ConfigPath, targetConfig, FRR_PERMISSIONS)
if err != nil {
return false, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/frr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"io/fs"
"io/ioutil"
"net"
"os"
"text/template"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (m *FRRManager) Init() error {
}
}

bytes, err := ioutil.ReadFile(m.TemplatePath)
bytes, err := os.ReadFile(m.TemplatePath)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/frr/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package frr

import (
_ "embed"
"os"

"bytes"
"io/ioutil"
"regexp"
"text/template"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func render(tpl *template.Template, vrfs interface{}) ([]byte, error) {
}

func generateTemplateConfig(template string, original string) error {
bytes, err := ioutil.ReadFile(original)
bytes, err := os.ReadFile(original)
if err != nil {
return err
}
Expand All @@ -87,7 +87,7 @@ func generateTemplateConfig(template string, original string) error {
commentToRemove := regexp.MustCompile(`(?m)^\#\+\+`)
content = commentToRemove.ReplaceAllString(content, "")

err = ioutil.WriteFile(template, []byte(content), FRR_PERMISSIONS)
err = os.WriteFile(template, []byte(content), FRR_PERMISSIONS)
if err != nil {
return err
}
Expand Down

0 comments on commit 04c11d4

Please sign in to comment.