Skip to content

Commit fb4e5eb

Browse files
rfc: add Interface resource + controller and initial provider setup
1 parent 0f72092 commit fb4e5eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+95284
-141
lines changed

.golangci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
version: "2"
1010
run:
1111
modules-download-mode: readonly
12-
timeout: 3m0s # none by default in v2
12+
timeout: 10m0s # none by default in v2
1313

1414
formatters:
1515
enable:
@@ -126,6 +126,8 @@ linters:
126126
- github.com/mdlayher/arp
127127
# for github.com/sapcc/vpa_butler
128128
- k8s.io/client-go
129+
# until https://github.com/openconfig/ygnmi/pull/157 is merged
130+
- github.com/openconfig/ygnmi
129131
toolchain-forbidden: true
130132
go-version-pattern: 1\.\d+(\.0)?$
131133
gosec:
@@ -183,6 +185,7 @@ linters:
183185
- third_party$
184186
- builtin$
185187
- examples$
188+
- internal/provider/openconfig
186189

187190
output:
188191
formats:

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ builds:
3636
- -X github.com/sapcc/go-api-declarations/bininfo.version={{ .Version }}
3737
- -X github.com/sapcc/go-api-declarations/bininfo.commit={{ .FullCommit }}
3838
- -X github.com/sapcc/go-api-declarations/bininfo.buildDate={{ .CommitDate }} # use CommitDate instead of Date for reproducibility
39-
main: ./cmd/manager
39+
main: ./cmd
4040
# Set the modified timestamp on the output binary to ensure that builds are reproducible.
4141
mod_timestamp: "{{ .CommitTimestamp }}"
4242

Makefile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ install-kustomize: FORCE
4242

4343
fmt: FORCE install-gofumpt
4444
@printf "\e[1;36m>> gofumpt -l -w .\e[0m\n"
45-
@gofumpt -l -w .
45+
@gofumpt -l -w $(shell git ls-files '*.go' | grep -v '^internal/provider/openconfig')
4646

4747
# Run the e2e tests against a k8s cluster.
4848
test-e2e: FORCE
@@ -84,17 +84,13 @@ undeploy: FORCE install-kustomize
8484

8585
# Install CRDs into the k8s cluster
8686
deploy-crds: FORCE generate install-kustomize
87-
@if [ -d config/crd ]; then \
88-
@printf "\e[1;36m>> kustomize build config/crd | kubectl apply -f -\e[0m\n"; \
89-
@kustomize build config/crd | kubectl apply -f -; \
90-
fi
87+
@printf "\e[1;36m>> kustomize build config/crd | kubectl apply -f -\e[0m\n"
88+
@kustomize build config/crd | kubectl apply -f -
9189

9290
# Uninstall CRDs from the k8s cluster
9391
undeploy-crds: FORCE install-kustomize
94-
@if [ -d config/crd ]; then \
95-
@printf "\e[1;36m>> kustomize build config/crd | kubectl delete -f -\e[0m\n"; \
96-
@kustomize build config/crd | kubectl delete --ignore-not-found=true -f -; \
97-
fi
92+
@printf "\e[1;36m>> kustomize build config/crd | kubectl delete -f -\e[0m\n"
93+
@kustomize build config/crd | kubectl delete --ignore-not-found=true -f -
9894

9995
# Create a Kind cluster for local development and testing.
10096
kind-create: FORCE
@@ -173,7 +169,7 @@ BININFO_BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
173169
build-all: build/network-operator
174170

175171
build/network-operator: FORCE generate
176-
env $(GO_BUILDENV) go build $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=network-operator -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -o build/network-operator ./cmd/manager
172+
env $(GO_BUILDENV) go build $(GO_BUILDFLAGS) -ldflags '-s -w -X github.com/sapcc/go-api-declarations/bininfo.binName=network-operator -X github.com/sapcc/go-api-declarations/bininfo.version=$(BININFO_VERSION) -X github.com/sapcc/go-api-declarations/bininfo.commit=$(BININFO_COMMIT_HASH) -X github.com/sapcc/go-api-declarations/bininfo.buildDate=$(BININFO_BUILD_DATE) $(GO_LDFLAGS)' -o build/network-operator ./cmd
177173

178174
DESTDIR =
179175
ifeq ($(shell uname -s),Darwin)
@@ -192,7 +188,7 @@ ifeq ($(GO_TESTPKGS),)
192188
GO_TESTPKGS := ./...
193189
endif
194190
# which packages to measure coverage for
195-
GO_COVERPKGS := $(shell go list ./... | grep -E '/internal')
191+
GO_COVERPKGS := $(shell go list ./... | grep -E '/internal' | grep -Ev '/internal/provider/openconfig')
196192
# to get around weird Makefile syntax restrictions, we need variables containing nothing, a space and comma
197193
null :=
198194
space := $(null) $(null)

Makefile.maker.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55

66
binaries:
77
- name: network-operator
8-
fromPackage: ./cmd/manager
8+
fromPackage: ./cmd
99
installTo: bin/
1010

1111
controllerGen:
@@ -16,6 +16,7 @@ controllerGen:
1616

1717
coverageTest:
1818
only: "/internal"
19+
except: "/internal/provider/openconfig"
1920

2021
dockerfile:
2122
enabled: false
@@ -25,6 +26,9 @@ golang:
2526

2627
golangciLint:
2728
createConfig: true
29+
skipDirs:
30+
- internal/provider/openconfig
31+
timeout: 10m
2832

2933
goReleaser:
3034
createConfig: true
@@ -76,7 +80,7 @@ verbatim: |
7680
7781
fmt: FORCE install-gofumpt
7882
@printf "\e[1;36m>> gofumpt -l -w .\e[0m\n"
79-
@gofumpt -l -w .
83+
@gofumpt -l -w $(shell git ls-files '*.go' | grep -v '^internal/provider/openconfig')
8084
8185
# Run the e2e tests against a k8s cluster.
8286
test-e2e: FORCE
@@ -118,17 +122,13 @@ verbatim: |
118122
119123
# Install CRDs into the k8s cluster
120124
deploy-crds: FORCE generate install-kustomize
121-
@if [ -d config/crd ]; then \
122-
@printf "\e[1;36m>> kustomize build config/crd | kubectl apply -f -\e[0m\n"; \
123-
@kustomize build config/crd | kubectl apply -f -; \
124-
fi
125+
@printf "\e[1;36m>> kustomize build config/crd | kubectl apply -f -\e[0m\n"
126+
@kustomize build config/crd | kubectl apply -f -
125127
126128
# Uninstall CRDs from the k8s cluster
127129
undeploy-crds: FORCE install-kustomize
128-
@if [ -d config/crd ]; then \
129-
@printf "\e[1;36m>> kustomize build config/crd | kubectl delete -f -\e[0m\n"; \
130-
@kustomize build config/crd | kubectl delete --ignore-not-found=true -f -; \
131-
fi
130+
@printf "\e[1;36m>> kustomize build config/crd | kubectl delete -f -\e[0m\n"
131+
@kustomize build config/crd | kubectl delete --ignore-not-found=true -f -
132132
133133
# Create a Kind cluster for local development and testing.
134134
kind-create: FORCE

PROJECT

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@ plugins:
99
helm.kubebuilder.io/v1-alpha: {}
1010
projectName: network-operator
1111
repo: github.com/ironcore-dev/network-operator
12+
resources:
13+
- api:
14+
crdVersion: v1
15+
namespaced: true
16+
controller: true
17+
domain: ironcore.dev
18+
group: network
19+
kind: Interface
20+
path: github.com/ironcore-dev/network-operator/api/v1alpha1
21+
version: v1alpha1
1222
version: "3"

Tiltfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@ docker_build('controller:latest', '.', ignore=['*/*/zz_generated.deepcopy.go', '
1111
'api/', 'cmd/', 'hack/', 'internal/', 'go.mod', 'go.sum', 'Makefile',
1212
])
1313

14+
local_resource('controller-gen', 'make generate', ignore=['*/*/zz_generated.deepcopy.go', 'config/crd/bases/*'], deps=[
15+
'api/', 'cmd/', 'hack/', 'internal/', 'go.mod', 'go.sum', 'Makefile',
16+
])
17+
1418
k8s_yaml(kustomize('config/default'))
15-
k8s_resource('network-operator-controller-manager')
19+
k8s_resource('network-operator-controller-manager', resource_deps=['controller-gen'])
20+
21+
# Sample resources with manual trigger mode
22+
k8s_yaml('./config/samples/v1alpha1_interface.yaml')
23+
k8s_resource(new_name='lo0', objects=['lo0:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
24+
k8s_resource(new_name='lo1', objects=['lo1:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
25+
k8s_resource(new_name='eth1-1', objects=['eth1-1:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
26+
k8s_resource(new_name='eth1-2', objects=['eth1-2:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
27+
k8s_resource(new_name='eth1-10', objects=['eth1-10:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
1628

1729
print('🚀 network-operator development environment')
18-
print('👉 Edit the controller code inside the api/, cmd/, or internal/ directories')
30+
print('👉 Edit the code inside the api/, cmd/, or internal/ directories')
1931
print('👉 Tilt will automatically rebuild and redeploy when changes are detected')
2032
# vim: ft=tiltfile syn=python

api/v1alpha1/groupversion_info.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package v1alpha1 contains API Schema definitions for the network.ironcore.dev v1alpha1 API group.
5+
// +kubebuilder:validation:Required
6+
// +kubebuilder:object:generate=true
7+
// +groupName=network.ironcore.dev
8+
package v1alpha1
9+
10+
import (
11+
"k8s.io/apimachinery/pkg/runtime/schema"
12+
"sigs.k8s.io/controller-runtime/pkg/scheme"
13+
)
14+
15+
var (
16+
// GroupVersion is group version used to register these objects.
17+
GroupVersion = schema.GroupVersion{Group: "network.ironcore.dev", Version: "v1alpha1"}
18+
19+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
20+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
21+
22+
// AddToScheme adds the types in this group-version to the given scheme.
23+
AddToScheme = SchemeBuilder.AddToScheme
24+
)
25+
26+
// WatchLabel is a label that can be applied to any Network API object.
27+
//
28+
// Controllers which allow for selective reconciliation may check this label and proceed
29+
// with reconciliation of the object only if this label and a configured value is present.
30+
const WatchLabel = "network.ironcore.dev/watch-filter"
31+
32+
// FinalizerName is the identifier used by the controllers to perform cleanup before a resource is deleted.
33+
// It is added when the resource is created and ensures that the controller can handle teardown logic
34+
// (e.g., deleting external dependencies) before Kubernetes finalizes the deletion.
35+
const FinalizerName = "network.ironcore.dev/finalizer"
36+
37+
// Condition types that are used across different objects.
38+
const (
39+
// Ready is the top-level status condition that reports if an object is ready.
40+
// This condition indicates whether the resource is ready to be used and will be calculated by the
41+
// controller based on child conditions, if present.
42+
ReadyCondition = "Ready"
43+
)
44+
45+
// Reasons that are used across different objects.
46+
const (
47+
// ReadyReason indicates that the resource is ready for use.
48+
ReadyReason = "Ready"
49+
50+
// NotReadyReason indicates that the resource is not ready for use.
51+
NotReadyReason = "NotReady"
52+
53+
// ReconcilePendingReason indicates that the controller is waiting for resources to be reconciled.
54+
ReconcilePendingReason = "ReconcilePending"
55+
)

0 commit comments

Comments
 (0)