Giter VIP home page Giter VIP logo

dnsmasq-controller's Introduction

Dnsmasq-controller

A Dnsmasq-controller for Kubernetes, implemented in go using kubebuilder.

Status

GitHub GitHub GitHub go.mod Go version

Supported resources

  • DnsmasqOptions
  • DnsHosts
  • DhcpHosts
  • DhcpOptions

Configuration

Flag Type Required Description
-cleanup bool false Cleanup Dnsmasq config directory before start.
-conf-dir string false Dnsmasq config directory for write configuration to. (default "/etc/dnsmasq.d")
-controller string false Name of the controller this controller satisfies. (default "")
-development bool false Run the controller in development mode.
-dhcp bool false Enable DHCP Service and configuration discovery.
-dns bool false Enable DNS Service and configuration discovery.
-enable-leader-election bool false Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.
-kubeconfig string false Paths to a kubeconfig. Only required if out-of-cluster.
-log-level string false The log level used by the operator. (default "info")
-metrics-addr string false The address the metric endpoint binds to. (default ":8080")
-sync-delay int false Time in seconds to syncronise Dnsmasq configuration. (default 1)
-watch-namespace string false Namespace the controller watches for updates to Kubernetes objects. All namespaces are watched if this parameter is left empty.
-- array false Additional command line arguments for Dnsmasq may be specified after -- (read dnsmasq-man for more details)

Installation

# CRDs
kubectl apply -k config/crd/bases

# RBAC
kubectl apply -k config/rbac

# DNS-server (for infra.example.org)
kubectl apply -k config/dns-server

# DHCP-server
kubectl apply -k config/dhcp-server

# Add dnsmasq role to your nodes
kubectl label node <node1> <node2> <node3> node-role.kubernetes.io/dnsmasq=

Examples

Global DHCP-configuration:

---
apiVersion: dnsmasq.kvaps.cf/v1beta1
kind: DhcpOptions
metadata:
  name: default-network-configuration
spec:
  controller: ""
  options:
  - key: option:router
    values: [192.168.67.1]
  - key: option:dns-server
    values: [192.168.67.1]
  - key: option:domain-name
    values: [infra.example.org]
  - key: option:domain-search
    values: [infra.example.org]
---
apiVersion: dnsmasq.kvaps.cf/v1beta1
kind: DnsmasqOptions
metadata:
  name: default-matchers
spec:
  controller: ""
  options:
  - key: dhcp-range
    values: [192.168.67.0,static,infinite]
  - key: dhcp-match
    values: [set:iPXE,"175","39"]
  - key: dhcp-match
    values: [set:X86PC,option:client-arch,"0"]
  - key: dhcp-match
    values: [set:X86-64_EFI,option:client-arch,"7"]
  - key: dhcp-match
    values: [set:X86-64_EFI,option:client-arch,"9"]

Global DNS-configuration:

---
apiVersion: dnsmasq.kvaps.cf/v1beta1
kind: DnsmasqOptions
metadata:
  name: global-dns
spec:
  controller: ""
  options:
  - key: srv-host
    values: [_kerberos-master._tcp.infra.example.org,freeipa.example.org,"88"]
  - key: srv-host
    values: [_kerberos-master._udp.infra.example.org,freeipa.example.org,"88"]
  - key: srv-host
    values: [_kerberos._tcp.infra.example.org,freeipa.example.org,"88"]
  - key: srv-host
    values: [_kerberos._udp.infra.example.org,freeipa.example.org,"88"]
  - key: srv-host
    values: [_kpasswd._tcp.infra.example.org,freeipa.example.org,"464"]
  - key: srv-host
    values: [_kpasswd._udp.infra.example.org,freeipa.example.org,"464"]
  - key: srv-host
    values: [_ldap._tcp.infra.example.org,freeipa.example.org,"389"]
  - key: srv-host
    values: [_ntp._udp.infra.example.org,129.6.15.28,"123"]
  - key: srv-host
    values: [_ntp._udp.infra.example.org,129.6.15.29,"123"]
  - key: txt-record
    values: [_kerberos.infra.example.org,EXAMPLE.ORG]

Netboot-server configuration with tag ltsp1:

---
apiVersion: dnsmasq.kvaps.cf/v1beta1
kind: DhcpOptions
metadata:
  name: ltsp1
spec:
  controller: ""
  options:
  - key: option:server-ip-address
    tags: [ltsp1]
    values: [192.168.67.11]
  - key: option:tftp-server
    tags: [ltsp1]
    values: [ltsp1]
  - key: option:bootfile-name
    tags: [ltsp1,X86PC]
    values: [ltsp/grub/i386-pc/core.0]
  - key: option:bootfile-name
    tags: [ltsp1,X86-64_EFI]
    values: [ltsp/grub/x86_64-efi/core.efi]

DHCP-client for network booting using assigned tag ltsp1:

---
apiVersion: dnsmasq.kvaps.cf/v1beta1
kind: DhcpHosts
metadata:
  name: netboot-client
spec:
  controller: ""
  hosts:
  - ip: 192.168.67.20
    macs:
    - 94:57:a5:d3:b6:f2
    - 94:57:a5:d3:b6:f3
    clientIDs: ["*"]
    setTags: [ltsp1]
    hostname: node1
    leaseTime: infinite

Add A, AAAA and PTR records to the DNS:

---
apiVersion: dnsmasq.kvaps.cf/v1beta1
kind: DnsHosts
metadata:
  name: netboot-client
spec:
  controller: ""
  hosts:
  - ip: 192.168.67.20
    hostnames:
    - node1
    - node1.infra.example.org

Development

Pre-requisites

Getting started

make install
make run

Running tests

make test

dnsmasq-controller's People

Contributors

bc185174 avatar kvaps avatar mrakopes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dnsmasq-controller's Issues

Can execute "make install"

Step 1: clone code from github
Step2: execute make install
we can't execute make install

go run sigs.k8s.io/controller-tools/cmd/[email protected] crd rbac:roleName=dnsmasq-controller paths="./..." output:crd:artifacts:config=config/crd/bases
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa0c04f]

goroutine 60 [running]:
go/types.(*Checker).handleBailout(0xc00001f200, 0xc000efdd40)
        /usr/local/go/src/go/types/check.go:367 +0x88
panic({0xbb8e00?, 0x1297d10?})
        /usr/local/go/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0xdad4d8, 0x12a0740})
        /usr/local/go/src/go/types/sizes.go:228 +0x30f
go/types.(*Config).sizeof(...)
        /usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0xdad4d8?, 0x12a0740?})
        /usr/local/go/src/go/types/const.go:76 +0x9e
go/types.representableConst({0xdb39a0, 0x126c5c0}, 0xc00001f200, 0x12a0740, 0xc000efd4b0)
        /usr/local/go/src/go/types/const.go:92 +0x192
go/types.(*Checker).representation(0xc00001f200, 0xc000e24e00, 0x12a0740)
        /usr/local/go/src/go/types/const.go:256 +0x65
go/types.(*Checker).implicitTypeAndValue(0xc00001f200, 0xc000e24e00, {0xdad500, 0xc000210930})
        /usr/local/go/src/go/types/expr.go:375 +0x2d7
go/types.(*Checker).assignment(0xc00001f200, 0xc000e24e00, {0xdad500, 0xc000210930}, {0xc85fa6, 0x14})
        /usr/local/go/src/go/types/assignments.go:52 +0x2e5
go/types.(*Checker).initConst(0xc00001f200, 0xc000d5d4a0, 0xc000e24e00)
        /usr/local/go/src/go/types/assignments.go:126 +0x2c5
go/types.(*Checker).constDecl(0xc00001f200, 0xc000d5d4a0, {0xdb0198, 0xc000b2fa80}, {0xdb0198, 0xc000b2faa0}, 0x0)
        /usr/local/go/src/go/types/decl.go:490 +0x311
go/types.(*Checker).objDecl(0xc00001f200, {0xdb9000, 0xc000d5d4a0}, 0x0)
        /usr/local/go/src/go/types/decl.go:191 +0xa49
go/types.(*Checker).packageObjects(0xc00001f200)
        /usr/local/go/src/go/types/resolver.go:693 +0x4dd
go/types.(*Checker).checkFiles(0xc00001f200, {0xc0009ad110, 0x5, 0x5})
        /usr/local/go/src/go/types/check.go:408 +0x1a5
go/types.(*Checker).Files(...)
        /usr/local/go/src/go/types/check.go:372
sigs.k8s.io/controller-tools/pkg/loader.(*loader).typeCheck(0xc00024ef90, 0xc00079bb00)
        /home/matthew/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/loader.go:283 +0x36a
sigs.k8s.io/controller-tools/pkg/loader.(*Package).NeedTypesInfo(0xc00079bb00)
        /home/matthew/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/loader.go:96 +0x39
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check(0xc000d04a80, 0xc00079bb00)
        /home/matthew/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:263 +0x2b7
sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check.func1(0x53?)
        /home/matthew/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:257 +0x53
created by sigs.k8s.io/controller-tools/pkg/loader.(*TypeChecker).check in goroutine 66
        /home/matthew/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/loader/refs.go:255 +0x1c5
exit status 2
make: *** [Makefile:52: manifests] Error 1

Upgrade go version to 1.22

The golang version is quite far behind. Should look to uplift this to 1.22 along with the go dependencies.

k8s v1.23.3 no matches for kind "CustomResourceDefinition"

unable to recognize "https://github.com/kvaps/dnsmasq-controller/raw/master/config/crd/bases/dnsmasq.kvaps.cf_dhcphosts.yaml": no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1" unable to recognize "https://github.com/kvaps/dnsmasq-controller/raw/master/config/crd/bases/dnsmasq.kvaps.cf_dhcpoptions.yaml": no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1" unable to recognize "https://github.com/kvaps/dnsmasq-controller/raw/master/config/crd/bases/dnsmasq.kvaps.cf_dnshosts.yaml": no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1" unable to recognize "https://github.com/kvaps/dnsmasq-controller/raw/master/config/crd/bases/dnsmasq.kvaps.cf_dnsmasqoptions.yaml": no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1"

Is this related to: https://kubernetes.io/blog/2021/07/14/upcoming-changes-in-kubernetes-1-22/ ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.