Skip to content

Commit

Permalink
Revert "feat: allow config-specified host prefix instead of 'nid'"
Browse files Browse the repository at this point in the history
This reverts commit 6f1bfe3.
  • Loading branch information
synackd committed Dec 11, 2024
1 parent 6f1bfe3 commit d8fa710
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
19 changes: 5 additions & 14 deletions coresmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
cache *Cache
baseURL *url.URL
bootScriptBaseURL *url.URL
hostnamePrefix string
leaseDuration time.Duration
)

Expand All @@ -49,8 +48,8 @@ func setup4(args ...string) (handler.Handler4, error) {
log.Infof("initializing coresmd/coresmd %s (%s), built %s", version.Version, version.GitCommit, version.BuildTime)

// Ensure all required args were passed
if len(args) != 6 {
return nil, errors.New("expected 6 arguments: base URL, boot script base URL, CA certificate path, hostname prefix, cache duration, lease duration")
if len(args) != 5 {
return nil, errors.New("expected 5 arguments: base URL, boot script base URL, CA certificate path, cache duration, lease duration")
}

// Create new SmdClient using first argument (base URL)
Expand Down Expand Up @@ -82,25 +81,17 @@ func setup4(args ...string) (handler.Handler4, error) {
log.Infof("CA certificate path was empty, not setting")
}

// Parse hostname prefix
hostnamePrefix = strings.Trim(args[3], `"'`)
log.Infof("hostname prefix: %s", hostnamePrefix)
if hostnamePrefix == "" {
log.Info("no hostname prefix set, defaulting to 'nid'")
hostnamePrefix = "nid"
}

// Create new Cache using fourth argument (cache validity duration) and new SmdClient
// pointer
log.Debug("generating new Cache")
cache, err = NewCache(args[4], smdClient)
cache, err = NewCache(args[3], smdClient)
if err != nil {
return nil, fmt.Errorf("failed to create new cache: %w", err)
}

// Set lease duration from fifth argument
log.Debug("setting lease duration")
leaseDuration, err = time.ParseDuration(args[5])
leaseDuration, err = time.ParseDuration(args[4])
if err != nil {
return nil, fmt.Errorf("failed to parse lease duration: %w", err)
}
Expand Down Expand Up @@ -140,7 +131,7 @@ func Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {

// Set client hostname
if ifaceInfo.Type == "Node" {
resp.Options.Update(dhcpv4.OptHostName(fmt.Sprintf("%s%04d", hostnamePrefix, ifaceInfo.CompNID)))
resp.Options.Update(dhcpv4.OptHostName(fmt.Sprintf("nid%04d", ifaceInfo.CompNID)))
}

// Set root path to this server's IP
Expand Down
9 changes: 3 additions & 6 deletions resources/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ server4:
# address if name servers are not configured.
# 3. (OPTIONAL) Path to CA cert used for TLS with the SMD base URL. If
# there is already a trusted certificate, this can be blank ("").
# 4. Node hostname prefix. The hostnames given to nodes will be of the
# format "<prefix><nid>". If this argument is blank, "nid" is used as
# the prefix. <nid> is the node ID number, 0-padded to four places.
# 5. Cache validity duration. Coresmd uses a pull-through cache to store
# 4. Cache validity duration. Coresmd uses a pull-through cache to store
# network information and this is the duration to refresh that cache.
# 6. Lease duration.
- coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt '' 30s 1h
# 5. Lease duration.
- coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt 30s 1h

# Any requests reaching this point are unknown to SMD and it is up to the
# administrator to decide how to handle unknown packets.
Expand Down

0 comments on commit d8fa710

Please sign in to comment.