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 support for metal-operators Endpoint API #185

Merged
merged 17 commits into from
Sep 20, 2024
Merged
4 changes: 1 addition & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: golangci/golangci-lint-action@v6
with:
args: --timeout 15m
version: v1.61
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target
bin
.idea/
cover.out
/vendor
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Copy the go source
COPY main.go main.go
COPY plugins/ plugins/
COPY internal/ internal/

ARG TARGETOS
ARG TARGETARCH
Expand All @@ -22,7 +23,7 @@
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o fedhcp main.go

FROM debian:stable as installer

Check warning on line 26 in Dockerfile

View workflow job for this annotation

GitHub Actions / buildAndPush

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN apt-get update \
&& apt-get -y install --no-install-recommends libcap2-bin \
Expand Down
34 changes: 18 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.30.0

.PHONY: target/fedhcp
.PHONY: all

all: target/fedhcp
all: build

target/fedhcp:
mkdir -p target
CGO_ENABLED=0 go build -o target/fedhcp .
build:
go build -o bin/fedhcp ./main.go

clean:
rm -rf target
Expand All @@ -19,15 +18,15 @@ run: all

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} $(GITHUB_PAT_MOUNT) .
docker build -t ${IMG}

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
fmt: goimports ## Run goimports against code.
$(GOIMPORTS) -w .

.PHONY: vet
vet: ## Run go vet against code.
Expand All @@ -45,8 +44,8 @@ addlicense: ## Add license headers to all go files.
checklicense: ## Check that every file has a license header present.
find . -name '*.go' -exec go run github.com/google/addlicense -check -c 'OnMetal authors' {} +

lint: ## Run golangci-lint against code.
golangci-lint run ./...
lint: golangci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run ./...

.PHONY: test
test: controller-gen fmt vet envtest ## Run tests.
Expand All @@ -65,16 +64,14 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
GOIMPORTS ?= $(LOCALBIN)/goimports-$(GOIMPORTS_VERSION)

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.1
CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.57.2
#KUSTOMIZE_VERSION ?= latest
#CONTROLLER_TOOLS_VERSION ?= latest
#ENVTEST_VERSION ?= latest
#GOLANGCI_LINT_VERSION ?= latest
ENVTEST_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.61.0
GOIMPORTS_VERSION ?= v0.25.0

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand All @@ -96,6 +93,11 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})

.PHONY: goimports
goimports: $(GOIMPORTS) ## Download goimports locally if necessary.
$(GOIMPORTS): $(LOCALBIN)
$(call go-install-tool,$(GOIMPORTS),golang.org/x/tools/cmd/goimports,$(GOIMPORTS_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,28 @@ The OOB plugin leases an IP object to an out-of-band client, based on a subnet d

An IP object with a random IP address from the subnet's vacant list is created in IPAM, the IP address is then leased back to the client. Currently no cleanup-on-release is performed, so clients with stable identifiers are guaranteed to become stable IP addresses.
### Configuration
As for in-band, a kubernetes namespace shall be passed as a parameter. Further, an subnet label list in the form `value:key` shall be passed, it is used for subnet detection.
As for in-band, a kubernetes namespace shall be passed as a parameter. Further, a subnet label list in the form `value:key` shall be passed, it is used for subnet detection.
### Notes
- supports both IPv4 and IPv6
- IPv6 relays are supported, IPv4 are not
- other than for in-band, where the DHCP leasing and kubernetes persistence are handled in different plugins, for out-of-band a single plugin is used
- depends on [IPAM operator](https://github.com/ironcore-dev/ipam)

## Metal
The Metal plugin acts as a connection link between DHCP and the IronCore metal stack. It creates an `EndPoint` object for each machine with leased IP address. Those endpoints are then consumed by the metal operator, who then creates the corresponding `Machine` objects.

### Configuration
Path to an inventory yaml shall be passed as a string. It represents a list of machines as follows:
```yaml
- name: server-01
macAddress: 00:1A:2B:3C:4D:5E
- name: server-02
macAddress: 00:1A:2B:3C:4D:5F
```
### Notes
- supports both IPv4 and IPv6
- IPv6 relays are supported, IPv4 are not
- depends on [metal operator](https://github.com/ironcore-dev/metal)

## PXEBoot
The PXEBoot plugin implements an (i)PXE network boot.
Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ server6:
- dns: 2001:4860:4860::6464 2001:4860:4860::64
# implement (i)PXE boot
- pxeboot: tftp://[2001:db8::1]/ipxe/x86_64/ipxe http://[2001:db8::1]/ipxe/boot6
# create Endpoint objects in kubernetes
- metal: inventory.yaml
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ require (
github.com/coredhcp/coredhcp v0.0.0-20240908184240-576af8676ffa
github.com/google/addlicense v1.1.1
github.com/insomniacslk/dhcp v0.0.0-20240829085014-a3a4c1f04475
github.com/ironcore-dev/controller-utils v0.9.3
github.com/ironcore-dev/ipam v0.2.2
github.com/ironcore-dev/metal-operator v0.0.0-20240910120000-bbd70c2a0eb0
github.com/mdlayher/netx v0.0.0-20230430222610-7e21880baee8
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace
Expand All @@ -17,6 +21,8 @@ require (
sigs.k8s.io/controller-runtime v0.19.0
)

replace github.com/coredhcp/coredhcp => github.com/damyan/coredhcp v0.0.0-20240911115402-66f9c25a305e

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
Expand All @@ -30,16 +36,19 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down Expand Up @@ -70,11 +79,11 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/u-root/uio v0.0.0-20240224005618-d2acac8f3701 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
Expand Down
Loading
Loading