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

Updates to hostname plugin #4

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
go: errors parsing go.mod:
go.mod:26: malformed module path "<<<<<<<": invalid char '<'
go.mod:28: usage: require module/path v1.2.3
go.mod:30: usage: require module/path v1.2.3
// Copyright 2020 Ettore Di Giacinto <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.9.3
github.com/spectrocloud-labs/herd v0.4.2
github.com/spf13/cobra v0.0.6
github.com/twpayne/go-vfs/v4 v4.3.0
github.com/willdonnelly/passwd v0.0.0-20141013001024-7935dab3074c
github.com/zcalusic/sysinfo v0.9.5
Expand Down Expand Up @@ -50,6 +51,7 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kendru/darwin/go/depgraph v0.0.0-20221105232959-877d6a81060c // indirect
Expand All @@ -65,6 +67,7 @@ require (
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tredoe/osutil/v2 v2.0.0-rc.16 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vishvananda/netlink v0.0.0-20170808154308-f5a6f697a596 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/itchyny/gojq v0.12.12 h1:x+xGI9BXqKoJQZkr95ibpe3cdrTbY8D9lonrK433rcA=
github.com/itchyny/gojq v0.12.12/go.mod h1:j+3sVkjxwd7A7Z5jrbKibgOLn0ZfLWkV+Awxr/pyzJE=
Expand Down Expand Up @@ -272,9 +273,11 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs=
github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
11 changes: 1 addition & 10 deletions pkg/plugins/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package plugins
import (
"bufio"
"fmt"
"math/rand"
"strings"
"syscall"
"time"

"github.com/denisbrodbeck/machineid"
"github.com/hashicorp/go-multierror"
Expand All @@ -27,15 +25,8 @@ func Hostname(l logger.Interface, s schema.Stage, fs vfs.FS, console Console) er
return nil
}

// Template the input string with random generated strings and UUID.
// Those can be used to e.g. generate random node names based on patterns "foo-{{.UUID}}"
rand.Seed(time.Now().UnixNano())

id, _ := machineid.ID()
myuuid, err := uuid.NewV4()
if err != nil {
return err
}
myuuid := uuid.NewV4()
tmpl, err := utils.TemplatedString(hostname,
struct {
UUID string
Expand Down
5 changes: 2 additions & 3 deletions pkg/plugins/timesyncd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package plugins_test

import (
"io"
"io/ioutil"

"github.com/sirupsen/logrus"
"github.com/twpayne/go-vfs/v4/vfst"
Expand Down Expand Up @@ -48,9 +47,9 @@ var _ = Describe("Timesyncd", func() {
file, err := fs.Open("/etc/systemd/timesyncd.conf")
Expect(err).ShouldNot(HaveOccurred())

b, err := ioutil.ReadAll(file)
b, err := io.ReadAll(file)
Expect(err).ShouldNot(HaveOccurred())
Expect(string(b)).Should(Equal("[Time]\nNTP = 0.pool\n"))
Expect(string(b)).Should(Equal("[Time]\nNTP = 0.pool\n\n"))
})
})
})