Skip to content

Commit

Permalink
Remove unneeded code:
Browse files Browse the repository at this point in the history
This functionality to disable DHCP entirely
will be available in the refactored hardware API.
See tinkerbell/tink#673

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Mar 25, 2023
1 parent 7d51d31 commit 63c9434
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 69 deletions.
4 changes: 1 addition & 3 deletions cmd/boots/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import (
)

var (
provisionerEngineName = env.Get("PROVISIONER_ENGINE_NAME", "packet")

mainlog log.Logger

GitRev = "unknown (use make)"
Expand Down Expand Up @@ -120,7 +118,7 @@ func main() {
if err != nil {
mainlog.Fatal(err)
}
jobManager := job.NewCreator(l, provisionerEngineName, finder)
jobManager := job.NewCreator(l, finder)

go func() {
mainlog.With("addr", cfg.syslogAddr).Info("serving syslog")
Expand Down
14 changes: 0 additions & 14 deletions job/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ func IsSpecialOS(i *client.Instance) bool {
func (j Job) ServeDHCP(ctx context.Context, w dhcp4.ReplyWriter, req *dhcp4.Packet) (bool, error) {
span := trace.SpanFromContext(ctx)

// If we are not the chosen provisioner for this piece of hardware
// do not respond to the DHCP request
if !j.areWeProvisioner() {
return false, nil
}

// setup reply
span.AddEvent("dhcp.NewReply")
// only DISCOVER and REQUEST get replies; reply is nil for ignored reqs
Expand Down Expand Up @@ -93,14 +87,6 @@ func (j Job) configureDHCP(ctx context.Context, rep, req *dhcp4.Packet) bool {
return true
}

func (j Job) areWeProvisioner() bool {
if j.hardware.HardwareProvisioner() == "" {
return true
}

return j.hardware.HardwareProvisioner() == j.ProvisionerEngineName()
}

func (j Job) setPXEFilename(rep *dhcp4.Packet, isTinkerbellIPXE, isARM, isUEFI, isHTTPClient bool) {
if j.HardwareState() == "in_use" {
if j.InstanceID() == "" {
Expand Down
93 changes: 41 additions & 52 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ type Manager interface {

// Creator is a type that can create jobs.
type Creator struct {
finder client.HardwareFinder
provisionerEngineName string
logger log.Logger
ExtraKernelParams []string
Registry string
RegistryUsername string
RegistryPassword string
TinkServerTLS bool
TinkServerGRPCAddr string
OSIEURLOverride string
finder client.HardwareFinder
logger log.Logger
ExtraKernelParams []string
Registry string
RegistryUsername string
RegistryPassword string
TinkServerTLS bool
TinkServerGRPCAddr string
OSIEURLOverride string
}

// NewCreator returns a manager that can create jobs.
func NewCreator(logger log.Logger, provisionerEngineName string, finder client.HardwareFinder) *Creator {
func NewCreator(logger log.Logger, finder client.HardwareFinder) *Creator {
return &Creator{
finder: finder,
provisionerEngineName: provisionerEngineName,
logger: logger,
finder: finder,
logger: logger,
}
}

Expand All @@ -53,23 +51,22 @@ func Init(l log.Logger) {
// Job holds per request data.
type Job struct {
log.Logger
provisionerEngineName string
mac net.HardwareAddr
ip net.IP
start time.Time
dhcp dhcp.Config
hardware client.Hardware
instance *client.Instance
NextServer net.IP
IpxeBaseURL string
BootsBaseURL string
ExtraKernelParams []string
Registry string
RegistryUsername string
RegistryPassword string
TinkServerTLS bool
TinkServerGRPCAddr string
OSIEURLOverride string
mac net.HardwareAddr
ip net.IP
start time.Time
dhcp dhcp.Config
hardware client.Hardware
instance *client.Instance
NextServer net.IP
IpxeBaseURL string
BootsBaseURL string
ExtraKernelParams []string
Registry string
RegistryUsername string
RegistryPassword string
TinkServerTLS bool
TinkServerGRPCAddr string
OSIEURLOverride string
}

// AllowPxe returns the value from the hardware data
Expand All @@ -85,22 +82,15 @@ func (j Job) AllowPXE() bool {
return j.instance.AllowPXE
}

// ProvisionerEngineName returns the current provisioning engine name
// as defined by the env var PROVISIONER_ENGINE_NAME supplied at runtime.
func (j Job) ProvisionerEngineName() string {
return j.provisionerEngineName
}

// CreateFromDHCP looks up hardware using the MAC from cacher to create a job.
// OpenTelemetry: If a hardware record is available and has an in-band traceparent
// specified, the returned context will have that trace set as its parent and the
// spans will be linked.
func (c *Creator) CreateFromDHCP(ctx context.Context, mac net.HardwareAddr, giaddr net.IP, circuitID string) (context.Context, *Job, error) {
j := &Job{
mac: mac,
start: time.Now(),
provisionerEngineName: c.provisionerEngineName,
Logger: c.logger,
mac: mac,
start: time.Now(),
Logger: c.logger,
}
d, err := c.finder.ByMAC(ctx, mac, giaddr, circuitID)
if err != nil {
Expand Down Expand Up @@ -134,17 +124,16 @@ func (c *Creator) CreateFromRemoteAddr(ctx context.Context, ip string) (context.
// spans will be linked.
func (c *Creator) createFromIP(ctx context.Context, ip net.IP) (context.Context, *Job, error) {
j := &Job{
ip: ip,
start: time.Now(),
provisionerEngineName: c.provisionerEngineName,
Logger: c.logger,
ExtraKernelParams: c.ExtraKernelParams,
Registry: c.Registry,
RegistryUsername: c.RegistryUsername,
RegistryPassword: c.RegistryPassword,
TinkServerTLS: c.TinkServerTLS,
TinkServerGRPCAddr: c.TinkServerGRPCAddr,
OSIEURLOverride: c.OSIEURLOverride,
ip: ip,
start: time.Now(),
Logger: c.logger,
ExtraKernelParams: c.ExtraKernelParams,
Registry: c.Registry,
RegistryUsername: c.RegistryUsername,
RegistryPassword: c.RegistryPassword,
TinkServerTLS: c.TinkServerTLS,
TinkServerGRPCAddr: c.TinkServerGRPCAddr,
OSIEURLOverride: c.OSIEURLOverride,
}

c.logger.With("ip", ip).Info("discovering from ip")
Expand Down

0 comments on commit 63c9434

Please sign in to comment.